diff --git a/apps/web/pages/documents/[id]/recipients.tsx b/apps/web/pages/documents/[id]/recipients.tsx index fefa9a27a..8dc9e7f64 100644 --- a/apps/web/pages/documents/[id]/recipients.tsx +++ b/apps/web/pages/documents/[id]/recipients.tsx @@ -18,13 +18,16 @@ import { UserPlusIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { DocumentStatus, Document as PrismaDocument } from "@prisma/client"; +import { DocumentStatus, Document as PrismaDocument, Recipient } from "@prisma/client"; import { FormProvider, useFieldArray, useForm, useWatch } from "react-hook-form"; +import { toast } from "react-hot-toast"; export type FormValues = { - signers: { id: number; email: string; name: string }[]; + signers: Array>; }; +type FormSigner = FormValues["signers"][number]; + const RecipientsPage: NextPageWithLayout = (props: any) => { const title: string = `"` + props?.document?.title + `"` + "Recipients | Documenso"; const breadcrumbItems = [ @@ -63,7 +66,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => { }); const formValues = useWatch({ control, name: "signers" }); const cancelButtonRef = useRef(null); - const hasEmailError = (formValue: any): boolean => { + const hasEmailError = (formValue: FormSigner): boolean => { const index = formValues.findIndex((e) => e.id === formValue.id); return !!errors?.signers?.[index]?.email; }; @@ -108,12 +111,14 @@ const RecipientsPage: NextPageWithLayout = (props: any) => { color="primary" icon={PaperAirplaneIcon} onClick={() => { - setOpen(true); + formValues.some((r) => r.email && hasEmailError(r)) + ? toast.error("Please enter a valid email address.", { id: "invalid email" }) + : setOpen(true); }} disabled={ (formValues.length || 0) === 0 || !formValues.some( - (r: any) => r.email && !hasEmailError(r) && r.sendStatus === "NOT_SENT" + (r) => r.email && !hasEmailError(r) && r.sendStatus === "NOT_SENT" ) || loading }> @@ -138,7 +143,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => { trigger(); }}>