diff --git a/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx b/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx index 3b2a384be..0181a5ea7 100644 --- a/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx +++ b/apps/web/src/app/(dashboard)/templates/data-table-templates.tsx @@ -144,6 +144,7 @@ export const TemplatesDataTable = ({
diff --git a/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx b/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx index f43b91ffe..cbf5b5e4a 100644 --- a/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx +++ b/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx @@ -15,7 +15,9 @@ import { } from '@documenso/lib/constants/template'; import { AppError } from '@documenso/lib/errors/app-error'; import type { Recipient } from '@documenso/prisma/client'; +import { DocumentSigningOrder } from '@documenso/prisma/client'; import { trpc } from '@documenso/trpc/react'; +import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { Checkbox } from '@documenso/ui/primitives/checkbox'; import { @@ -51,6 +53,7 @@ const ZAddRecipientsForNewDocumentSchema = z id: z.number(), email: z.string().email(), name: z.string(), + signingOrder: z.number().optional(), }), ), }) @@ -86,6 +89,7 @@ type TAddRecipientsForNewDocumentSchema = z.infer { - const isRecipientEmailPlaceholder = recipient.email.match( - TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX, - ); + recipients: recipients + .sort((a, b) => (a.signingOrder || 0) - (b.signingOrder || 0)) + .map((recipient) => { + const isRecipientEmailPlaceholder = recipient.email.match( + TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX, + ); - const isRecipientNamePlaceholder = recipient.name.match( - TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX, - ); + const isRecipientNamePlaceholder = recipient.name.match( + TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX, + ); - return { - id: recipient.id, - name: !isRecipientNamePlaceholder ? recipient.name : '', - email: !isRecipientEmailPlaceholder ? recipient.email : '', - }; - }), + return { + id: recipient.id, + name: !isRecipientNamePlaceholder ? recipient.name : '', + email: !isRecipientEmailPlaceholder ? recipient.email : '', + signingOrder: recipient.signingOrder ?? undefined, + }; + }), }, }); @@ -203,6 +211,33 @@ export function UseTemplateDialog({
{formRecipients.map((recipient, index) => (
+ {templateSigningOrder === DocumentSigningOrder.SEQUENTIAL && ( + ( + + + + + + + )} + /> + )} +