Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

[FE] feat: 회원 탈퇴 기능 구현 #412

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/src/apis/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ import { http } from './fetch';

// 멤버페이지 정보 조회: GET
export const getMemberInfo = () => http.get(memberURL);

// 멤버 탈퇴: POST
export const deleteMemberAccount = () => http.post(`${memberURL}/delete`);
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import Modal from 'components/@common/Modal/Modal';
import { useMemberDelete } from 'hooks/queries/member/useMemberDelete';
import { styled } from 'styled-components';

type Props = {
isOpen: boolean;
closeModal: () => void;
};

const DeleteAccountModal = ({ isOpen, closeModal }: Props) => {
const deleteMember = useMemberDelete();

const deleteAccount = () => {
deleteMember.mutate();
};

return (
<Modal isOpen={isOpen} closeModal={closeModal}>
<S.Container>
<S.Title>회원 탈퇴</S.Title>
<S.Content>
<p>탈퇴 시, 회원 정보가 모두 삭제되고 재가입 시 복원되지 않습니다.</p>
<p>정말 탈퇴하시겠습니까?</p>
</S.Content>
<S.ButtonContainer>
<S.DeleteAccountButton onClick={deleteAccount}>탈퇴</S.DeleteAccountButton>
<S.CancelButton onClick={closeModal}>취소</S.CancelButton>
</S.ButtonContainer>
</S.Container>
</Modal>
);
};

export default DeleteAccountModal;

const S = {
Container: styled.div`
display: flex;
flex-direction: column;
align-items: center;
gap: 3rem;
width: 50vw;
max-width: 40rem;
`,
Title: styled.h1`
font-size: 2rem;
font-weight: 700;
`,
Content: styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 1rem;
height: 100%;
margin: 2rem 0;
font-size: 1.3rem;
`,
ButtonContainer: styled.div`
display: flex;
gap: 1rem;
button {
padding: 1rem 6rem;
border-radius: 8px;
}
`,
DeleteAccountButton: styled.button`
border: 2px solid ${({ theme }) => theme.color.red5};
background-color: ${({ theme }) => theme.color.red5};
color: ${({ theme }) => theme.color.gray1};

&:hover {
border: 2px solid ${({ theme }) => theme.color.red6};
background-color: ${({ theme }) => theme.color.red6};
}
`,
CancelButton: styled.button`
border: 2px solid ${({ theme }) => theme.color.gray4};
background-color: ${({ theme }) => theme.color.gray4};

&:hover {
border: 2px solid ${({ theme }) => theme.color.gray5};
background-color: ${({ theme }) => theme.color.gray5};
}
`,
};
26 changes: 22 additions & 4 deletions frontend/src/components/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { DefaultUserProfileIcon } from 'assets/icons';
import DeleteAccountModal from 'components/Modal/DeleteAccountModal.tsx/DeleteAccountModal';
import { useModal } from 'hooks/@common/useModal';
import { styled } from 'styled-components';

type Props = {
name: string;
};

const Profile = ({ name }: Props) => {
const { isOpen, openModal, closeModal } = useModal();

return (
<S.Profile>
<DefaultUserProfileIcon />
{name}
</S.Profile>
<>
<S.Profile>
<DefaultUserProfileIcon />
{name}
<S.DeleteAccountButton onClick={openModal}>탈퇴하기</S.DeleteAccountButton>
</S.Profile>
<DeleteAccountModal isOpen={isOpen} closeModal={closeModal} />
</>
);
};

Expand All @@ -30,4 +38,14 @@ const S = {
font-size: 2rem;
font-weight: bold;
`,
DeleteAccountButton: styled.button`
padding: 0.1rem 0;
color: ${({ theme }) => theme.color.gray7};
border-bottom: 1px solid ${({ theme }) => theme.color.gray6};

&:hover {
color: ${({ theme }) => theme.color.gray8};
border-bottom: 1px solid ${({ theme }) => theme.color.gray7};
}
`,
};
21 changes: 21 additions & 0 deletions frontend/src/hooks/queries/member/useMemberDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useMutation } from '@tanstack/react-query';
import { deleteMemberAccount } from 'apis/member';
import { useToast } from 'hooks/@common/useToast';
import { usePageNavigate } from 'hooks/usePageNavigate';
import { getErrorMessage } from 'utils/error';

export const useMemberDelete = () => {
const toast = useToast();
const { goIntroducePage } = usePageNavigate();

return useMutation(deleteMemberAccount, {
onSuccess: () => {
localStorage.removeItem('accessToken');
goIntroducePage();
toast.show({ type: 'success', message: '탈퇴가 완료되었습니다.' });
},
onError: (error) => {
toast.show({ type: 'error', message: getErrorMessage(error) });
},
});
Comment on lines +11 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutate 를 따로 분리해서 리턴하지 않고 객체 자체를 리턴하신 이유는 mutate 이외에도 사용하는 프로퍼티가 있어서 그런가용?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 이제 공통으로 뺐으니까 다른 프로퍼티를 사용할 수도 있으니 바로 리턴하였습니다.
쿼리 훅 분리하면 다 이런식으로 바뀔 것 같아요~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 그렇군요 이해했습니다~!

};
5 changes: 5 additions & 0 deletions frontend/src/mocks/handlers/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ export const memberHandlers = [
rest.get(memberURL, (_, res, ctx) => {
return res(ctx.json(member), ctx.status(200));
}),

// 회원 탈퇴: POST
rest.post(`${memberURL}/delete`, (_, res, ctx) => {
return res(ctx.status(200));
}),
];