mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: typeIn confirmation
This commit is contained in:
@ -1,5 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { signOut } from 'next-auth/react';
|
import { signOut } from 'next-auth/react';
|
||||||
|
|
||||||
import type { User } from '@documenso/prisma/client';
|
import type { User } from '@documenso/prisma/client';
|
||||||
@ -16,6 +18,7 @@ import {
|
|||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from '@documenso/ui/primitives/dialog';
|
} from '@documenso/ui/primitives/dialog';
|
||||||
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
export type DeleteAccountDialogProps = {
|
export type DeleteAccountDialogProps = {
|
||||||
@ -27,6 +30,9 @@ export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProp
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const hasTwoFactorAuthentication = user.twoFactorEnabled;
|
const hasTwoFactorAuthentication = user.twoFactorEnabled;
|
||||||
|
const username = user.name!;
|
||||||
|
|
||||||
|
const [enteredUsername, setEnteredUsername] = useState<string>('');
|
||||||
|
|
||||||
const { mutateAsync: deleteAccount, isLoading: isDeletingAccount } =
|
const { mutateAsync: deleteAccount, isLoading: isDeletingAccount } =
|
||||||
trpc.profile.deleteAccount.useMutation();
|
trpc.profile.deleteAccount.useMutation();
|
||||||
@ -76,7 +82,7 @@ export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProp
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-shrink-0">
|
<div className="flex-shrink-0">
|
||||||
<Dialog>
|
<Dialog onOpenChange={() => setEnteredUsername('')}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button variant="destructive">Delete Account</Button>
|
<Button variant="destructive">Delete Account</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
@ -103,17 +109,44 @@ export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProp
|
|||||||
, along with all of your completed documents, signatures, and all other resources
|
, along with all of your completed documents, signatures, and all other resources
|
||||||
belonging to your Account.
|
belonging to your Account.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
|
{!hasTwoFactorAuthentication && (
|
||||||
|
<DialogDescription>
|
||||||
|
Please type <span className="font-semibold">{username}</span> to confirm.
|
||||||
|
</DialogDescription>
|
||||||
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
|
{!hasTwoFactorAuthentication && (
|
||||||
|
<div className="mt-4">
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
value={enteredUsername}
|
||||||
|
onChange={(e) => setEnteredUsername(e.target.value)}
|
||||||
|
onPaste={(e) => e.preventDefault()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
|
{!hasTwoFactorAuthentication && (
|
||||||
<Button
|
<Button
|
||||||
|
className="text-red-500 hover:bg-red-500 hover:text-white sm:w-full"
|
||||||
onClick={onDeleteAccount}
|
onClick={onDeleteAccount}
|
||||||
loading={isDeletingAccount}
|
loading={isDeletingAccount}
|
||||||
variant="destructive"
|
variant="outline"
|
||||||
disabled={hasTwoFactorAuthentication}
|
disabled={hasTwoFactorAuthentication || enteredUsername !== username}
|
||||||
>
|
>
|
||||||
{isDeletingAccount ? 'Deleting account...' : 'Confirm Deletion'}
|
{isDeletingAccount ? (
|
||||||
|
'Deleting account...'
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<span className="sm:hidden">Delete account</span>
|
||||||
|
<span className="hidden sm:block">
|
||||||
|
I understand the consequences, delete this account
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user