-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): initial account deletion implementation
- Loading branch information
1 parent
ba11ebe
commit b6eda04
Showing
17 changed files
with
320 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.exportDataContainer { | ||
.textWithButtonContainer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
|
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
70 changes: 70 additions & 0 deletions
70
src/components/DeleteAccountModal/DeleteAccountModal.module.scss
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,70 @@ | ||
@use 'src/styles/variables'; | ||
|
||
.formContainer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 40px; | ||
align-items: center; | ||
padding: 30px; | ||
} | ||
|
||
.formContainerSmall { | ||
gap: 20px; | ||
} | ||
|
||
.innerContainer { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 16px; | ||
align-items: center; | ||
} | ||
|
||
.passwordButtonsContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 8px; | ||
width: 100%; | ||
} | ||
|
||
.buttonsContainer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: flex-end; | ||
align-items: center; | ||
width: 100%; | ||
gap: 16px; | ||
} | ||
|
||
.heading { | ||
width: 50%; | ||
margin-bottom: 20px; | ||
color: variables.$dark-onbackground-main; | ||
font-weight: 400; | ||
font-size: 20px; | ||
line-height: 28px; | ||
text-align: center; | ||
} | ||
|
||
.paragraph { | ||
width: 100%; | ||
margin: 0; | ||
padding: 0; | ||
color: variables.$dark-onbackground-main; | ||
font-size: 14px; | ||
line-height: 20px; | ||
text-align: left; | ||
} | ||
|
||
.button { | ||
margin: auto; | ||
} | ||
|
||
.warningBox { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 8px 16px 8px 16px; | ||
background-color: variables.$dark-warning-surface; | ||
border-radius: 4px; | ||
gap: 16px; | ||
} |
101 changes: 101 additions & 0 deletions
101
src/components/DeleteAccountModal/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,101 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { type SchemaOf, object, string } from 'yup'; | ||
import { useNavigate, useLocation } from 'react-router'; | ||
import { useState } from 'react'; | ||
import { useMutation } from 'react-query'; | ||
|
||
import PasswordField from '../PasswordField/PasswordField'; | ||
import Button from '../Button/Button'; | ||
|
||
import styles from './DeleteAccountModal.module.scss'; | ||
|
||
import type { DeleteAccountFormData } from '#types/account'; | ||
import useForm from '#src/hooks/useForm'; | ||
import { addQueryParam, removeQueryParam } from '#src/utils/location'; | ||
import { deleteAccountData, logout } from '#src/stores/AccountController'; | ||
|
||
const DeleteAccountModal = () => { | ||
const { t } = useTranslation('user'); | ||
|
||
const [enteredPassword, setEnteredPassword] = useState<string>(''); | ||
|
||
const deleteAccount = useMutation(deleteAccountData, { | ||
onSuccess: async () => { | ||
await logout(); | ||
navigate('/'); | ||
}, | ||
onError: () => { | ||
setEnteredPassword(''); | ||
handleCancel(); | ||
}, | ||
}); | ||
|
||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
const validationSchema: SchemaOf<DeleteAccountFormData> = object().shape({ | ||
password: string().required(t('login.field_required')), | ||
}); | ||
const initialValues: DeleteAccountFormData = { password: '' }; | ||
const { handleSubmit, handleChange, values, errors } = useForm( | ||
initialValues, | ||
() => { | ||
setEnteredPassword(values.password); | ||
navigate(addQueryParam(location, 'confirmation', 'true')); | ||
}, | ||
validationSchema, | ||
); | ||
|
||
const handleCancel = () => { | ||
const removedU = removeQueryParam(location, 'u'); | ||
navigate(removedU.split('&confirmation')[0]); | ||
}; | ||
|
||
return enteredPassword ? ( | ||
<div className={styles.formContainer}> | ||
<h2 className={styles.heading}>{t('account.delete_account_title')}</h2> | ||
<div className={styles.innerContainer}> | ||
<p className={styles.paragraph}>{t('account.delete_account_modal_text_1')}</p> | ||
<p className={styles.paragraph}>{t('account.delete_account_modal_text_2')}</p> | ||
<div className={styles.warningBox}> | ||
<p className={styles.paragraph}>{t('account.delete_account_modal_warning_1')}</p> | ||
<p className={styles.paragraph}>{t('account.delete_account_modal_warning_2')}</p> | ||
</div> | ||
<p className={styles.paragraph}> | ||
{t('account.delete_account_modal_text_3')} <br /> | ||
{t('account.delete_account_modal_text_4')} | ||
</p> | ||
</div> | ||
<div className={styles.buttonsContainer}> | ||
<Button disabled={deleteAccount.isLoading} variant="text" label={t('account.cancel')} onClick={handleCancel} /> | ||
<Button | ||
disabled={deleteAccount.isLoading} | ||
variant="delete" | ||
label={t('account.delete_account_title')} | ||
onClick={() => { | ||
deleteAccount.mutate(enteredPassword); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
) : ( | ||
<form onSubmit={handleSubmit} className={`${styles.formContainer} ${styles.formContainerSmall}`}> | ||
<h2 className={styles.heading}>{t('account.delete_account_modal_title')}</h2> | ||
<PasswordField | ||
value={values.password} | ||
onChange={handleChange} | ||
label={t('account.password')} | ||
placeholder={t('account.delete_account_modal_placeholder')} | ||
error={!!errors.password || !!errors.form} | ||
name="password" | ||
showHelperText={false} | ||
/> | ||
<div className={styles.passwordButtonsContainer}> | ||
<Button type="submit" className={styles.button} color="primary" fullWidth label={t('account.continue')} /> | ||
<Button onClick={handleCancel} className={styles.button} variant="text" fullWidth label={t('account.cancel')} /> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default DeleteAccountModal; |
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 |
---|---|---|
|
@@ -18,3 +18,7 @@ | |
display: none; | ||
} | ||
} | ||
|
||
.largeDialog { | ||
max-width: 768px; | ||
} |
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.