This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
[FE] feat: 회원 탈퇴 기능 구현 #412
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
frontend/src/components/Modal/DeleteAccountModal.tsx/DeleteAccountModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutate
를 따로 분리해서 리턴하지 않고 객체 자체를 리턴하신 이유는mutate
이외에도 사용하는 프로퍼티가 있어서 그런가용?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 이제 공통으로 뺐으니까 다른 프로퍼티를 사용할 수도 있으니 바로 리턴하였습니다.
쿼리 훅 분리하면 다 이런식으로 바뀔 것 같아요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 그렇군요 이해했습니다~!