Skip to content
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 @@ -3,20 +3,21 @@
import { cn } from '@/components/common/ui/(shadcn)/lib/utils';
import Button from '@/components/common/ui/button';
import { Modal } from '@/components/common/ui/modal';
import { useWithdrawMemberMutation } from '@/hooks/queries/user/use-withdraw-member-mutation';

interface WithdrawalConfirmModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}

// TODO: withdrawal API not yet available — wire DELETE /api/v1/members/me when added
export default function WithdrawalConfirmModal({
open,
onOpenChange,
}: WithdrawalConfirmModalProps) {
const handleConfirm = async () => {
// TODO: call DELETE /api/v1/members/me and redirect to /
onOpenChange(false);
const { mutate: withdraw, isPending } = useWithdrawMemberMutation();

const handleConfirm = () => {
withdraw();
};

return (
Expand Down Expand Up @@ -88,6 +89,7 @@ export default function WithdrawalConfirmModal({
color="secondary"
size="medium"
className="flex-1"
disabled={isPending}
onClick={() => onOpenChange(false)}
>
취소
Expand All @@ -96,9 +98,10 @@ export default function WithdrawalConfirmModal({
color="primary"
size="medium"
className="flex-1"
disabled={isPending}
onClick={handleConfirm}
>
탈퇴하기
{isPending ? '탈퇴 중...' : '탈퇴하기'}
</Button>
</div>
</Modal.Footer>
Expand Down
25 changes: 25 additions & 0 deletions src/hooks/queries/user/use-withdraw-member-mutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useMutation } from '@tanstack/react-query';
import { axiosInstanceV6 } from '@/api/client/axios';
import { AUTH_ROUTE_PATHS } from '@/features/auth/model/auth-route';
import { clearClientAuthStateAndRedirect } from '@/features/auth/model/client-auth-cleanup';
import { useToastStore } from '@/stores/use-toast-store';
import { analyzeError, sendErrorToSentry } from '@/utils/error-handler';

export const useWithdrawMemberMutation = () => {
const showToast = useToastStore((state) => state.showToast);

return useMutation({
mutationFn: () =>
axiosInstanceV6.delete('mypage/class/withdraw', {
data: { agreedToClassWithdrawalNotice: true },
}),
onSuccess: () => {
clearClientAuthStateAndRedirect(AUTH_ROUTE_PATHS.LANDING);
},
onError: (error) => {
const errorInfo = analyzeError(error);
showToast(errorInfo.userMessage, 'error');
sendErrorToSentry(errorInfo, { source: 'useWithdrawMemberMutation' });
},
});
};
Loading