diff --git a/packages/web-domains/src/home/common/hooks/useSetCurrentMeeting.ts b/packages/web-domains/src/home/common/hooks/useSetCurrentMeeting.ts index 762a6ec6..65192436 100644 --- a/packages/web-domains/src/home/common/hooks/useSetCurrentMeeting.ts +++ b/packages/web-domains/src/home/common/hooks/useSetCurrentMeeting.ts @@ -37,6 +37,11 @@ export const useSetCurrentMeeting = () => { } } }; + useEffect(() => { + if (currentMeeting) { + setCurrentMeeting(null); + } + }, []); useEffect(() => { if (!currentMeeting) { diff --git a/packages/web-domains/src/user/features/get-user-info/services/useMeetingMemberService.ts b/packages/web-domains/src/user/features/get-user-info/services/useMeetingMemberService.ts index 81222f3e..1610bdab 100644 --- a/packages/web-domains/src/user/features/get-user-info/services/useMeetingMemberService.ts +++ b/packages/web-domains/src/user/features/get-user-info/services/useMeetingMemberService.ts @@ -1,23 +1,18 @@ +import { useQueryClient } from '@tanstack/react-query'; import { useRouter } from 'next/navigation'; import { useCreateMeetingMember, Params } from '@/common/apis/queries/useCreateMeetingMember'; +import { useUpdateLastMeeting } from '@/home/common/apis/mutations/useUpdateLastMeeting'; +import { MEETING_INFO_QUERY_KEY } from '@/home/common/apis/queries/useGetMeetingName'; export const useMeetingMemberService = () => { const router = useRouter(); - const { mutateAsync } = useCreateMeetingMember(); + const { mutateAsync: createMeetingMember } = useCreateMeetingMember(); + const { mutateAsync: updateLastMeeting } = useUpdateLastMeeting(); + const queryClient = useQueryClient(); const participateMeeting = async (params: Params) => { - await mutateAsync(params, { - onSuccess: () => { - // 멤버로 가입된 경우 - if (params.role === 'MEMBER') { - router.push(`/user/member/closing?inviteCode=${params.inviteCode}`); - } - // 오너로 가입된 경우 - if (params.role === 'OWNER') { - router.push(`/meeting/new/closing?inviteCode=${params.inviteCode}`); - } - }, + const { data } = await createMeetingMember(params, { onError: (res) => { if (res.response?.status === 404) { alert('모임을 찾을 수 없습니다.'); @@ -27,6 +22,22 @@ export const useMeetingMemberService = () => { } }, }); + await updateLastMeeting( + { meetingId: data.meetingId }, + { + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: [MEETING_INFO_QUERY_KEY] }); + // 멤버로 가입된 경우 + if (params.role === 'MEMBER') { + router.push(`/user/member/closing?inviteCode=${params.inviteCode}`); + } + // 오너로 가입된 경우 + if (params.role === 'OWNER') { + router.push(`/meeting/new/closing?inviteCode=${params.inviteCode}`); + } + }, + }, + ); }; return { participateMeeting };