mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 03:01:59 +10:00
feat: allow same signer email multiple times
This commit is contained in:
@ -6,34 +6,22 @@ import { ZRecipientActionAuthTypesSchema } from '@documenso/lib/types/document-a
|
|||||||
import { ZMapNegativeOneToUndefinedSchema } from './add-settings.types';
|
import { ZMapNegativeOneToUndefinedSchema } from './add-settings.types';
|
||||||
import { DocumentSigningOrder, RecipientRole } from '.prisma/client';
|
import { DocumentSigningOrder, RecipientRole } from '.prisma/client';
|
||||||
|
|
||||||
export const ZAddSignersFormSchema = z
|
export const ZAddSignersFormSchema = z.object({
|
||||||
.object({
|
signers: z.array(
|
||||||
signers: z.array(
|
z.object({
|
||||||
z.object({
|
formId: z.string().min(1),
|
||||||
formId: z.string().min(1),
|
nativeId: z.number().optional(),
|
||||||
nativeId: z.number().optional(),
|
email: z
|
||||||
email: z
|
.string()
|
||||||
.string()
|
.email({ message: msg`Invalid email`.id })
|
||||||
.email({ message: msg`Invalid email`.id })
|
.min(1),
|
||||||
.min(1),
|
name: z.string(),
|
||||||
name: z.string(),
|
role: z.nativeEnum(RecipientRole),
|
||||||
role: z.nativeEnum(RecipientRole),
|
signingOrder: z.number().optional(),
|
||||||
signingOrder: z.number().optional(),
|
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(ZRecipientActionAuthTypesSchema.optional()),
|
||||||
actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(
|
}),
|
||||||
ZRecipientActionAuthTypesSchema.optional(),
|
),
|
||||||
),
|
signingOrder: z.nativeEnum(DocumentSigningOrder),
|
||||||
}),
|
});
|
||||||
),
|
|
||||||
signingOrder: z.nativeEnum(DocumentSigningOrder),
|
|
||||||
})
|
|
||||||
.refine(
|
|
||||||
(schema) => {
|
|
||||||
const emails = schema.signers.map((signer) => signer.email.toLowerCase());
|
|
||||||
|
|
||||||
return new Set(emails).size === emails.length;
|
|
||||||
},
|
|
||||||
// Dirty hack to handle errors when .root is populated for an array type
|
|
||||||
{ message: msg`Signers must have unique emails`.id, path: ['signers__root'] },
|
|
||||||
);
|
|
||||||
|
|
||||||
export type TAddSignersFormSchema = z.infer<typeof ZAddSignersFormSchema>;
|
export type TAddSignersFormSchema = z.infer<typeof ZAddSignersFormSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user