From 28e974cef5cf5b1bb6da2baf3f754941f1aacf12 Mon Sep 17 00:00:00 2001 From: solmee Date: Fri, 31 May 2024 01:05:44 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20LoginState,=20UserState,=20logout?= =?UTF-8?q?=EC=9D=84=20=EC=A0=84=EB=B6=80=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20useResetUserInfo=ED=9B=85=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useResetUserInfo.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/hooks/useResetUserInfo.ts diff --git a/src/hooks/useResetUserInfo.ts b/src/hooks/useResetUserInfo.ts new file mode 100644 index 00000000..7db29cc7 --- /dev/null +++ b/src/hooks/useResetUserInfo.ts @@ -0,0 +1,21 @@ +import { useSetRecoilState } from 'recoil'; + +import { LogInState } from '@/home/recoil/LogInState'; +import { UserState } from '@/home/recoil/UserState'; +import { api } from '@/service/TokenService'; + +const resetUserInfo = ( + resetLoginState: (value: boolean) => void, + resetUserState: (value: null) => void +) => { + resetLoginState(false); + resetUserState(null); + api.logout(); +}; + +export const useResetUserInfo = () => { + const resetLoginState = useSetRecoilState(LogInState); + const resetUserState = useSetRecoilState(UserState); + + return () => resetUserInfo(resetLoginState, resetUserState); +}; From 3ee2433c9e68baec84d014e4f8607117437aa1e7 Mon Sep 17 00:00:00 2001 From: solmee Date: Fri, 31 May 2024 01:08:20 +0900 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20=EA=B8=B0=EC=A1=B4=20postWithdraw=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=EC=97=90=EC=84=9C=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=B6=80=EB=B6=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/home/apis/postWithdraw.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/home/apis/postWithdraw.ts b/src/home/apis/postWithdraw.ts index e63284d6..fc379d4c 100644 --- a/src/home/apis/postWithdraw.ts +++ b/src/home/apis/postWithdraw.ts @@ -13,7 +13,6 @@ export const postWithdraw = async (): Promise => { headers: api.headers, } ); - api.logout(); return { success: true }; } catch (error) { if (isAxiosError(error)) return { success: false, error }; From c46d68e984576aa1a76baa3370b5728e0fac7c5b Mon Sep 17 00:00:00 2001 From: solmee Date: Fri, 31 May 2024 01:09:51 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20Withdraw=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=ED=83=88=ED=87=B4=20=EC=84=B1=EA=B3=B5=20=EC=8B=9C=20useResetU?= =?UTF-8?q?serInfo=20=EB=B6=88=EB=9F=AC=EC=99=80=EC=84=9C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/home/pages/Withdraw/Withdraw.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/home/pages/Withdraw/Withdraw.tsx b/src/home/pages/Withdraw/Withdraw.tsx index 8ad7563c..5c0a3aaf 100644 --- a/src/home/pages/Withdraw/Withdraw.tsx +++ b/src/home/pages/Withdraw/Withdraw.tsx @@ -6,6 +6,7 @@ import { useNavigate } from 'react-router-dom'; import Logo from '@/assets/soomsil_logo.svg'; import { postWithdraw } from '@/home/apis/postWithdraw'; import { WithdrawSuccess } from '@/home/components/WithdrawSuccess/WithdrawSuccess'; +import { useResetUserInfo } from '@/hooks/useResetUserInfo'; import { StyledButtonText, @@ -22,6 +23,7 @@ export const Withdraw = () => { const navigate = useNavigate(); const [agreed, setAgreed] = useState(false); const [draw, setDraw] = useState(false); + const resetUserInfo = useResetUserInfo(); const handleGoToHome = () => { navigate('/'); @@ -36,6 +38,7 @@ export const Withdraw = () => { const { success, error } = await postWithdraw(); if (success) { setDraw((prevDraw) => !prevDraw); + resetUserInfo(); } else if (error) { alert(`탈퇴 처리에 실패했습니다: ${error.message}`); } From 416f7d4ac1b4e64cc29608fe9088b7ca2a50dc21 Mon Sep 17 00:00:00 2001 From: solmee Date: Wed, 12 Jun 2024 15:30:00 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=20resetUserI?= =?UTF-8?q?nfo=EC=9C=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC=ED=96=88=EB=8D=98=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A5=BC=20=ED=95=98=EB=82=98=EB=A1=9C=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useResetUserInfo.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/hooks/useResetUserInfo.ts b/src/hooks/useResetUserInfo.ts index 7db29cc7..a4a4e549 100644 --- a/src/hooks/useResetUserInfo.ts +++ b/src/hooks/useResetUserInfo.ts @@ -4,18 +4,13 @@ import { LogInState } from '@/home/recoil/LogInState'; import { UserState } from '@/home/recoil/UserState'; import { api } from '@/service/TokenService'; -const resetUserInfo = ( - resetLoginState: (value: boolean) => void, - resetUserState: (value: null) => void -) => { - resetLoginState(false); - resetUserState(null); - api.logout(); -}; - export const useResetUserInfo = () => { const resetLoginState = useSetRecoilState(LogInState); const resetUserState = useSetRecoilState(UserState); - return () => resetUserInfo(resetLoginState, resetUserState); + return () => { + resetLoginState(false); + resetUserState(null); + api.logout(); + }; }; From 8b0af1176b2cde92045e1104eb3952450b9a1249 Mon Sep 17 00:00:00 2001 From: solmee Date: Thu, 20 Jun 2024 00:42:04 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20postWithdraw=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=84=20mutation=EC=9D=84=20=ED=99=9C=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20alert=20?= =?UTF-8?q?=EB=8C=80=EC=8B=A0=20errorboundary=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/home/apis/postWithdraw.ts | 22 ++---- src/home/pages/Withdraw/Withdraw.tsx | 113 ++++++++++++++------------- src/hooks/usePostWithdraw.ts | 17 ++++ 3 files changed, 80 insertions(+), 72 deletions(-) create mode 100644 src/hooks/usePostWithdraw.ts diff --git a/src/home/apis/postWithdraw.ts b/src/home/apis/postWithdraw.ts index fc379d4c..402e5a25 100644 --- a/src/home/apis/postWithdraw.ts +++ b/src/home/apis/postWithdraw.ts @@ -1,21 +1,9 @@ -import { isAxiosError } from 'axios'; - import { authClient } from '@/apis'; -import { PostWithdrawResponse, AuthErrorData } from '@/home/types/Auth.type'; import { api } from '@/service/TokenService'; -export const postWithdraw = async (): Promise => { - try { - await authClient.post( - '/auth/withdraw', - {}, - { - headers: api.headers, - } - ); - return { success: true }; - } catch (error) { - if (isAxiosError(error)) return { success: false, error }; - return Promise.reject(error); - } +export const postWithdraw = async (data: object) => { + const res = await authClient.post('/auth/withdraw', data, { + headers: api.headers, + }); + return res.data; }; diff --git a/src/home/pages/Withdraw/Withdraw.tsx b/src/home/pages/Withdraw/Withdraw.tsx index 5c0a3aaf..a31d0059 100644 --- a/src/home/pages/Withdraw/Withdraw.tsx +++ b/src/home/pages/Withdraw/Withdraw.tsx @@ -1,12 +1,13 @@ import { useState } from 'react'; import { BoxButton, CheckBox } from '@yourssu/design-system-react'; +import { ErrorBoundary } from 'react-error-boundary'; import { useNavigate } from 'react-router-dom'; import Logo from '@/assets/soomsil_logo.svg'; -import { postWithdraw } from '@/home/apis/postWithdraw'; +import { Fallback } from '@/components/Fallback/Fallback'; import { WithdrawSuccess } from '@/home/components/WithdrawSuccess/WithdrawSuccess'; -import { useResetUserInfo } from '@/hooks/useResetUserInfo'; +import { usePostWithdraw } from '@/hooks/usePostWithdraw'; import { StyledButtonText, @@ -23,7 +24,7 @@ export const Withdraw = () => { const navigate = useNavigate(); const [agreed, setAgreed] = useState(false); const [draw, setDraw] = useState(false); - const resetUserInfo = useResetUserInfo(); + const withdrawMutation = usePostWithdraw(); const handleGoToHome = () => { navigate('/'); @@ -33,61 +34,63 @@ export const Withdraw = () => { setAgreed((prevAgreed) => !prevAgreed); }; - const handleWithdrawAgree = async () => { - try { - const { success, error } = await postWithdraw(); - if (success) { - setDraw((prevDraw) => !prevDraw); - resetUserInfo(); - } else if (error) { - alert(`탈퇴 처리에 실패했습니다: ${error.message}`); + const handleWithdrawAgree = () => { + withdrawMutation.mutate( + {}, + { + onSuccess: () => { + setDraw((prevDraw) => !prevDraw); + }, } - } catch (error) { - if (error instanceof Error) { - alert(`탈퇴 처리 중 오류가 발생했습니다: ${error.message}`); - } else { - alert(`알 수 없는 오류가 발생했습니다`); - } - } + ); }; return ( - - Logo-image - - {draw ? ( - - ) : ( - <> - 계정 탈퇴 - 계정 탈퇴 전 꼭 확인하세요. - - 탈퇴하는 즉시 데이터가 제거되며, 복구가 불가능합니다. - - 닉네임, 이메일 등 사용자를 특정할 수 있는 모든 계정 정보가 지워집니다. - - - 등록된 글이나 댓글의 삭제를 원한다면 탈퇴 이전에 삭제하시기 바랍니다. - - - - - 안내사항을 확인하였으며, 이에 동의합니다. - - - - 탈퇴하기 - - - )} - - + + + Logo-image + + {draw ? ( + + ) : ( + <> + 계정 탈퇴 + 계정 탈퇴 전 꼭 확인하세요. + + + 탈퇴하는 즉시 데이터가 제거되며, 복구가 불가능합니다. + + + 닉네임, 이메일 등 사용자를 특정할 수 있는 모든 계정 정보가 지워집니다. + + + 등록된 글이나 댓글의 삭제를 원한다면 탈퇴 이전에 삭제하시기 바랍니다. + + + + + 안내사항을 확인하였으며, 이에 동의합니다. + + + + 탈퇴하기 + + + )} + + + ); }; diff --git a/src/hooks/usePostWithdraw.ts b/src/hooks/usePostWithdraw.ts new file mode 100644 index 00000000..e0b15d0d --- /dev/null +++ b/src/hooks/usePostWithdraw.ts @@ -0,0 +1,17 @@ +import { useMutation } from '@tanstack/react-query'; + +import { postWithdraw } from '@/home/apis/postWithdraw'; + +import { useResetUserInfo } from './useResetUserInfo'; + +export const usePostWithdraw = () => { + const resetUserInfo = useResetUserInfo(); + + return useMutation({ + mutationFn: postWithdraw, + onSuccess: () => { + resetUserInfo(); + }, + throwOnError: true, + }); +}; From 1e218f020a8099e43c9f5f4ace23b881c86af322 Mon Sep 17 00:00:00 2001 From: solmee Date: Fri, 21 Jun 2024 13:24:57 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20UserState=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useResetUserInfo.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/hooks/useResetUserInfo.ts b/src/hooks/useResetUserInfo.ts index a4a4e549..c31116ad 100644 --- a/src/hooks/useResetUserInfo.ts +++ b/src/hooks/useResetUserInfo.ts @@ -1,16 +1,13 @@ import { useSetRecoilState } from 'recoil'; import { LogInState } from '@/home/recoil/LogInState'; -import { UserState } from '@/home/recoil/UserState'; import { api } from '@/service/TokenService'; export const useResetUserInfo = () => { const resetLoginState = useSetRecoilState(LogInState); - const resetUserState = useSetRecoilState(UserState); return () => { resetLoginState(false); - resetUserState(null); api.logout(); }; };