Skip to content

Commit

Permalink
fix: last-meeting 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJeongHooo authored and Andrevile committed Aug 27, 2024
1 parent 8ef90f2 commit 48b6144
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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('모임을 찾을 수 없습니다.');
Expand All @@ -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 };
Expand Down

0 comments on commit 48b6144

Please sign in to comment.