From e2d85e0728cf375b39d73b4554a6cc2fe16dcaa8 Mon Sep 17 00:00:00 2001 From: minbo Date: Wed, 18 Sep 2024 18:54:53 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20getApplicantState=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20=EC=9C=A0=ED=8B=B8=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applicantNode/CustomResource.component.tsx | 18 ++++++++++-------- frontend/src/apis/applicant/index.ts | 13 ------------- frontend/src/utils/applicant/index.ts | 9 +++++++++ 3 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 frontend/src/utils/applicant/index.ts diff --git a/frontend/components/applicant/applicantNode/CustomResource.component.tsx b/frontend/components/applicant/applicantNode/CustomResource.component.tsx index ac47efa0..ce057872 100644 --- a/frontend/components/applicant/applicantNode/CustomResource.component.tsx +++ b/frontend/components/applicant/applicantNode/CustomResource.component.tsx @@ -1,10 +1,5 @@ import Txt from "@/components/common/Txt.component"; -import { - ApplicantReq, - getApplicantState, - getApplicantStateRes, - patchApplicantState, -} from "@/src/apis/applicant"; +import { ApplicantReq, patchApplicantState } from "@/src/apis/applicant"; import { applicantDataFinder } from "@/src/functions/finder"; import Portfolio from "./Portfolio"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; @@ -13,6 +8,8 @@ import KanbanCardApplicantStatusLabel from "@/components/kanban/card/CardApplica import { useAtomValue } from "jotai"; import { KanbanSelectedButtonNumberState } from "@/src/stores/kanban/Navbar.atoms"; import { getMyInfo } from "@/src/apis/interview"; +import { findApplicantState } from "@/src/utils/applicant"; +import { ApplicantPassState, getKanbanCards } from "@/src/apis/kanban"; interface ApplicantResourceProps { data: ApplicantReq[]; @@ -36,7 +33,12 @@ const ApplicantResource = ({ isError, } = useQuery({ queryKey: ["applicantState", applicantId, navbarId], - queryFn: () => getApplicantState(navbarId, `${applicantId}`, generation), + queryFn: async () => + findApplicantState( + await getKanbanCards(navbarId, generation), + `${applicantId}` + ), + staleTime: 3000, }); const { @@ -57,7 +59,7 @@ const ApplicantResource = ({ navbarId, ]); - const snapshotState = queryClient.getQueryData([ + const snapshotState = queryClient.getQueryData([ "applicantState", applicantId, navbarId, diff --git a/frontend/src/apis/applicant/index.ts b/frontend/src/apis/applicant/index.ts index 6bc7655d..355e65dc 100644 --- a/frontend/src/apis/applicant/index.ts +++ b/frontend/src/apis/applicant/index.ts @@ -147,16 +147,3 @@ export const patchApplicantState = async ( return data; }; - -export type getApplicantStateRes = ApplicantPassState | undefined; - -export const getApplicantState = async ( - navigationId: string, - applicantId: string, - generation: string -): Promise => { - const cardsData = await getKanbanCards(navigationId, generation); - - return cardsData.find((card) => card.applicantId === applicantId)?.state - .passState; -}; 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; +};