Compare commits

...

2 Commits

Author SHA1 Message Date
3eebd52dd1 fix: improve types 2023-04-19 23:52:37 +10:00
f8f4c07d11 add toast error for invalid email 2023-04-19 23:48:21 +10:00

View File

@ -18,11 +18,12 @@ import {
UserPlusIcon, UserPlusIcon,
XMarkIcon, XMarkIcon,
} from "@heroicons/react/24/outline"; } 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 { FormProvider, useFieldArray, useForm, useWatch } from "react-hook-form";
import { toast } from "react-hot-toast";
export type FormValues = { export type FormValues = {
signers: { id: number; email: string; name: string }[]; signers: Array<Pick<Recipient, 'id' | 'email' | 'name' | 'sendStatus'>>;
}; };
const RecipientsPage: NextPageWithLayout = (props: any) => { const RecipientsPage: NextPageWithLayout = (props: any) => {
@ -108,12 +109,14 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
color="primary" color="primary"
icon={PaperAirplaneIcon} icon={PaperAirplaneIcon}
onClick={() => { onClick={() => {
setOpen(true); formValues.some((r) => r.email && hasEmailError(r))
? toast.error("Please enter a valid email address.", { id: "invalid email" })
: setOpen(true);
}} }}
disabled={ disabled={
(formValues.length || 0) === 0 || (formValues.length || 0) === 0 ||
!formValues.some( !formValues.some(
(r: any) => r.email && !hasEmailError(r) && r.sendStatus === "NOT_SENT" (r) => r.email && !hasEmailError(r) && r.sendStatus === "NOT_SENT"
) || ) ||
loading loading
}> }>