'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { useAction } from 'next-safe-action/hooks'; 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 { useAsyncDialog } from '@kit/ui/hooks/use-async-dialog'; import { If } from '@kit/ui/if'; import { Input } from '@kit/ui/input'; import { reactivateUserAction } from '../lib/server/admin-server-actions'; import { ReactivateUserSchema } from '../lib/server/schema/admin-actions.schema'; export function AdminReactivateUserDialog( props: React.PropsWithChildren<{ userId: string; }>, ) { const { dialogProps, isPending, setIsPending, setOpen } = useAsyncDialog(); return ( Reactivate User Are you sure you want to reactivate this user? { setIsPending(false); setOpen(false); }} /> ); } function ReactivateUserForm(props: { userId: string; isPending: boolean; setIsPending: (pending: boolean) => void; onSuccess: () => void; }) { const { execute, hasErrored } = useAction(reactivateUserAction, { onExecute: () => props.setIsPending(true), onSuccess: () => props.onSuccess(), onSettled: () => props.setIsPending(false), }); const form = useForm({ resolver: zodResolver(ReactivateUserSchema), defaultValues: { userId: props.userId, confirmation: '', }, }); return (
execute(data))} > Error There was an error reactivating the user. Please check the server logs to see what went wrong. ( Type CONFIRM to confirm Are you sure you want to do this? )} /> Cancel ); }