diff --git a/src/api/authApi.tsx b/src/api/authApi.tsx index d3ef2c2..d359b5b 100644 --- a/src/api/authApi.tsx +++ b/src/api/authApi.tsx @@ -43,3 +43,9 @@ export async function postRefereshToken() { console.log(error) } } + +// 회원 탈퇴 +export const userWithdrawal = async () => { + const response = await privateApi.delete('/my-page/withdrawal') + return response +} diff --git a/src/components/Main/Sidebar.tsx b/src/components/Main/Sidebar.tsx index 8ec83e2..4be05fe 100644 --- a/src/components/Main/Sidebar.tsx +++ b/src/components/Main/Sidebar.tsx @@ -10,6 +10,8 @@ import PATH from '@src/constants/pathConst' import useSidebar from '@src/hooks/useSidebar' import useLoginState from '@src/hooks/useLoginState' import { BoldCloseIcon, MyCommentIcon, MyHeartIcon, MyPageIcon, MyPostIcon } from '@src/constants/icons' +import { userWithdrawal } from '@src/api/authApi' +import useModal from '@src/hooks/useModal' const Sidebar = () => { const isMobile = useMediaQuery({ @@ -19,6 +21,7 @@ const Sidebar = () => { const { isSidebarOpen } = useSelector((state: RootState) => state.sidebar) const { closeSidebar } = useSidebar() const { accessAfterLoginAlert, logoutHandler } = useLoginState() + const { openModal } = useModal() useEffect(() => { if (!isMobile) { @@ -30,6 +33,27 @@ const Sidebar = () => { const userRole = useSelector((state: RootState) => state.userInfo.role) const refreshToken = getCookieToken() + const deleteAccount = async () => { + try { + const response = await userWithdrawal() + if (response.status === 200) { + logoutHandler() + openModal({ + isModalOpen: true, + isConfirm: false, + content: ['회원탈퇴에 성공했습니다.'], + navigateOption: PATH.HOME, + }) + } + } catch (error) { + openModal({ + isModalOpen: true, + isConfirm: false, + content: ['회원탈퇴에 실패했습니다. 고객센터로 문의해주세요.'], + }) + } + } + return ( @@ -174,7 +198,7 @@ const Sidebar = () => { > 로그아웃 -
console.log('회원탈퇴')}> +
deleteAccount()}> 회원탈퇴