Files
twenty_crm/front/src/modules/settings/profile/components/DeleteAccount.tsx
gitstart-twenty 00a3c8ca2b Change to using arrow functions (#1603)
* Change to using arrow functions

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>

* Add lint rule

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2023-09-15 18:41:10 -07:00

65 lines
1.9 KiB
TypeScript

import { useCallback, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { useAuth } from '@/auth/hooks/useAuth';
import { currentUserState } from '@/auth/states/currentUserState';
import { AppPath } from '@/types/AppPath';
import { Button } from '@/ui/button/components/Button';
import { ConfirmationModal } from '@/ui/modal/components/ConfirmationModal';
import { H2Title } from '@/ui/typography/components/H2Title';
import { useDeleteUserAccountMutation } from '~/generated/graphql';
export const DeleteAccount = () => {
const [isDeleteAccountModalOpen, setIsDeleteAccountModalOpen] =
useState(false);
const [deleteUserAccount] = useDeleteUserAccountMutation();
const currentUser = useRecoilValue(currentUserState);
const userEmail = currentUser?.email;
const { signOut } = useAuth();
const navigate = useNavigate();
const handleLogout = useCallback(() => {
signOut();
navigate(AppPath.SignIn);
}, [signOut, navigate]);
const deleteAccount = async () => {
await deleteUserAccount();
handleLogout();
};
return (
<>
<H2Title
title="Danger zone"
description="Delete account and all the associated data"
/>
<Button
accent="danger"
onClick={() => setIsDeleteAccountModalOpen(true)}
variant="secondary"
title="Delete account"
/>
<ConfirmationModal
confirmationValue={userEmail}
confirmationPlaceholder={userEmail ?? ''}
isOpen={isDeleteAccountModalOpen}
setIsOpen={setIsDeleteAccountModalOpen}
title="Account Deletion"
subtitle={
<>
This action cannot be undone. This will permanently delete your
entire account. <br /> Please type in your email to confirm.
</>
}
onConfirmClick={deleteAccount}
deleteButtonText="Delete account"
/>
</>
);
};