diff --git a/src/apis/unregisterService.ts b/src/apis/unregisterService.ts new file mode 100644 index 0000000..a68729b --- /dev/null +++ b/src/apis/unregisterService.ts @@ -0,0 +1,7 @@ +import fetchApi from "@apis/ky"; +import { logoutPost } from "@apis/logoutService"; + +export const unregisterDelete = async () => { + await fetchApi.delete('members/me') + logoutPost() +} \ No newline at end of file diff --git a/src/constants/alertMessage.ts b/src/constants/alertMessage.ts index 46f98df..7747f70 100644 --- a/src/constants/alertMessage.ts +++ b/src/constants/alertMessage.ts @@ -64,6 +64,13 @@ const ALERT_MESSAGE = { actionText: '삭제하기', cancelText: '취소', }, + + UNREGISTER: { + title: '회원 탈퇴', + notice: '회원 탈퇴하시겠습니까?', + actionText: '탈퇴하기', + cancelText: '취소', + }, } export type AlertMessage = keyof typeof ALERT_MESSAGE diff --git a/src/layouts/GlobalNav/index.tsx b/src/layouts/GlobalNav/index.tsx index c5e6c27..5d4cb26 100644 --- a/src/layouts/GlobalNav/index.tsx +++ b/src/layouts/GlobalNav/index.tsx @@ -13,7 +13,6 @@ import UserIconFill from '@assets/icon/nav_user_fill.svg?react' import { Link, useLocation } from 'react-router-dom' import { ROUTE_PATH } from '@constants/ROUTE_PATH' import { useEffect, useState } from 'react' -import { useUserStore } from '@store/useUserStore' const GlobalNav = () => { const { pathname } = useLocation() @@ -36,32 +35,53 @@ const GlobalNav = () => { - - {pathname === ROUTE_PATH.MATE_LIST ? ( - - ) : ( + {isLogin ? ( + + {pathname === ROUTE_PATH.MATE_LIST ? ( + + ) : ( + + )} + 메이트 찾기 + + ) : ( + - )} - 메이트 찾기 - + 메이트 찾기 + + )} - - {pathname === ROUTE_PATH.GOODS_LIST ? ( - - ) : ( + {isLogin ? ( + + {pathname === ROUTE_PATH.GOODS_LIST ? ( + + ) : ( + + )} + 굿즈거래 + + ) : ( + - )} - 굿즈거래 - + 굿즈거래 + + )} - - {pathname === ROUTE_PATH.CHAT ? : } - 채팅 - + {isLogin ? ( + + {pathname === ROUTE_PATH.CHAT ? : } + 채팅 + + ) : ( + + + 채팅 + + )} diff --git a/src/pages/ProfilePage/ProfileMain.tsx b/src/pages/ProfilePage/ProfileMain.tsx index 8292cd2..839dc5b 100644 --- a/src/pages/ProfilePage/ProfileMain.tsx +++ b/src/pages/ProfilePage/ProfileMain.tsx @@ -31,10 +31,14 @@ import { UserInfo } from '@typings/userForm' import Alert from '@components/Alert' import ALERT_MESSAGE from '@constants/alertMessage' import { logoutPost } from '@apis/logoutService' +import { unregisterDelete } from '@apis/unregisterService' import { formatManner } from '@utils/formatManner' + const ProfileMain = () => { - const alertRef = useRef(null) + const logoutAlertRef = useRef(null) // 로그아웃용 ref + const unregisterAlertRef = useRef(null) // 회원탈퇴용 ref + const navigate = useNavigate() const { id } = useParams() @@ -50,17 +54,17 @@ const ProfileMain = () => { ) const handleLogoutClick = () => { - if (alertRef.current) { - alertRef.current.showModal() + if (logoutAlertRef.current) { + logoutAlertRef.current.showModal() } } const confirmLogout = async () => { try { await logoutPost() - localStorage.removeItem('token') - if (alertRef.current) { - alertRef.current.close() + localStorage.clear() + if (logoutAlertRef.current) { + logoutAlertRef.current.close() } navigate(ROUTE_PATH.HOME) } catch (error) { @@ -102,7 +106,7 @@ const ProfileMain = () => { onLogoutClick={handleLogoutClick} /> { ) : null} + + { + if (unregisterAlertRef.current) { + unregisterAlertRef.current.showModal() + } + }} + /> + + { + try { + await unregisterDelete() + localStorage.clear() + navigate(ROUTE_PATH.HOME) + toast.success('회원탈퇴가 완료되었습니다.') + } catch (error) { + console.error('회원탈퇴 실패:', error) + toast.error('회원탈퇴에 실패했습니다. 다시 시도해주세요.') + } + }} + /> )