Skip to content

Commit 90745ba

Browse files
committed
Merge branch 'develop' into FE-260
2 parents f1cd03a + 39260ad commit 90745ba

8 files changed

Lines changed: 131 additions & 11 deletions

File tree

src/apis/auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ export const getIsDuplicatedNickname = (nickname: string) => {
2323
export const logout = () => {
2424
return baseInstance.post(`/member/logout`)
2525
}
26+
27+
export const withdrawUser = () => {
28+
return baseInstance.delete(`/member/delete`)
29+
}

src/assets/close_icon.svg

Lines changed: 3 additions & 0 deletions
Loading

src/assets/moon_large.svg

Lines changed: 9 additions & 0 deletions
Loading

src/pages/Setting/Withdraw/CheckedNicknameBeforeWithDraw.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { useLocation, useNavigate } from 'react-router-dom'
33
import { NICKNAME_MAX_LENGTH } from '@assets/constant/constant'
44
import { ReactComponent as CloseIcon } from '@assets/icon_closed.svg'
55
import { ReactComponent as Back } from '@assets/back.svg'
6+
import { useUser } from '@react-query/hooks/useUser'
67
import useDebounce from '@hooks/useDebounce'
78
import Button from '@components/Button'
89
import Alert from '@components/Alert'
910

1011
export default function CheckedNicknameBeforeWithDraw() {
1112
const navigate = useNavigate()
1213
const { state } = useLocation()
14+
const { deleteUser } = useUser()
1315
const inputRef = useRef<HTMLInputElement>(null)
1416
const [isCheckedNickname, setIsCheckedNickname] = useState(false)
1517
const [nickname, setNickname] = useState('')
@@ -38,6 +40,15 @@ export default function CheckedNicknameBeforeWithDraw() {
3840
[nickname]
3941
)
4042

43+
const handleWithdraw = () => {
44+
try {
45+
deleteUser()
46+
navigate('/setting/withdraw/complete')
47+
} catch (e) {
48+
alert('로그아웃에 실패하였습니다.')
49+
}
50+
}
51+
4152
return (
4253
<>
4354
<section id="route-backIcon-button" className="ml-[18px] mt-4">
@@ -114,11 +125,11 @@ export default function CheckedNicknameBeforeWithDraw() {
114125
<br /> 재가입이 불가능해요.
115126
</>
116127
}
117-
confirmMessage=""
118-
cancelMessage="아니오"
128+
confirmMessage="둘러보기"
129+
cancelMessage="탈퇴하기"
119130
onConfirm={() => setAlertOpen(false)}
120131
onClose={() => setAlertOpen(false)}
121-
onCancel={() => setAlertOpen(false)}
132+
onCancel={handleWithdraw}
122133
/>
123134
</>
124135
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react'
2+
import { useNavigate } from 'react-router-dom'
3+
import Button from '@components/Button'
4+
import { ReactComponent as MoonIcon } from '@assets/moon_large.svg'
5+
import { ReactComponent as CloseIcon } from '@assets/close_icon.svg'
6+
7+
export default function CompletedWithdraw() {
8+
const navigate = useNavigate()
9+
10+
return (
11+
<>
12+
<CloseIcon
13+
className="ml-6 mt-4 cursor-pointer"
14+
onClick={() => navigate('/', { replace: true })}
15+
/>
16+
<div className="flex h-full flex-col items-center justify-center px-5">
17+
<MoonIcon className="mb-10" />
18+
<p className="mb-4 text-[20px] font-semibold leading-[30px] text-grey-10">
19+
레코딧 탈퇴가 완료되었습니다
20+
</p>
21+
<p className="mb-10 text-center text-[14px] leading-[21px]">
22+
<span className="text-primary-2">축하와 위로</span>가 필요할 때<br />
23+
언제든 다시 또 찾아주세요!
24+
</p>
25+
<Button
26+
disabled={false}
27+
property="solid"
28+
onClick={() => navigate('/', { replace: true })}
29+
>
30+
레코딧 둘러보기
31+
</Button>
32+
</div>
33+
</>
34+
)
35+
}

src/react-query/hooks/useUser.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { QUERY_KEYS } from '@react-query/queryKeys'
22
import { useQuery, useQueryClient } from '@tanstack/react-query'
33
import { getUserInfo } from '@apis/user'
4-
import { logout } from '@apis/auth'
4+
import { logout, withdrawUser } from '@apis/auth'
55

66
export const useUser = () => {
77
const queryClient = useQueryClient()
@@ -15,12 +15,20 @@ export const useUser = () => {
1515
refetchOnMount: false,
1616
refetchOnReconnect: false,
1717
refetchOnWindowFocus: false,
18+
onError: () => {
19+
queryClient.setQueriesData([QUERY_KEYS.user], null)
20+
},
1821
})
1922

2023
const logoutUser = async () => {
2124
await logout()
2225
queryClient.setQueriesData([QUERY_KEYS.user], null)
2326
}
2427

25-
return { user, refetch, isLoading, logoutUser }
28+
const deleteUser = async () => {
29+
await withdrawUser()
30+
queryClient.invalidateQueries()
31+
}
32+
33+
return { user, refetch, isLoading, logoutUser, deleteUser }
2634
}

src/routes/protectedRoute.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ProtectedRoute = ({ children, route }: RouteProps) => {
4343
)
4444
}
4545

46-
if (!user && route?.indexOf('myrecord')) {
46+
if (!user && route?.indexOf('myrecord') !== -1) {
4747
return (
4848
<Alert
4949
visible={true}
@@ -64,6 +64,26 @@ const ProtectedRoute = ({ children, route }: RouteProps) => {
6464
)
6565
}
6666

67+
if (!user && route?.indexOf('withdraw') !== -1) {
68+
return (
69+
<Alert
70+
visible={true}
71+
mainMessage={
72+
<div className="text-base font-semibold leading-6">
73+
비회원은 계정을
74+
<br />
75+
<span className="text-sub-1">탈퇴</span> 할 수 없어요
76+
</div>
77+
}
78+
cancelMessage="닫기"
79+
confirmMessage="로그인"
80+
onClose={() => navigate('/')}
81+
onCancel={() => navigate('/')}
82+
onConfirm={() => redirectPage('/setting')}
83+
/>
84+
)
85+
}
86+
6787
return children
6888
}
6989

src/routes/router.tsx

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const FeedbackMail = lazy(
2828
() => import('@pages/Setting/FeedbackMail/FeedbackMail')
2929
)
3030
const Withdraw = lazy(() => import('@pages/Setting/Withdraw/Withdraw'))
31+
const CheckedNicknameBeforeWithDraw = lazy(
32+
() => import('@pages/Setting/Withdraw/CheckedNicknameBeforeWithDraw')
33+
)
34+
const CompletedWithdraw = lazy(
35+
() => import('@pages/Setting/Withdraw/CompletedWithdraw')
36+
)
3137
const AddRecord = lazy(() => import('@pages/AddRecord/AddRecord'))
3238
const DetailRecord = lazy(() => import('@pages/DetailRecord/DetailRecord'))
3339

@@ -123,13 +129,37 @@ const router = createBrowserRouter([
123129
</Suspense>
124130
),
125131
},
132+
126133
{
127134
path: 'withdraw',
128-
element: (
129-
<Suspense fallback={<Loading />}>
130-
<Withdraw />
131-
</Suspense>
132-
),
135+
children: [
136+
{
137+
index: true,
138+
element: (
139+
<Suspense fallback={<Loading />}>
140+
<ProtectedRoute route={'/setting/withdraw'}>
141+
<Withdraw />
142+
</ProtectedRoute>
143+
</Suspense>
144+
),
145+
},
146+
{
147+
path: 'check',
148+
element: (
149+
<ProtectedRoute route={'/setting/withdraw/check'}>
150+
<CheckedNicknameBeforeWithDraw />
151+
</ProtectedRoute>
152+
),
153+
},
154+
{
155+
path: 'complete',
156+
element: (
157+
<ProtectedRoute route={'/setting/withdraw/complete'}>
158+
<CompletedWithdraw />
159+
</ProtectedRoute>
160+
),
161+
},
162+
],
133163
},
134164
],
135165
},

0 commit comments

Comments
 (0)