From afab5645c2c227de2923abd9ad2a17cec9081e43 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Fri, 3 Jan 2025 22:52:45 +0100 Subject: [PATCH] NORY-47: add dialog to show recovery information --- .../components/identity/identity-actions.tsx | 96 +++++++++++++++++-- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/dashboard/src/components/identity/identity-actions.tsx b/dashboard/src/components/identity/identity-actions.tsx index 6ecaa8b..0ddcf32 100644 --- a/dashboard/src/components/identity/identity-actions.tsx +++ b/dashboard/src/components/identity/identity-actions.tsx @@ -1,8 +1,8 @@ 'use client'; import { Identity } from '@ory/client'; -import { Button } from '@/components/ui/button'; -import { Key, Link, Trash, UserCheck, UserMinus, UserX } from 'lucide-react'; +import { Button, buttonVariants } from '@/components/ui/button'; +import { Copy, Key, Link, Trash, UserCheck, UserMinus, UserX } from 'lucide-react'; import { ConfirmationDialogWrapper } from '@/components/confirmation-dialog-wrapper'; import { blockIdentity, @@ -14,6 +14,18 @@ import { } from '@/lib/action/identity'; import { toast } from 'sonner'; import { useRouter } from 'next/navigation'; +import { useState } from 'react'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; interface IdentityActionProps { identity: Identity; @@ -24,14 +36,84 @@ export function IdentityActions({ identity }: IdentityActionProps, const router = useRouter(); + const [dialogVisible, setDialogVisible] = useState(false); + const [dialogLink, setDialogLink] = useState(''); + const [dialogCode, setDialogCode] = useState(undefined); + return ( <> + setDialogVisible(value)}> + + + Recovery account + + You created a recovery flow. Provide the user with the following information so they can + access their account again. + + +
+ +
+ + +
+

+ { + dialogCode ? + 'The user will need this link to access the recovery flow.' + : + 'This magic link will authenticate the user automatically' + } +

+
+ { + dialogCode ? +
+ +
+ + +
+

+ The user will need to enter this code on the recovery page. +

+
+ : + <> + } + + + Close + + +
+
+ { await createRecoveryCode(identity.id) .then((response) => { - console.log('recovery code created', response); - toast.success(response.recovery_code); + setDialogLink(response.recovery_link); + setDialogCode(response.recovery_code); + setDialogVisible(true); }) .catch(() => toast.error('Creating recovery code failed')); }} @@ -49,8 +131,9 @@ export function IdentityActions({ identity }: IdentityActionProps, onSubmit={async () => { await createRecoveryLink(identity.id) .then((response) => { - console.log('recovery link created', response); - toast.success(response.recovery_link); + setDialogLink(response.recovery_link); + setDialogCode(undefined); + setDialogVisible(true); }) .catch(() => toast.error('Creating recovery link failed. It is likely magic-links are disabled on your Ory Kratos instance.')); }} @@ -135,7 +218,6 @@ export function IdentityActions({ identity }: IdentityActionProps, - ); } \ No newline at end of file