-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
155 lines (137 loc) · 4.52 KB
/
index.tsx
File metadata and controls
155 lines (137 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import theme from '@styles/theme';
import { patchUserWithdrawApi } from '@apis/user';
import { getCurrentUserId } from '@utils/getCurrentUserId';
import back from '@assets/arrow/left.svg';
import BottomButton from '@components/BottomButton/index';
import { OODDFrame } from '@components/Frame/Frame';
import Modal from '@components/Modal/index';
import Skeleton from '@components/Skeleton';
import { StyledText } from '@components/Text/StyledText';
import TopBar from '@components/TopBar/index';
import {
CancelContainer,
SubTitle,
Text,
InfoBox,
InfoItem,
CheckboxWrapper,
CheckboxInput,
Label,
StyledCheckboxText,
} from './styles';
const AccountCancel: React.FC = () => {
const [isChecked, setIsChecked] = useState(false);
const [modalContent, setModalContent] = useState<string | null>(null);
const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState(true); // Loading state
const navigate = useNavigate();
useEffect(() => {
setTimeout(() => {
setIsLoading(false);
}, 1000);
}, []);
const handleCheckboxChange = () => {
setIsChecked(!isChecked);
};
const handleModalClose = () => {
setIsModalVisible(false);
setModalContent(null);
};
const handleDeleteAccount = async () => {
try {
if (!isChecked) {
setModalContent('탈퇴 안내사항에 동의해야 합니다.');
setIsModalVisible(true);
return;
}
const currentUserId = getCurrentUserId();
const token = localStorage.getItem('new_jwt_token');
if (!currentUserId || !token) {
setModalContent('사용자 정보를 찾을 수 없습니다.');
setIsModalVisible(true);
return;
}
const response = await patchUserWithdrawApi(currentUserId);
if (response.isSuccess) {
setModalContent('계정이 성공적으로 삭제되었습니다.');
setIsModalVisible(true);
localStorage.clear();
setTimeout(() => {
navigate('/login');
}, 2000);
} else {
setModalContent(response.code || '알 수 없는 오류가 발생했습니다.');
setIsModalVisible(true);
}
} catch (error) {
console.error('계정 삭제하는데 오류남:', error);
setModalContent('계정을 삭제하는 동안 오류가 발생했습니다. 다시 시도해 주세요.');
setIsModalVisible(true);
}
};
if (isLoading) {
return (
<OODDFrame>
<CancelContainer>
<TopBar text="회원 탈퇴" LeftButtonSrc={back} onClickLeftButton={() => navigate(-1)} />
<SubTitle>
<StyledText as="div" $textTheme={{ style: 'headline2-medium' }} color={theme.colors.text.primary}>
OOTD 탈퇴 전 확인하세요!
<Skeleton width="100%" height={25} />
</StyledText>
</SubTitle>
</CancelContainer>
<BottomButton content="탈퇴하기" onClick={handleDeleteAccount} disabled={!isChecked} />
</OODDFrame>
);
}
return (
<OODDFrame>
<CancelContainer>
<TopBar text="회원 탈퇴" LeftButtonSrc={back} onClickLeftButton={() => navigate(-1)} />
<SubTitle>
<StyledText as="div" $textTheme={{ style: 'headline2-medium' }} color={theme.colors.text.primary}>
OOTD 탈퇴 전 확인하세요!
</StyledText>
</SubTitle>
<Text as="div">
<StyledText as="div" $textTheme={{ style: 'caption1-regular' }} color={theme.colors.text.primary}>
{`탈퇴하시면 이용 중인 서비스가 폐쇄되며,\n모든 데이터는 복구할 수 없습니다.`}
</StyledText>
</Text>
<InfoBox>
<InfoItem as="div">
<StyledText
as="div"
$textTheme={{ style: 'body1-medium' }}
color={theme.colors.text.primary}
style={{ whiteSpace: 'nowrap' }}
>
지금까지 OODD를 이용해주셔서 감사합니다!
</StyledText>
</InfoItem>
</InfoBox>
<CheckboxWrapper as="div">
<Label>
<CheckboxInput type="checkbox" checked={isChecked} onChange={handleCheckboxChange} />
<StyledCheckboxText as="span" $textTheme={{ style: 'body2-regular' }}>
안내사항을 모두 확인하였으며, 이에 동의합니다.
</StyledCheckboxText>
</Label>
</CheckboxWrapper>
</CancelContainer>
<BottomButton content="탈퇴하기" onClick={handleDeleteAccount} disabled={!isChecked} />
{isModalVisible && (
<Modal
content={modalContent || ''}
onClose={handleModalClose}
isCloseButtonVisible={true}
button={{ content: '확인', onClick: handleModalClose }}
/>
)}
</OODDFrame>
);
};
export default AccountCancel;