diff --git a/src/hooks/useApplyProject.ts b/src/hooks/useApplyProject.ts index 2b119eae..3048dce0 100644 --- a/src/hooks/useApplyProject.ts +++ b/src/hooks/useApplyProject.ts @@ -1,9 +1,10 @@ -import { useMutation } from '@tanstack/react-query'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; import { MODAL_MESSAGE } from '../constants/modalMessage'; import { postApplicantProject } from '../api/joinProject.api'; import { ROUTES } from '../constants/routes'; import { useNavigate } from 'react-router-dom'; import { joinProject } from '../models/joinProject'; +import { ProjectListKey, userInfoKey } from './queries/keys'; interface UseApplyProjectProps { id: number; @@ -12,10 +13,21 @@ interface UseApplyProjectProps { const useApplyProject = ({ id, handleModalOpen }: UseApplyProjectProps) => { const navigate = useNavigate(); + const queryClient = useQueryClient(); + const userInfo = queryClient.getQueryData(userInfoKey.userProfile) as + | { id: number } + | undefined; + const userId = userInfo?.id; const mutation = useMutation({ mutationFn: (formData: joinProject) => postApplicantProject(formData, id), onSuccess: () => { + queryClient.invalidateQueries({ + queryKey: ProjectListKey.myAppliedStatusList, + }); + queryClient.invalidateQueries({ + queryKey: [userInfoKey.userJoinedList, userId], + }); handleModalOpen(MODAL_MESSAGE.applyProjectSuccess); setTimeout(() => {