Skip to content

Commit 5de28b0

Browse files
authored
Merge pull request #234 from DevKor-github/feat/#233/delete-user
[#233] 회원 탈퇴 구현 구현
2 parents cec39d0 + d8e92ae commit 5de28b0

4 files changed

Lines changed: 84 additions & 18 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import client from '@/common/utils/client';
2+
import { QUERY_KEYS } from '@/libs/queryKeys';
3+
import { useMutation, useQueryClient } from '@tanstack/react-query';
4+
5+
const deleteUser = async () => {
6+
const response = await client.delete('/api/v1/user');
7+
return response.data;
8+
};
9+
10+
export const useDeleteUser = () => {
11+
const queryClient = useQueryClient();
12+
13+
return useMutation({
14+
mutationFn: deleteUser,
15+
onSuccess: () => {
16+
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.USER] });
17+
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.IS_LOGIN] });
18+
},
19+
});
20+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import CustomAlert from '@/common/components/CustomAlert';
2+
import { useToast } from '@/common/hooks/useToast';
3+
import { useDeleteUser } from '@/features/my/apis/useDeleteUser';
4+
import { cx } from '@styled-system/css';
5+
6+
import * as s from './style.css';
7+
import { useState } from 'react';
8+
9+
const DeleteAccountButton = () => {
10+
const { openToast } = useToast();
11+
const { mutate: deleteUser } = useDeleteUser();
12+
const [showDeleteAlert, setShowDeleteAlert] = useState(false);
13+
14+
const handleDelete = () => {
15+
deleteUser(undefined, {
16+
onSuccess: () => {
17+
openToast({ message: '회원탈퇴 완료!' });
18+
},
19+
});
20+
setShowDeleteAlert(false);
21+
};
22+
23+
return (
24+
<>
25+
<button className={s.GoMenu} onClick={() => setShowDeleteAlert(true)}>
26+
<div className={s.MenuContent}>
27+
<span className={cx(`mgc_user_x_fill`)} />
28+
회원 탈퇴
29+
</div>
30+
<div className={cx('mgc_right_line', s.Icon)} />
31+
</button>
32+
{showDeleteAlert && (
33+
<CustomAlert
34+
title="회원 탈퇴 후 복구가 불가능해요!"
35+
subTitle="정말 탈퇴하실 건가요?"
36+
yesBtn="네, 탈퇴할게요"
37+
onNo={() => setShowDeleteAlert(false)}
38+
onYes={handleDelete}
39+
/>
40+
)}
41+
</>
42+
);
43+
};
44+
export default DeleteAccountButton;

src/features/my/components/MyTrade/index.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Link } from 'react-router';
44
import { usePostLogout } from '../../apis/usePostLogout';
55
import { useToast } from '@/common/hooks/useToast';
66
import { REPICKA_INSTAGRAM } from '@/libs/constants';
7+
import DeleteAccountButton from '@/features/my/components/MyTrade/DeleteAccountButton';
78

89
interface MenuProps {
910
Title: string;
@@ -28,35 +29,35 @@ const Menu = ({ Title, Icon, Addr }: MenuProps) => {
2829
);
2930
}
3031

31-
if (Title !== '로그아웃') {
32+
if (Title === '로그아웃') {
3233
return (
33-
<Link className={s.GoMenu} to={Addr}>
34+
<button
35+
className={s.GoMenu}
36+
onClick={() => {
37+
postLogout(undefined, {
38+
onSuccess: () => {
39+
openToast({ message: '로그아웃 완료!' });
40+
},
41+
});
42+
}}
43+
>
3444
<div className={s.MenuContent}>
3545
<span className={cx(`${Icon}`)} />
3646
{Title}
3747
</div>
3848
<div className={cx('mgc_right_line', s.Icon)} />
39-
</Link>
49+
</button>
4050
);
4151
}
4252

4353
return (
44-
<button
45-
className={s.GoMenu}
46-
onClick={() => {
47-
postLogout(undefined, {
48-
onSuccess: () => {
49-
openToast({ message: '로그아웃 완료!' });
50-
},
51-
});
52-
}}
53-
>
54+
<Link className={s.GoMenu} to={Addr}>
5455
<div className={s.MenuContent}>
5556
<span className={cx(`${Icon}`)} />
5657
{Title}
5758
</div>
5859
<div className={cx('mgc_right_line', s.Icon)} />
59-
</button>
60+
</Link>
6061
);
6162
};
6263

@@ -69,6 +70,7 @@ const MyTrade = () => {
6970
<Menu Icon="mgc_shopping_bag_1_fill" Title="나의 판매 내역" Addr="/my-trade" />
7071
<Menu Icon="mgc_instagram_line" Title="문의하기" Addr="/my-trade" />
7172
<Menu Icon="mgc_exit_fill" Title="로그아웃" Addr="/my-trade" />
73+
<DeleteAccountButton />
7274
</div>
7375
</div>
7476
);

src/pages/LoginPage/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import AppleLogo from '@/libs/assets/AppleLogo';
1212
const LoginPage = () => {
1313
const navigate = useNavigate();
1414
const { data: isLogin, isLoading } = useGetIsLogin();
15-
const redirectionUrl = encodeURIComponent(window.location.origin + '/');
15+
const redirectUrl = import.meta.env.VITE_REDIRECT_URL || undefined;
1616

1717
useEffect(() => {
1818
if (isLogin) {
@@ -32,21 +32,21 @@ const LoginPage = () => {
3232
<div className={s.ButtonContainer}>
3333
<a
3434
className={s.LoginButton({ src: 'apple' })}
35-
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/apple?redirectURI=${redirectionUrl}`}
35+
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/apple${redirectUrl ? `?redirectURI=${redirectUrl}` : ''}`}
3636
>
3737
<AppleLogo />
3838
Apple로 로그인
3939
</a>
4040
<a
4141
className={s.LoginButton({ src: 'google' })}
42-
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/google?redirectURI=${redirectionUrl}`}
42+
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/google${redirectUrl ? `?redirectURI=${redirectUrl}` : ''}`}
4343
>
4444
<GoogleLogo />
4545
Google로 로그인
4646
</a>
4747
<a
4848
className={s.LoginButton({ src: 'kakao' })}
49-
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/kakao?redirectURI=${redirectionUrl}`}
49+
href={`${import.meta.env.VITE_API_URL}/oauth2/authorization/kakao${redirectUrl ? `?redirectURI=${redirectUrl}` : ''}`}
5050
>
5151
<KakaoLogo />
5252
카카오톡으로 로그인

0 commit comments

Comments
 (0)