fix: update styling and e2e test

This commit is contained in:
Lucas Smith
2024-03-12 02:57:22 +00:00
parent efb90ca5fb
commit d3f4e20f1c
2 changed files with 20 additions and 26 deletions

View File

@@ -19,6 +19,7 @@ import {
DialogTrigger, DialogTrigger,
} from '@documenso/ui/primitives/dialog'; } from '@documenso/ui/primitives/dialog';
import { Input } from '@documenso/ui/primitives/input'; import { Input } from '@documenso/ui/primitives/input';
import { Label } from '@documenso/ui/primitives/label';
import { useToast } from '@documenso/ui/primitives/use-toast'; import { useToast } from '@documenso/ui/primitives/use-toast';
export type DeleteAccountDialogProps = { export type DeleteAccountDialogProps = {
@@ -30,7 +31,6 @@ export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProp
const { toast } = useToast(); const { toast } = useToast();
const hasTwoFactorAuthentication = user.twoFactorEnabled; const hasTwoFactorAuthentication = user.twoFactorEnabled;
const userEmail = user.email;
const [enteredEmail, setEnteredEmail] = useState<string>(''); const [enteredEmail, setEnteredEmail] = useState<string>('');
@@ -86,6 +86,7 @@ export const DeleteAccountDialog = ({ className, user }: DeleteAccountDialogProp
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="destructive">Delete Account</Button> <Button variant="destructive">Delete Account</Button>
</DialogTrigger> </DialogTrigger>
<DialogContent> <DialogContent>
<DialogHeader className="space-y-4"> <DialogHeader className="space-y-4">
<DialogTitle>Delete Account</DialogTitle> <DialogTitle>Delete Account</DialogTitle>
@@ -109,43 +110,34 @@ 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">{userEmail}</span> to confirm.
</DialogDescription>
)}
</DialogHeader> </DialogHeader>
{!hasTwoFactorAuthentication && ( {!hasTwoFactorAuthentication && (
<div className="mt-4"> <div className="mt-4">
<Label>
Please type{' '}
<span className="text-muted-foreground font-semibold">{user.email}</span> to
confirm.
</Label>
<Input <Input
type="text" type="text"
className="mt-2"
aria-label="Confirm Email"
value={enteredEmail} value={enteredEmail}
onChange={(e) => setEnteredEmail(e.target.value)} onChange={(e) => setEnteredEmail(e.target.value)}
/> />
</div> </div>
)} )}
<DialogFooter> <DialogFooter>
{!hasTwoFactorAuthentication && ( <Button
<Button onClick={onDeleteAccount}
className="text-red-500 hover:bg-red-500 hover:text-white sm:w-full" loading={isDeletingAccount}
onClick={onDeleteAccount} variant="destructive"
loading={isDeletingAccount} disabled={hasTwoFactorAuthentication || enteredEmail !== user.email}
variant="outline" >
disabled={hasTwoFactorAuthentication || enteredEmail !== userEmail} {isDeletingAccount ? 'Deleting account...' : 'Confirm Deletion'}
> </Button>
{isDeletingAccount ? (
'Deleting account...'
) : (
<>
<span className="sm:hidden">Delete account</span>
<span className="hidden sm:block">
I understand the consequences, delete this account
</span>
</>
)}
</Button>
)}
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
</Dialog> </Dialog>

View File

@@ -16,6 +16,8 @@ test('delete user', async ({ page }) => {
}); });
await page.getByRole('button', { name: 'Delete Account' }).click(); await page.getByRole('button', { name: 'Delete Account' }).click();
await page.getByLabel('Confirm Email').fill(user.email);
await expect(page.getByRole('button', { name: 'Confirm Deletion' })).not.toBeDisabled();
await page.getByRole('button', { name: 'Confirm Deletion' }).click(); await page.getByRole('button', { name: 'Confirm Deletion' }).click();
await page.waitForURL(`${WEBAPP_BASE_URL}/signin`); await page.waitForURL(`${WEBAPP_BASE_URL}/signin`);