|
1 | 1 | import { useUser } from '@react-query/hooks/useUser' |
2 | | -import React from 'react' |
| 2 | +import React, { useState } from 'react' |
3 | 3 | import SettingSection from './SettingSection' |
4 | 4 | import { ReactComponent as Front } from '@assets/front_white.svg' |
5 | 5 | import { useNavigate } from 'react-router-dom' |
| 6 | +import Alert from '@components/Alert' |
6 | 7 | import Loading from '@components/Loading' |
7 | 8 |
|
8 | 9 | export default function Setting() { |
9 | | - const { user, isLoading } = useUser() |
| 10 | + const { user, isLoading, logoutUser } = useUser() |
| 11 | + const [isClickedLogout, setIsClickedLogout] = useState(false) |
| 12 | + |
10 | 13 | const PADDING_VALUE = 24 |
11 | 14 |
|
12 | 15 | const navigate = useNavigate() |
13 | 16 |
|
| 17 | + const handleLogout = async () => { |
| 18 | + try { |
| 19 | + logoutUser() |
| 20 | + navigate('/') |
| 21 | + } catch (e) { |
| 22 | + alert('로그아웃에 실패하였습니다.') |
| 23 | + } |
| 24 | + } |
| 25 | + |
14 | 26 | const getPaddingIgnoreWidth = () => { |
15 | 27 | return `ml-[-${PADDING_VALUE}px] w-[calc(100%+${PADDING_VALUE * 2}px)]` |
16 | 28 | } |
@@ -73,12 +85,32 @@ export default function Setting() { |
73 | 85 | {user && ( |
74 | 86 | <div> |
75 | 87 | <div className={`h-[15px] ${getPaddingIgnoreWidth()} bg-grey-2`} /> |
76 | | - <section> |
| 88 | + <section |
| 89 | + id="logout-item-section" |
| 90 | + onClick={() => setIsClickedLogout(true)} |
| 91 | + > |
77 | 92 | <SettingSection routeText="로그아웃" /> |
| 93 | + </section> |
| 94 | + <section id="withdraw-item-section"> |
78 | 95 | <SettingSection routeText="회원탈퇴" routeUrl="/setting/withdraw" /> |
79 | 96 | </section> |
80 | 97 | </div> |
81 | 98 | )} |
| 99 | + {isClickedLogout && ( |
| 100 | + <Alert |
| 101 | + visible={true} |
| 102 | + mainMessage={ |
| 103 | + <> |
| 104 | + <span className="text-sub-1">로그아웃</span> 하시겠어요? |
| 105 | + </> |
| 106 | + } |
| 107 | + confirmMessage="둘러보기" |
| 108 | + cancelMessage="로그아웃" |
| 109 | + onConfirm={() => setIsClickedLogout(false)} |
| 110 | + onClose={() => setIsClickedLogout(false)} |
| 111 | + onCancel={handleLogout} |
| 112 | + /> |
| 113 | + )} |
82 | 114 | </div> |
83 | 115 | ) |
84 | 116 | } |
0 commit comments