diff --git a/frontend/components/applicant/DetailLeft.component.tsx b/frontend/components/applicant/DetailLeft.component.tsx index 7abe5b3f..f227c47b 100644 --- a/frontend/components/applicant/DetailLeft.component.tsx +++ b/frontend/components/applicant/DetailLeft.component.tsx @@ -24,7 +24,7 @@ const ApplicantDetailLeft = ({ return ( <> - + { +const ApplicantResource = ({ + data, + postId, + generation, +}: ApplicantResourceProps) => { + const navbarId = useAtomValue(KanbanSelectedButtonNumberState); + const searchParams = useSearchParams(); + const applicantId = searchParams.get("applicantId"); + const queryClient = useQueryClient(); + + const { + data: initialState, + isLoading, + isError, + } = useQuery({ + queryKey: ["applicantState", applicantId, navbarId], + queryFn: async () => + findApplicantState( + await getKanbanCards(navbarId, generation), + `${applicantId}` + ), + staleTime: 3000, + }); + + const { + data: myInfo, + isLoading: myInfoLoading, + isError: myInfoError, + } = useQuery({ + queryKey: ["user"], + queryFn: getMyInfo, + }); + const { mutate } = useMutation({ + mutationFn: (afterState: "non-pass" | "pass") => + patchApplicantState(`${applicantId}`, afterState), + onMutate: async () => { + await queryClient.cancelQueries([ + "applicantState", + applicantId, + navbarId, + ]); + + const snapshotState = queryClient.getQueryData([ + "applicantState", + applicantId, + navbarId, + ]); + + return { snapshotState }; + }, + onSuccess: () => { + queryClient.invalidateQueries(["kanbanDataArray", generation]); + }, + onError: (error, variables, context) => { + window.alert("상태 변경에 실패했습니다."); + }, + onSettled: () => { + queryClient.invalidateQueries(["applicantState", applicantId, navbarId]); + }, + }); + + const onFailedButtonClick = () => { + mutate("non-pass"); + }; + + const onPassedButtonClick = () => { + mutate("pass"); + }; + + if (!initialState || isLoading || !myInfo || myInfoLoading) { + return
로딩중...
; + } + + if (isError || myInfoError) { + return
에러 발생
; + } + return ( <> -
- - {applicantDataFinder(data, "major")} - - {`[${applicantDataFinder( - data, - "field" - )}] ${applicantDataFinder(data, "name")}`} +
+
+
+ + {applicantDataFinder(data, "major")} + + +
+ {`[${applicantDataFinder( + data, + "field" + )}] ${applicantDataFinder(data, "name")}`} +
+ {(myInfo.role === "ROLE_OPERATION" || + myInfo.role === "ROLE_PRESIDENT") && ( +
+ + +
+ )}
diff --git a/frontend/components/kanban/column/ColumnWithBackButton.component.tsx b/frontend/components/kanban/column/ColumnWithBackButton.component.tsx index 423669d7..89caab0c 100644 --- a/frontend/components/kanban/column/ColumnWithBackButton.component.tsx +++ b/frontend/components/kanban/column/ColumnWithBackButton.component.tsx @@ -30,9 +30,11 @@ const KanbanColumnDetailCard = ({ data: kanbanDataArray, isError, isLoading, - } = useQuery(["kanbanDataArray", generation], () => - getAllKanbanData(navbarId, generation) - ); + } = useQuery({ + queryKey: ["kanbanDataArray", generation], + queryFn: () => getAllKanbanData(navbarId, generation), + staleTime: 3000, + }); if (!kanbanDataArray || isLoading) { return
로딩중...
; diff --git a/frontend/src/apis/applicant/index.ts b/frontend/src/apis/applicant/index.ts index a2a5db74..355e65dc 100644 --- a/frontend/src/apis/applicant/index.ts +++ b/frontend/src/apis/applicant/index.ts @@ -1,6 +1,7 @@ import { getAllInterviewerWithOrder } from "@/src/apis/interview"; import { APPLICANT_KEYS } from "@/src/constants"; import { https } from "@/src/functions/axios"; +import { ApplicantPassState, getKanbanCards, KanbanCardReq } from "../kanban"; export interface ApplicantReq { name: string; @@ -131,3 +132,18 @@ export const getApplicantTimeTables = async (id: string) => { return data; }; + +interface PatchApplicantStateRes { + passState: ApplicantPassState; +} + +export const patchApplicantState = async ( + id: string, + afterState: "non-pass" | "pass" +) => { + const { data } = await https.patch( + `/applicants/${id}/state?afterState=${afterState}` + ); + + return data; +}; diff --git a/frontend/src/utils/applicant/index.ts b/frontend/src/utils/applicant/index.ts new file mode 100644 index 00000000..3210c4aa --- /dev/null +++ b/frontend/src/utils/applicant/index.ts @@ -0,0 +1,9 @@ +import { KanbanCardReq } from "@/src/apis/kanban"; + +export const findApplicantState = ( + cardsData: KanbanCardReq[], + applicantId: string +) => { + return cardsData.find((card) => card.applicantId === applicantId)?.state + .passState; +};