Skip to content

Commit

Permalink
feat: add deleteUser function and update UserDeleteModal component
Browse files Browse the repository at this point in the history
  • Loading branch information
seonghunYang committed Apr 25, 2024
1 parent 259ed10 commit 364e312
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
64 changes: 32 additions & 32 deletions app/business/user/user.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,42 +23,42 @@ export async function signOut() {
}

export async function deleteUser(prevState: FormState, formData: FormData): Promise<FormState> {
// 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: '회원 탈퇴가 완료되었습니다.',
};
}

Expand Down
3 changes: 2 additions & 1 deletion app/ui/user/user-info-navigator/user-delete-modal.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,7 +14,7 @@ export default function UserDeleteModal() {
회원탈퇴를 진행하시겠습니까? 탈퇴를 진행하면더 비밀번호 입력이 필요합니다.
</p>
<div className="my-4">
<Form action={deleteUser} id={'user-delete'}>
<Form failMessageControl={'toast'} action={deleteUser} id={'user-delete'}>
<Form.PasswordInput label="비밀번호" id="password" placeholder="비밀번호를 입력하세요" required={true} />
<Form.SubmitButton label="탈퇴하기" position="center" variant="primary" />
</Form>
Expand Down

0 comments on commit 364e312

Please sign in to comment.