Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 모임생성시 생성된 모임으로 이동 #164

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export const useSetCurrentMeeting = () => {
}
}
};
useEffect(() => {
if (currentMeeting) {
setCurrentMeeting(null);
}
}, []);

useEffect(() => {
if (!currentMeeting) {
Expand Down
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
Loading