mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
fix: improve types
This commit is contained in:
@ -18,14 +18,16 @@ 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";
|
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' | 'readStatus' | 'signingStatus'>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type FormSigner = FormValues["signers"][number];
|
||||||
|
|
||||||
const RecipientsPage: NextPageWithLayout = (props: any) => {
|
const RecipientsPage: NextPageWithLayout = (props: any) => {
|
||||||
const title: string = `"` + props?.document?.title + `"` + "Recipients | Documenso";
|
const title: string = `"` + props?.document?.title + `"` + "Recipients | Documenso";
|
||||||
const breadcrumbItems = [
|
const breadcrumbItems = [
|
||||||
@ -64,7 +66,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
|||||||
});
|
});
|
||||||
const formValues = useWatch({ control, name: "signers" });
|
const formValues = useWatch({ control, name: "signers" });
|
||||||
const cancelButtonRef = useRef(null);
|
const cancelButtonRef = useRef(null);
|
||||||
const hasEmailError = (formValue: any): boolean => {
|
const hasEmailError = (formValue: FormSigner): boolean => {
|
||||||
const index = formValues.findIndex((e) => e.id === formValue.id);
|
const index = formValues.findIndex((e) => e.id === formValue.id);
|
||||||
return !!errors?.signers?.[index]?.email;
|
return !!errors?.signers?.[index]?.email;
|
||||||
};
|
};
|
||||||
@ -109,14 +111,14 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
|||||||
color="primary"
|
color="primary"
|
||||||
icon={PaperAirplaneIcon}
|
icon={PaperAirplaneIcon}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
formValues.some((r: any) => r.email && hasEmailError(r))
|
formValues.some((r) => r.email && hasEmailError(r))
|
||||||
? toast.error("Please enter a valid email address.", { id: "invalid email" })
|
? toast.error("Please enter a valid email address.", { id: "invalid email" })
|
||||||
: setOpen(true);
|
: 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
|
||||||
}>
|
}>
|
||||||
@ -141,7 +143,7 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
|||||||
trigger();
|
trigger();
|
||||||
}}>
|
}}>
|
||||||
<ul role="list" className="divide-y divide-gray-200">
|
<ul role="list" className="divide-y divide-gray-200">
|
||||||
{fields.map((item: any, index: number) => (
|
{fields.map((item, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className="group w-full border-0 px-2 py-3 hover:bg-green-50 sm:py-4">
|
className="group w-full border-0 px-2 py-3 hover:bg-green-50 sm:py-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user