'use client'; import { useState, useTransition } from 'react'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert'; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@kit/ui/alert-dialog'; import { Button } from '@kit/ui/button'; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from '@kit/ui/form'; import { If } from '@kit/ui/if'; import { Input } from '@kit/ui/input'; import { deleteAccountAction } from '../lib/server/admin-server-actions'; import { DeleteAccountSchema } from '../lib/server/schema/admin-actions.schema'; export function AdminDeleteAccountDialog( props: React.PropsWithChildren<{ accountId: string; }>, ) { const [pending, startTransition] = useTransition(); const [error, setError] = useState(false); const form = useForm({ resolver: zodResolver(DeleteAccountSchema), defaultValues: { accountId: props.accountId, confirmation: '', }, }); return ( {props.children} Delete Account Are you sure you want to delete this account? All the data associated with this account will be permanently deleted. Any active subscriptions will be canceled.
{ startTransition(async () => { try { await deleteAccountAction(data); setError(false); } catch { setError(true); } }); })} > Error There was an error deleting the account. Please check the server logs to see what went wrong. ( Type CONFIRM to confirm Are you sure you want to do this? This action cannot be undone. )} /> Cancel
); }