'use client'; import { signOut } from 'next-auth/react'; import type { User } from '@documenso/prisma/client'; import { TRPCClientError } from '@documenso/trpc/client'; import { trpc } from '@documenso/trpc/react'; import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@documenso/ui/primitives/dialog'; import { useToast } from '@documenso/ui/primitives/use-toast'; export type DeleteAccountDialogProps = { className?: string; user: User; }; export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProps) => { const { toast } = useToast(); const hasTwoFactorAuthentication = user.twoFactorEnabled; const { mutateAsync: deleteAccount, isLoading: isDeletingAccount } = trpc.profile.deleteAccount.useMutation(); const onDeleteAccount = async () => { try { await deleteAccount(); toast({ title: 'Account deleted', description: 'Your account has been deleted successfully.', duration: 5000, }); return await signOut({ callbackUrl: '/' }); } catch (err) { if (err instanceof TRPCClientError && err.data?.code === 'BAD_REQUEST') { toast({ title: 'An error occurred', description: err.message, variant: 'destructive', }); } else { toast({ title: 'An unknown error occurred', variant: 'destructive', description: err.message ?? 'We encountered an unknown error while attempting to delete your account. Please try again later.', }); } } }; return (
Delete Account Delete your account and all its contents, including completed documents. This action is irreversible and will cancel your subscription, so proceed with caution.
Delete Account This action is not reversible. Please be certain. {hasTwoFactorAuthentication && ( Disable Two Factor Authentication before deleting your account. )} Documenso will delete all of your documents , along with all of your completed documents, signatures, and all other resources belonging to your Account.
); };