forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: I can delete my account easily (twentyhq#977)
* Add support for account deletion Co-authored-by: v1b3m <vibenjamin6@gmail.com> * Add more fixes Co-authored-by: Benjamin Mayanja <vibenjamin6@gmail.com> * Add more fixes Co-authored-by: v1b3m <vibenjamin6@gmail.com> --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com>
- Loading branch information
1 parent
98f913a
commit dda3fa8
Showing
8 changed files
with
306 additions
and
89 deletions.
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
106 changes: 106 additions & 0 deletions
106
front/src/modules/settings/profile/components/DeleteModal.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,106 @@ | ||
import { useState } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { AnimatePresence, LayoutGroup } from 'framer-motion'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { currentUserState } from '@/auth/states/currentUserState'; | ||
import { Button, ButtonVariant } from '@/ui/button/components/Button'; | ||
import { TextInput } from '@/ui/input/components/TextInput'; | ||
import { Modal } from '@/ui/modal/components/Modal'; | ||
import { debounce } from '~/utils/debounce'; | ||
|
||
interface DeleteModalProps { | ||
isOpen: boolean; | ||
title: string; | ||
subtitle: string; | ||
setIsOpen: (val: boolean) => void; | ||
handleConfirmDelete: () => void; | ||
deleteButtonText?: string; | ||
} | ||
|
||
const StyledTitle = styled.div` | ||
font-size: ${({ theme }) => theme.font.size.lg}; | ||
font-weight: ${({ theme }) => theme.font.weight.semiBold}; | ||
`; | ||
|
||
const StyledModal = styled(Modal)` | ||
color: ${({ theme }) => theme.font.color.primary}; | ||
> * + * { | ||
margin-top: ${({ theme }) => theme.spacing(8)}; | ||
} | ||
`; | ||
|
||
const StyledCenteredButton = styled(Button)` | ||
justify-content: center; | ||
`; | ||
|
||
export const StyledDeleteButton = styled(StyledCenteredButton)` | ||
border-color: ${({ theme }) => theme.color.red20}; | ||
color: ${({ theme }) => theme.color.red}; | ||
font-size: ${({ theme }) => theme.font.size.md}; | ||
line-height: ${({ theme }) => theme.text.lineHeight.lg}; | ||
`; | ||
|
||
export function DeleteModal({ | ||
isOpen = false, | ||
title, | ||
subtitle, | ||
setIsOpen, | ||
handleConfirmDelete, | ||
deleteButtonText = 'Delete', | ||
}: DeleteModalProps) { | ||
const [email, setEmail] = useState(''); | ||
const [isValidEmail, setIsValidEmail] = useState(true); | ||
const currentUser = useRecoilValue(currentUserState); | ||
const userEmail = currentUser?.email; | ||
|
||
const handleEmailChange = (val: string) => { | ||
setEmail(val); | ||
isEmailMatchingUserEmail(val, userEmail); | ||
}; | ||
|
||
const isEmailMatchingUserEmail = debounce( | ||
(email1?: string, email2?: string) => { | ||
setIsValidEmail(Boolean(email1 && email2 && email1 === email2)); | ||
}, | ||
250, | ||
); | ||
|
||
const errorMessage = | ||
email && !isValidEmail ? 'email provided is not correct' : ''; | ||
|
||
return ( | ||
<AnimatePresence mode="wait"> | ||
<LayoutGroup> | ||
<StyledModal isOpen={isOpen}> | ||
<StyledTitle>{title}</StyledTitle> | ||
<div>{subtitle}</div> | ||
<TextInput | ||
value={email} | ||
onChange={handleEmailChange} | ||
placeholder={userEmail} | ||
fullWidth | ||
key={'email-' + userEmail} | ||
error={errorMessage} | ||
/> | ||
<StyledDeleteButton | ||
onClick={handleConfirmDelete} | ||
variant={ButtonVariant.Secondary} | ||
title={deleteButtonText} | ||
disabled={!isValidEmail || !email} | ||
fullWidth | ||
/> | ||
<StyledCenteredButton | ||
onClick={() => setIsOpen(false)} | ||
variant={ButtonVariant.Secondary} | ||
title="Cancel" | ||
fullWidth | ||
style={{ | ||
marginTop: 10, | ||
}} | ||
/> | ||
</StyledModal> | ||
</LayoutGroup> | ||
</AnimatePresence> | ||
); | ||
} |
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
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
Oops, something went wrong.