|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | +import { useRouter } from 'next/navigation' |
| 5 | + |
| 6 | +import { Button } from '@/shared/ui/button' |
| 7 | +import IconArrowLeft from '@/shared/assets/leftwards-arrow-bold.svg' |
| 8 | +import { |
| 9 | + AccountDeleteModalFlow, |
| 10 | + AccountDeleteNoticeCard, |
| 11 | + LinkedChannelsForDeleteCard, |
| 12 | +} from '@/widgets/me/accountDelete' |
| 13 | +import { useAuth } from '@/features/auth' |
| 14 | +import { useDeleteUser, type WithdrawalReason } from '@/features/me' |
| 15 | + |
| 16 | +export function MyAccountDeletePage() { |
| 17 | + const router = useRouter() |
| 18 | + const [open, setOpen] = useState(false) |
| 19 | + const { logout } = useAuth() |
| 20 | + const { mutateAsync: deleteUser } = useDeleteUser() |
| 21 | + |
| 22 | + async function handleSubmitReason( |
| 23 | + reason: WithdrawalReason, |
| 24 | + customReason?: string |
| 25 | + ) { |
| 26 | + await deleteUser({ |
| 27 | + reason, |
| 28 | + detail: reason === 'OTHER' ? customReason : undefined, |
| 29 | + }) |
| 30 | + } |
| 31 | + |
| 32 | + /* 탈퇴 완료 — 클라이언트 인증 상태 초기화 + refreshToken 쿠키 삭제 후 홈으로 이동 */ |
| 33 | + async function handleComplete() { |
| 34 | + setOpen(false) |
| 35 | + await logout() |
| 36 | + } |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className='flex h-fit w-full flex-col gap-24 p-24'> |
| 40 | + <button |
| 41 | + type='button' |
| 42 | + onClick={() => router.back()} |
| 43 | + className='flex w-fit cursor-pointer items-center gap-8 text-ibm-title-lg-normal text-text-and-icon-default'> |
| 44 | + <IconArrowLeft className='size-24' /> |
| 45 | + 계정 탈퇴 |
| 46 | + </button> |
| 47 | + |
| 48 | + <AccountDeleteNoticeCard /> |
| 49 | + <LinkedChannelsForDeleteCard /> |
| 50 | + |
| 51 | + <div className='flex justify-end'> |
| 52 | + <Button |
| 53 | + type='button' |
| 54 | + color='gray' |
| 55 | + variant='filled' |
| 56 | + size='sm' |
| 57 | + onClick={() => setOpen(true)}> |
| 58 | + 계정 탈퇴하기 |
| 59 | + </Button> |
| 60 | + </div> |
| 61 | + |
| 62 | + <AccountDeleteModalFlow |
| 63 | + open={open} |
| 64 | + onClose={() => setOpen(false)} |
| 65 | + onComplete={handleComplete} |
| 66 | + onSubmitReason={handleSubmitReason} |
| 67 | + /> |
| 68 | + </div> |
| 69 | + ) |
| 70 | +} |
0 commit comments