Skip to content

Commit

Permalink
fix: 삭제, 탈퇴 후 페이지이동 클라이언트단 x
Browse files Browse the repository at this point in the history
  • Loading branch information
phnml1 committed Dec 21, 2024
1 parent 92ad157 commit 50da5d7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export function ButtonGroup({ groupId }: { groupId: number }) {
const { status } = await leaveGroup();
if (status === 'success') {
alert('그룹 탈퇴에 성공했습니다!');
router.push('/group/history');
} else {
alert('그룹 탈퇴중 오류가 발생했습니다.');
}
Expand All @@ -43,7 +42,6 @@ export function ButtonGroup({ groupId }: { groupId: number }) {
const { status } = await deleteGroup();
if (status === 'success') {
alert('그룹 삭제에 성공했습니다!');
router.push('/group/history');
} else {
alert('그룹 삭제중 오류가 발생했습니다.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function fetchDeleteGroup(groupId: number) {
credentials: 'include',
cache: 'no-cache',
});
return response.data;
return response;
} catch (error) {
console.error(error);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { fetchDeleteGroup } from '../_lib/fetchDeleteGroup';
import { useRouter } from 'next/router';
import { redirect } from 'next/navigation';

export function useDeleteGroupMutation(groupId: number) {
const queryClient = useQueryClient();
Expand All @@ -11,10 +12,8 @@ export function useDeleteGroupMutation(groupId: number) {
return await fetchDeleteGroup(groupId); // 그룹 탈퇴 API 호출
},
onSuccess: (data) => {
if (data.status === 204) {
queryClient.removeQueries({queryKey:['groupDetail', groupId]});
queryClient.invalidateQueries({queryKey: ['currentGroups']});
queryClient.invalidateQueries({queryKey: ['previousGroups']});
if (data.status === 'success') {
window.location.href = '/group/history';
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ export function useLeaveGroupMutation(groupId: number) {
return await fetchLeaveGroup(groupId); // 그룹 탈퇴 API 호출
},
onSuccess: (data) => {
if (data.status === 204) {
queryClient.removeQueries({queryKey:['groupDetail', groupId]});
queryClient.invalidateQueries({queryKey: ['currentGroups']});
queryClient.invalidateQueries({queryKey: ['previousGroups']});
if (data.status === 'success') {
window.location.href = '/group/history'
}
}
});
Expand Down

0 comments on commit 50da5d7

Please sign in to comment.