From 7bebb453c2a9c409d92d6ff99ee03a3add3f856d Mon Sep 17 00:00:00 2001 From: hamo-o Date: Sun, 17 Nov 2024 20:07:04 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B2=98=EB=A6=AC,=20=EC=B2=A0=ED=9A=8C?= =?UTF-8?q?=20type=EC=9C=BC=EB=A1=9C=20=EC=82=AC=EC=9A=A9=20=EB=B0=8F=20ou?= =?UTF-8?q?tstandingRoundMap=EC=9C=BC=EB=A1=9C=201=EC=B0=A8,=202=EC=B0=A8?= =?UTF-8?q?=20=EC=9B=8C=EB=94=A9=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OutstandingDropDown/DropDownTrigger.tsx | 6 ++- .../_components/OutstandingDropDown/index.tsx | 7 +-- .../_components/StudentHeaderButtons.tsx | 48 ++----------------- .../app/students/_contexts/StudyProvider.tsx | 2 +- .../constants/status/outstandigOptions.ts | 8 ++++ 5 files changed, 21 insertions(+), 50 deletions(-) diff --git a/apps/admin/app/students/_components/OutstandingDropDown/DropDownTrigger.tsx b/apps/admin/app/students/_components/OutstandingDropDown/DropDownTrigger.tsx index 1e79d2a4..efff44bf 100644 --- a/apps/admin/app/students/_components/OutstandingDropDown/DropDownTrigger.tsx +++ b/apps/admin/app/students/_components/OutstandingDropDown/DropDownTrigger.tsx @@ -1,9 +1,11 @@ import Button from "wowds-ui/Button"; -const DropDownTrigger = ({ type }: { type: "ADD" | "DEL" }) => { +import type { OutstandingStudentsType } from "@/students/_contexts/StudyProvider"; + +const DropDownTrigger = ({ type }: { type: OutstandingStudentsType }) => { return ( ); }; diff --git a/apps/admin/app/students/_components/OutstandingDropDown/index.tsx b/apps/admin/app/students/_components/OutstandingDropDown/index.tsx index c485d56b..cbf6f59d 100644 --- a/apps/admin/app/students/_components/OutstandingDropDown/index.tsx +++ b/apps/admin/app/students/_components/OutstandingDropDown/index.tsx @@ -10,16 +10,17 @@ import type { AchievementType } from "types/entities/achievement"; import DropDown from "wowds-ui/DropDown"; import DropDownOption from "wowds-ui/DropDownOption"; +import type { OutstandingStudentsType } from "@/students/_contexts/StudyProvider"; import { outstandingStudentsAtom } from "@/students/_contexts/StudyProvider"; import DropDownTrigger from "./DropDownTrigger"; -const OutstandingDropDown = ({ type }: { type: "ADD" | "DEL" }) => { +const OutstandingDropDown = ({ type }: { type: OutstandingStudentsType }) => { const setOutstandingStudents = useSetAtom(outstandingStudentsAtom); const findOptions = () => { - if (type === "ADD") return OUTSTANDING_ADD_OPTIONS; - if (type === "DEL") return OUTSTANDING_DEL_OPTIONS; + if (type === "처리") return OUTSTANDING_ADD_OPTIONS; + if (type === "철회") return OUTSTANDING_DEL_OPTIONS; return null; }; diff --git a/apps/admin/app/students/_components/StudentHeaderButtons.tsx b/apps/admin/app/students/_components/StudentHeaderButtons.tsx index a317c296..afc420bf 100644 --- a/apps/admin/app/students/_components/StudentHeaderButtons.tsx +++ b/apps/admin/app/students/_components/StudentHeaderButtons.tsx @@ -1,14 +1,11 @@ -import studyAchievementApi from "apis/study/studyAchievementApi"; -import { tags } from "constants/tags"; +import { outstandingRoundMap } from "constants/status/outstandigOptions"; import { useAtom, useAtomValue } from "jotai"; import Link from "next/link"; -import { revalidateTagByName } from "utils/revalidateTagByName"; import Button from "wowds-ui/Button"; import { outstandingStudentsAtom, selectedStudentsAtom, - studyAtom, } from "../_contexts/StudyProvider"; import OutstandingDropDown from "./OutstandingDropDown"; @@ -18,7 +15,6 @@ const StudentsHeaderButtons = () => { ); const { type, achievement, enabled } = outstandingStudents; const selectedStudents = useAtomValue(selectedStudentsAtom); - const study = useAtomValue(studyAtom); const handleClickCancelButton = () => { setOutstandingStudents({ @@ -27,42 +23,6 @@ const StudentsHeaderButtons = () => { }); }; - const handleClickEnabledButton = async () => { - if (!study || !selectedStudents.length || !achievement) return; - - const fetch = - type === "ADD" - ? studyAchievementApi.postStudyAchievement - : studyAchievementApi.deleteStudyAchievement; - - const result = await fetch(study.studyId, { - studentIds: selectedStudents, - achievementType: achievement, - }); - - if (result.success) { - // TODO: revalidate 되지 않는 문제 해결 - revalidateTagByName(tags.students); - } - - setOutstandingStudents({ - ...outstandingStudents, - enabled: false, - }); - }; - - const formatTypeToText = () => { - if (type === "ADD") return "우수 처리"; - if (type === "DEL") return "우수 철회"; - return ""; - }; - - const formatAchievementToText = () => { - if (achievement === "FIRST_ROUND_OUTSTANDING_STUDENT") return "1차"; - if (achievement === "SECOND_ROUND_OUTSTANDING_STUDENT") return "2차"; - return ""; - }; - return enabled ? ( <> ) : ( <> - - + + ); }; diff --git a/apps/admin/app/students/_contexts/StudyProvider.tsx b/apps/admin/app/students/_contexts/StudyProvider.tsx index d440188a..5489a6e4 100644 --- a/apps/admin/app/students/_contexts/StudyProvider.tsx +++ b/apps/admin/app/students/_contexts/StudyProvider.tsx @@ -11,7 +11,7 @@ export type StudyAtomprops = { title: ReactNode; }; -export type OutstandingStudentsType = "ADD" | "DEL"; +export type OutstandingStudentsType = "처리" | "철회"; export type OutstandingStudentsProps = { type?: OutstandingStudentsType; diff --git a/apps/admin/constants/status/outstandigOptions.ts b/apps/admin/constants/status/outstandigOptions.ts index 1d7b0393..33dcde62 100644 --- a/apps/admin/constants/status/outstandigOptions.ts +++ b/apps/admin/constants/status/outstandigOptions.ts @@ -14,3 +14,11 @@ export const OUTSTANDING_DEL_OPTIONS: OutstandingDropDownOption[] = [ { id: 1, text: "1차 우수 철회", value: "FIRST_ROUND_OUTSTANDING_STUDENT" }, { id: 2, text: "2차 우수 철회", value: "SECOND_ROUND_OUTSTANDING_STUDENT" }, ]; + +export const outstandingRoundMap: Record< + AchievementType, + "1차 우수" | "2차 우수" +> = { + FIRST_ROUND_OUTSTANDING_STUDENT: "1차 우수", + SECOND_ROUND_OUTSTANDING_STUDENT: "2차 우수", +};