Skip to content

Commit

Permalink
fix: 처리, 철회 type으로 사용 및 outstandingRoundMap으로 1차, 2차 워딩 관리
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo-o committed Nov 17, 2024
1 parent 3bf1e64 commit 7bebb45
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -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 (
<Button size="sm" variant="outline">
우수 및 수료 {type === "ADD" ? "처리" : "철회"}
우수 및 수료 {type}
</Button>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
48 changes: 4 additions & 44 deletions apps/admin/app/students/_components/StudentHeaderButtons.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -18,7 +15,6 @@ const StudentsHeaderButtons = () => {
);
const { type, achievement, enabled } = outstandingStudents;
const selectedStudents = useAtomValue(selectedStudentsAtom);
const study = useAtomValue(studyAtom);

const handleClickCancelButton = () => {
setOutstandingStudents({
Expand All @@ -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 ? (
<>
<Button size="sm" variant="outline" onClick={handleClickCancelButton}>
Expand All @@ -74,13 +34,13 @@ const StudentsHeaderButtons = () => {
href={selectedStudents.length ? "/students/outstanding" : ""}
size="sm"
>
{`${formatAchievementToText()} ${formatTypeToText()}`}
{achievement && `${outstandingRoundMap[achievement]} ${type}`}
</Button>
</>
) : (
<>
<OutstandingDropDown type="ADD" />
<OutstandingDropDown type="DEL" />
<OutstandingDropDown type="처리" />
<OutstandingDropDown type="철회" />
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/app/students/_contexts/StudyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type StudyAtomprops = {
title: ReactNode;
};

export type OutstandingStudentsType = "ADD" | "DEL";
export type OutstandingStudentsType = "처리" | "철회";

export type OutstandingStudentsProps = {
type?: OutstandingStudentsType;
Expand Down
8 changes: 8 additions & 0 deletions apps/admin/constants/status/outstandigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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차 우수",
};

0 comments on commit 7bebb45

Please sign in to comment.