Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions apps/admin/src/views/score/api/featScore.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import instance from "@repo/api/axios";
import { AxiosError, type AxiosResponse } from "axios";
import { isAxiosError, type AxiosResponse } from "axios";

interface FeatScoreResponse {
categoryName: string;
value: number;
}

interface FeatScoreRequest {
email: string;
category: string;
score: number;
categoryName: string;
value: number;
}

export const featScore = async (
email: string,
category: string,
score: number,
score: number
): Promise<AxiosResponse<FeatScoreResponse>> => {
const data: FeatScoreRequest = {
email,
category,
score,
categoryName: category,
value: Number(score),
};
try {
return await instance.patch<FeatScoreResponse>("/score", data);
const id = email.split("@")[0]?.slice(1);
return await instance.patch<FeatScoreResponse>(`/score/${id}`, data);
} catch (error) {
if (error instanceof AxiosError) {
if (isAxiosError(error) && error.response) {
throw error;
}
throw new Error("Unknown error occurred");
Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/views/score/model/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Score {
}

export interface ScoreFormType {
activity: number | null;
oneSemester: number | null;
twoSemester: number | null;
newrrow: number | null;
Expand Down
34 changes: 26 additions & 8 deletions apps/admin/src/views/score/ui/scoreForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { useCallback } from "react";
import { Controller, useForm, useWatch } from "react-hook-form";
import { toast } from "sonner";

import { Checkbox } from "@/entities/score/ui/checkbox";
import Header from "@/shared/ui/header";

import { featScore } from "../api/featScore";
import type { ScoreFormType } from "../model/score";

import { Checkbox } from "@/entities/score/ui/checkbox";
import Header from "@/shared/ui/header";

const SCORE_CATEGORIES = {
ACTIVITY: "HUMANITIES-SERVICE-ACTIVITY",
SEMESTER_1: "HUMANITIES-SERVICE-CLUB_SEMESTER_1",
SEMESTER_2: "HUMANITIES-SERVICE-CLUB_SEMESTER_2",
NEWRROW: "HUMANITIES-ACTIVITIES-NEWRROW_S",
Expand All @@ -34,9 +36,7 @@ const ScoreForm = () => {
}, [router]);

const renderCheckbox = useCallback(
({
field,
}: {
({ field }: {
field: { value?: boolean; onChange: (value: boolean | null) => void };
}) => <Checkbox {...field} />,
[],
Expand Down Expand Up @@ -76,7 +76,16 @@ const ScoreForm = () => {
async (data: ScoreFormType) => {
let success = true;

if (data.oneSemester !== null && data.oneSemester > 0) {
if (data.activity !== null && data.activity > 0) {
success =
(await handleScoreSubmit(
SCORE_CATEGORIES.ACTIVITY,
data.activity,
"봉사활동 점수 추가 완료",
)) && success;
}

else if (data.oneSemester !== null && data.oneSemester > 0) {
success =
(await handleScoreSubmit(
SCORE_CATEGORIES.SEMESTER_1,
Expand Down Expand Up @@ -137,10 +146,19 @@ const ScoreForm = () => {
<h1 className="sm:text-titleMedium text-title4s text-tropicalblue-700 mt-[2.38rem]">
점수 추가
</h1>
<InputContainer label="봉사활동">
<Input
control={control}
max={40}
min={0}
name="activity"
type="number"
/>
</InputContainer>
<InputContainer label="1학기 봉사 시간">
<Input
control={control}
max={5}
max={1}
min={0}
name="oneSemester"
type="number"
Expand All @@ -149,7 +167,7 @@ const ScoreForm = () => {
<InputContainer label="2학기 봉사 시간">
<Input
control={control}
max={5}
max={1}
min={0}
name="twoSemester"
type="number"
Expand Down
Loading