feat(auth): add user and role management
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
import * as React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useMutation } from '@apollo/client';
|
||||
import Button from '@mui/material/Button';
|
||||
import Dialog from '@mui/material/Dialog';
|
||||
import DialogActions from '@mui/material/DialogActions';
|
||||
import DialogContent from '@mui/material/DialogContent';
|
||||
import DialogContentText from '@mui/material/DialogContentText';
|
||||
import DialogTitle from '@mui/material/DialogTitle';
|
||||
|
||||
import * as URLS from 'config/urls';
|
||||
import ConfirmationDialog from 'components/ConfirmationDialog';
|
||||
import apolloClient from 'graphql/client';
|
||||
import { DELETE_USER } from 'graphql/mutations/delete-user.ee';
|
||||
import { DELETE_CURRENT_USER } from 'graphql/mutations/delete-current-user.ee';
|
||||
import useAuthentication from 'hooks/useAuthentication';
|
||||
import useFormatMessage from 'hooks/useFormatMessage';
|
||||
import useCurrentUser from 'hooks/useCurrentUser';
|
||||
@@ -20,37 +15,29 @@ type DeleteAccountDialogProps = {
|
||||
}
|
||||
|
||||
export default function DeleteAccountDialog(props: DeleteAccountDialogProps) {
|
||||
const [deleteUser] = useMutation(DELETE_USER);
|
||||
const [deleteCurrentUser] = useMutation(DELETE_CURRENT_USER);
|
||||
const formatMessage = useFormatMessage();
|
||||
const currentUser = useCurrentUser();
|
||||
const authentication = useAuthentication();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleConfirm = React.useCallback(async () => {
|
||||
await deleteUser();
|
||||
await deleteCurrentUser();
|
||||
|
||||
authentication.updateToken('');
|
||||
await apolloClient.clearStore();
|
||||
|
||||
navigate(URLS.LOGIN);
|
||||
}, [deleteUser, currentUser]);
|
||||
}, [deleteCurrentUser, currentUser]);
|
||||
|
||||
return (
|
||||
<Dialog open onClose={props.onClose}>
|
||||
<DialogTitle >
|
||||
{formatMessage('deleteAccountDialog.title')}
|
||||
</DialogTitle>
|
||||
<DialogContent>
|
||||
<DialogContentText id="alert-dialog-description">
|
||||
{formatMessage('deleteAccountDialog.description')}
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={props.onClose}>{formatMessage('deleteAccountDialog.cancel')}</Button>
|
||||
<Button onClick={handleConfirm} color="error">
|
||||
{formatMessage('deleteAccountDialog.confirm')}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
<ConfirmationDialog
|
||||
title={formatMessage('deleteAccountDialog.title')}
|
||||
description={formatMessage('deleteAccountDialog.description')}
|
||||
onClose={props.onClose}
|
||||
onConfirm={handleConfirm}
|
||||
cancelButtonChildren={formatMessage('deleteAccountDialog.cancel')}
|
||||
confirmButtionChildren={formatMessage('deleteAccountDialog.confirm')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user