From c23d739f76f36f739f5bbe94c1a62561e7c28a9b Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Mon, 22 Jun 2026 14:41:38 +1000 Subject: [PATCH] feat: allow additional envelope duplicate settings (#3008) --- .../dialogs/envelope-duplicate-dialog.tsx | 78 +++++++++++++++- .../envelope-actions.spec.ts | 90 +++++++++++++++++++ .../envelope-router/duplicate-envelope.ts | 6 +- .../duplicate-envelope.types.ts | 12 ++- 4 files changed, 182 insertions(+), 4 deletions(-) diff --git a/apps/remix/app/components/dialogs/envelope-duplicate-dialog.tsx b/apps/remix/app/components/dialogs/envelope-duplicate-dialog.tsx index 9e33d338c..893fbf6e9 100644 --- a/apps/remix/app/components/dialogs/envelope-duplicate-dialog.tsx +++ b/apps/remix/app/components/dialogs/envelope-duplicate-dialog.tsx @@ -1,6 +1,7 @@ import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams'; import { trpc } from '@documenso/trpc/react'; import { Button } from '@documenso/ui/primitives/button'; +import { Checkbox } from '@documenso/ui/primitives/checkbox'; import { Dialog, DialogClose, @@ -11,10 +12,12 @@ import { DialogTitle, DialogTrigger, } from '@documenso/ui/primitives/dialog'; +import { Label } from '@documenso/ui/primitives/label'; import { useToast } from '@documenso/ui/primitives/use-toast'; import { Trans, useLingui } from '@lingui/react/macro'; import { EnvelopeType } from '@prisma/client'; import { useState } from 'react'; +import { Controller, useForm } from 'react-hook-form'; import { useNavigate } from 'react-router'; import { useCurrentTeam } from '~/providers/team'; @@ -37,6 +40,15 @@ export const EnvelopeDuplicateDialog = ({ envelopeId, envelopeType, trigger }: E const isDocument = envelopeType === EnvelopeType.DOCUMENT; + const form = useForm({ + defaultValues: { + includeRecipients: true, + includeFields: true, + }, + }); + + const includeRecipients = form.watch('includeRecipients'); + const { mutateAsync: duplicateEnvelope, isPending: isDuplicating } = trpc.envelope.duplicate.useMutation({ onSuccess: async ({ id }) => { toast({ @@ -55,8 +67,14 @@ export const EnvelopeDuplicateDialog = ({ envelopeId, envelopeType, trigger }: E }); const onDuplicate = async () => { + const { includeRecipients, includeFields } = form.getValues(); + try { - await duplicateEnvelope({ envelopeId }); + await duplicateEnvelope({ + envelopeId, + includeRecipients, + includeFields: includeRecipients && includeFields, + }); } catch { toast({ title: t`Something went wrong`, @@ -70,7 +88,20 @@ export const EnvelopeDuplicateDialog = ({ envelopeId, envelopeType, trigger }: E }; return ( - !isDuplicating && setOpen(value)}> + { + if (isDuplicating) { + return; + } + + setOpen(value); + + if (!value) { + form.reset(); + } + }} + > {trigger && {trigger}} @@ -87,6 +118,49 @@ export const EnvelopeDuplicateDialog = ({ envelopeId, envelopeType, trigger }: E +
+ ( +
+ { + field.onChange(checked === true); + + if (!checked) { + form.setValue('includeFields', false); + } + }} + /> + +
+ )} + /> + + ( +
+ field.onChange(checked === true)} + /> + +
+ )} + /> +
+