From 364e3127137feeca04151a68d33ac7697180b47c Mon Sep 17 00:00:00 2001 From: SeonghunYang Date: Thu, 25 Apr 2024 13:01:37 +0000 Subject: [PATCH] feat: add deleteUser function and update UserDeleteModal component --- app/business/user/user.command.ts | 64 +++++++++---------- .../user-info-navigator/user-delete-modal.tsx | 3 +- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/app/business/user/user.command.ts b/app/business/user/user.command.ts index 4e01b2f2..6c234392 100644 --- a/app/business/user/user.command.ts +++ b/app/business/user/user.command.ts @@ -2,7 +2,7 @@ import { FormState } from '@/app/ui/view/molecule/form/form-root'; import { API_PATH } from '../api-path'; -import { SignUpRequestBody, SignInRequestBody, ValidateTokenResponse } from './user.type'; +import { SignUpRequestBody, SignInRequestBody, ValidateTokenResponse, UserDeleteRequestBody } from './user.type'; import { httpErrorHandler } from '@/app/utils/http/http-error-handler'; import { BadRequestError } from '@/app/utils/http/http-error'; import { @@ -23,42 +23,42 @@ export async function signOut() { } export async function deleteUser(prevState: FormState, formData: FormData): Promise { - // const body: SignUpRequestBody = { - // authId, - // }; - - // try { - // const response = await fetch(`${API_PATH.user}/sign-up`, { - // method: 'POST', - // headers: { - // 'Content-Type': 'application/json', - // }, - // body: JSON.stringify(body), - // }); - - // const result = await response.json(); - - // httpErrorHandler(response, result); - // } catch (error) { - // if (error instanceof BadRequestError) { - // // 잘못된 요청 처리 로직 - // return { - // isSuccess: false, - // isFailure: true, - // validationError: {}, - // message: error.message, - // }; - // } else { - // // 나머지 에러는 더 상위 수준에서 처리 - // throw error; - // } - // } + try { + const body: UserDeleteRequestBody = { + password: formData.get('password') as string, + }; + + const response = await fetch(`${API_PATH.user}/delete-me`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${cookies().get('accessToken')?.value}`, + }, + body: JSON.stringify(body), + }); + const result = await response.json(); + + httpErrorHandler(response, result); + } catch (error) { + if (error instanceof BadRequestError) { + // 잘못된 요청 처리 로직 + return { + isSuccess: false, + isFailure: true, + validationError: {}, + message: error.message, + }; + } else { + // 나머지 에러는 더 상위 수준에서 처리 + throw error; + } + } return { isSuccess: true, isFailure: false, validationError: {}, - message: '회원가입이 완료되었습니다.', + message: '회원 탈퇴가 완료되었습니다.', }; } diff --git a/app/ui/user/user-info-navigator/user-delete-modal.tsx b/app/ui/user/user-info-navigator/user-delete-modal.tsx index fd8ac051..2e18ad48 100644 --- a/app/ui/user/user-info-navigator/user-delete-modal.tsx +++ b/app/ui/user/user-info-navigator/user-delete-modal.tsx @@ -1,3 +1,4 @@ +'use client'; import { DIALOG_KEY } from '@/app/utils/key/dialog.key'; import Modal from '../../view/molecule/modal/modal'; import Form from '../../view/molecule/form'; @@ -13,7 +14,7 @@ export default function UserDeleteModal() { 회원탈퇴를 진행하시겠습니까? 탈퇴를 진행하면더 비밀번호 입력이 필요합니다.

-
+