import { zodResolver } from '@hookform/resolvers/zod'; import { Trans } from '@lingui/react/macro'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@documenso/ui/primitives/dialog'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@documenso/ui/primitives/form/form'; import { Input } from '@documenso/ui/primitives/input'; import { DocumentSigningDisclosure } from '../general/document-signing/document-signing-disclosure'; export type NextSigner = { name: string; email: string; }; type ConfirmationDialogProps = { isOpen: boolean; onClose: () => void; onConfirm: (nextSigner?: NextSigner) => void; hasUninsertedFields: boolean; isSubmitting: boolean; allowDictateNextSigner?: boolean; defaultNextSigner?: NextSigner; }; const ZNextSignerFormSchema = z.object({ name: z.string().min(1, 'Name is required'), email: z.string().email('Invalid email address'), }); type TNextSignerFormSchema = z.infer; export function AssistantConfirmationDialog({ isOpen, onClose, onConfirm, hasUninsertedFields, isSubmitting, allowDictateNextSigner = false, defaultNextSigner, }: ConfirmationDialogProps) { const form = useForm({ resolver: zodResolver(ZNextSignerFormSchema), defaultValues: { name: defaultNextSigner?.name ?? '', email: defaultNextSigner?.email ?? '', }, }); const onOpenChange = () => { if (isSubmitting) { return; } form.reset({ name: defaultNextSigner?.name ?? '', email: defaultNextSigner?.email ?? '', }); onClose(); }; const handleSubmit = () => { // Validate the form and submit it if dictate signer is enabled. if (allowDictateNextSigner) { void form.handleSubmit(onConfirm)(); return; } onConfirm(); }; return (
Complete Document Are you sure you want to complete the document? This action cannot be undone. Please ensure that you have completed prefilling all relevant fields before proceeding.
{allowDictateNextSigner && (

The next recipient to sign this document will be{' '}

( Name )} /> ( Email )} />
)}
); }