-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dependabot/github_actions/actions/setup-n…
…ode-4
- Loading branch information
Showing
47 changed files
with
991 additions
and
184 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
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
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,121 @@ | ||
import { Box, Button, Card, CardContent, Link, Typography, lighten } from '@mui/material'; | ||
import { getAuth, signOut } from 'firebase/auth'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useRouter } from 'next/router'; | ||
import { useState } from 'react'; | ||
import { useDeleteUserMutation } from '../../app/api'; | ||
import { ErrorDisplay } from '../../constants/common'; | ||
import theme from '../../styles/theme'; | ||
import ConfirmDialog from '../forms/ConfirmDialog'; | ||
|
||
const cardStyle = { | ||
width: { xs: '100%', md: 'auto' }, | ||
flex: { xs: 'auto', md: 1 }, | ||
} as const; | ||
|
||
const AccountActionsCard = () => { | ||
const t = useTranslations('Account.accountSettings'); | ||
const tS = useTranslations('Shared'); | ||
const router = useRouter(); | ||
const [deleteUser, { isLoading }] = useDeleteUserMutation(); | ||
const [error, setError] = useState<ErrorDisplay>(); | ||
|
||
const [resetPasswordConfirmationRequired, setResetPasswordConfirmationRequired] = | ||
useState<boolean>(false); | ||
const [deleteAccountConfirmationRequired, setDeleteAccountConfirmationRequired] = | ||
useState<boolean>(false); | ||
|
||
const passwordResetConfirmHandler = (confirmed: boolean) => { | ||
if (confirmed) { | ||
router.push('/auth/reset-password'); | ||
} else { | ||
setResetPasswordConfirmationRequired(false); | ||
} | ||
}; | ||
|
||
const deleteAccountConfirmHandler = async (confirmed: boolean) => { | ||
if (confirmed) { | ||
const response = await deleteUser({}); | ||
|
||
if ((response as any)?.data?.id) { | ||
setError(undefined); | ||
router.push('/').then(() => { | ||
const auth = getAuth(); | ||
signOut(auth); | ||
}); | ||
} else { | ||
setError( | ||
t.rich('updateError', { | ||
link: (children) => <Link href={tS('feedbackTypeform')}>{children}</Link>, | ||
}), | ||
); | ||
} | ||
setDeleteAccountConfirmationRequired(false); | ||
} else { | ||
setDeleteAccountConfirmationRequired(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Card sx={cardStyle}> | ||
<CardContent> | ||
<Box sx={{ mb: 2 }}> | ||
<Typography variant="h2" component="h2"> | ||
{t('actions.title')} | ||
</Typography> | ||
<Typography>{t('actions.description')}</Typography> | ||
{error && <Typography color="error.main">{error}</Typography>} | ||
</Box> | ||
<Box display={['flex']} flexWrap="wrap" gap={2} rowGap={2}> | ||
<Button | ||
sx={{ | ||
background: theme.palette.secondary.dark, | ||
'&:hover': { background: lighten(theme.palette.secondary.dark, 0.2) }, | ||
}} | ||
variant="contained" | ||
onClick={() => { | ||
setResetPasswordConfirmationRequired(true); | ||
}} | ||
> | ||
{t('actions.button.resetPassword')} | ||
</Button> | ||
<Button | ||
id="delete-account-button" | ||
variant="outlined" | ||
sx={{ | ||
border: `solid 2px ${theme.palette.primary.dark}`, | ||
color: theme.palette.primary.dark, | ||
'&:hover': { | ||
border: `solid 2px ${theme.palette.primary.dark}`, | ||
background: theme.palette.primary.dark, | ||
color: theme.palette.common.white, | ||
}, | ||
}} | ||
onClick={() => { | ||
setDeleteAccountConfirmationRequired(true); | ||
}} | ||
> | ||
{t('actions.button.deleteAccount')} | ||
</Button> | ||
</Box> | ||
<ConfirmDialog | ||
title={t('actions.resetPasswordConfirmDialogTitle')} | ||
cancelLabel={t('actions.confirmDialogCancel')} | ||
submitLabel={t('actions.button.resetPassword')} | ||
isOpen={resetPasswordConfirmationRequired} | ||
onConfirm={passwordResetConfirmHandler} | ||
/> | ||
<ConfirmDialog | ||
title={t('actions.deleteAccountConfirmDialogTitle')} | ||
text={t('actions.deleteAccountConfirmDialogDescription')} | ||
cancelLabel={t('actions.confirmDialogCancel')} | ||
submitLabel={t('actions.button.deleteAccount')} | ||
isOpen={deleteAccountConfirmationRequired} | ||
onConfirm={deleteAccountConfirmHandler} | ||
/> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default AccountActionsCard; |
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,50 @@ | ||
import { DialogContent, DialogContentText } from '@mui/material'; | ||
import Button from '@mui/material/Button'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import * as React from 'react'; | ||
|
||
export default function ConfirmDialog({ | ||
isOpen, | ||
onConfirm, | ||
title, | ||
text, | ||
submitLabel, | ||
cancelLabel, | ||
}: { | ||
isOpen: boolean; | ||
onConfirm: (confirmed: boolean) => void; | ||
title: string; | ||
text?: string; | ||
submitLabel: string; | ||
cancelLabel: string; | ||
}) { | ||
const handleClose = (confirmAction: boolean) => () => { | ||
onConfirm(confirmAction); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Dialog | ||
open={isOpen} | ||
onClose={handleClose(false)} | ||
aria-labelledby="alert-dialog-title" | ||
aria-describedby="alert-dialog-description" | ||
> | ||
<DialogTitle id="alert-dialog-title">{title}</DialogTitle> | ||
{text && ( | ||
<DialogContent> | ||
<DialogContentText>{text}</DialogContentText> | ||
</DialogContent> | ||
)} | ||
<DialogActions> | ||
<Button onClick={handleClose(false)}>{cancelLabel}</Button> | ||
<Button id="confirm-dialog-submit" onClick={handleClose(true)} autoFocus> | ||
{submitLabel} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</React.Fragment> | ||
); | ||
} |
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.