Skip to content

The Open Source DocuSign Alternative.

fix: allow template recipients to be filled (#1148)

David Nguyene50ccca766c4
diff --git a/apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx b/apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx
index f8c7f9a43..d9da6c27c 100644
--- a/apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx
+++ b/apps/web/src/app/(dashboard)/templates/[id]/edit-template.tsx
@@ -141,6 +141,8 @@ export const EditTemplateForm = ({
recipients={recipients}
fields={fields}
onSubmit={onAddTemplatePlaceholderFormSubmit}
+ // Todo: Add when we setup template settings.
+ isTemplateOwnerEnterprise={false}
/>
<AddTemplateFieldsFormPartial
diff --git a/apps/web/src/app/(dashboard)/templates/[id]/template-page-view.tsx b/apps/web/src/app/(dashboard)/templates/[id]/template-page-view.tsx
index 7bb9640c5..8d5299177 100644
--- a/apps/web/src/app/(dashboard)/templates/[id]/template-page-view.tsx
+++ b/apps/web/src/app/(dashboard)/templates/[id]/template-page-view.tsx
@@ -73,7 +73,7 @@ export const TemplatePageView = async ({ params, team }: TemplatePageViewProps)
</div>
<EditTemplateForm
- className="mt-8"
+ className="mt-6"
template={template}
user={user}
recipients={templateRecipients}
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 7000e795a..d144eba3b 100644
--- a/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx
+++ b/apps/web/src/app/(dashboard)/templates/use-template-dialog.tsx
@@ -1,3 +1,5 @@
+import { useEffect, useState } from 'react';
+
import { useRouter } from 'next/navigation';
import { zodResolver } from '@hookform/resolvers/zod';
@@ -5,7 +7,10 @@ import { InfoIcon, Plus } from 'lucide-react';
import { useFieldArray, useForm } from 'react-hook-form';
import * as z from 'zod';
-import { TEMPLATE_RECIPIENT_PLACEHOLDER_REGEX } from '@documenso/lib/constants/template';
+import {
+ TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX,
+ TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX,
+} from '@documenso/lib/constants/template';
import { AppError } from '@documenso/lib/errors/app-error';
import type { Recipient } from '@documenso/prisma/client';
import { trpc } from '@documenso/trpc/react';
@@ -91,6 +96,8 @@ export function UseTemplateDialog({
const router = useRouter();
const { toast } = useToast();
+ const [open, setOpen] = useState(false);
+
const team = useOptionalCurrentTeam();
const form = useForm<TAddRecipientsForNewDocumentSchema>({
@@ -98,20 +105,18 @@ export function UseTemplateDialog({
defaultValues: {
sendDocument: false,
recipients: recipients.map((recipient) => {
- const isRecipientPlaceholder = recipient.email.match(TEMPLATE_RECIPIENT_PLACEHOLDER_REGEX);
+ const isRecipientEmailPlaceholder = recipient.email.match(
+ TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX,
+ );
- if (isRecipientPlaceholder) {
- return {
- id: recipient.id,
- name: '',
- email: '',
- };
- }
+ const isRecipientNamePlaceholder = recipient.name.match(
+ TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX,
+ );
return {
id: recipient.id,
- name: recipient.name,
- email: recipient.email,
+ name: !isRecipientNamePlaceholder ? recipient.name : '',
+ email: !isRecipientEmailPlaceholder ? recipient.email : '',
};
}),
},
@@ -158,8 +163,14 @@ export function UseTemplateDialog({
name: 'recipients',
});
+ useEffect(() => {
+ if (!open) {
+ form.reset();
+ }
+ }, [open, form]);
+
return (
- <Dialog>
+ <Dialog open={open} onOpenChange={(value) => !form.formState.isSubmitting && setOpen(value)}>
<DialogTrigger asChild>
<Button className="cursor-pointer">
<Plus className="-ml-1 mr-2 h-4 w-4" />
@@ -190,7 +201,7 @@ export function UseTemplateDialog({
{index === 0 && <FormLabel required>Email</FormLabel>}
<FormControl>
- <Input {...field} placeholder={recipients[index].email} />
+ <Input {...field} placeholder={recipients[index].email || 'Email'} />
</FormControl>
<FormMessage />
</FormItem>
@@ -205,7 +216,7 @@ export function UseTemplateDialog({
{index === 0 && <FormLabel>Name</FormLabel>}
<FormControl>
- <Input {...field} placeholder={recipients[index].name} />
+ <Input {...field} placeholder={recipients[index].name || 'Name'} />
</FormControl>
<FormMessage />
</FormItem>
diff --git a/packages/lib/constants/template.ts b/packages/lib/constants/template.ts
index 80dee97cf..061b9e594 100644
--- a/packages/lib/constants/template.ts
+++ b/packages/lib/constants/template.ts
@@ -1 +1,2 @@
-export const TEMPLATE_RECIPIENT_PLACEHOLDER_REGEX = /recipient\.\d+@documenso\.com/i;
+export const TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX = /recipient\.\d+@documenso\.com/i;
+export const TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX = /Recipient \d+/i;
diff --git a/packages/ui/components/recipient/recipient-action-auth-select.tsx b/packages/ui/components/recipient/recipient-action-auth-select.tsx
new file mode 100644
index 000000000..f42df157a
--- /dev/null
+++ b/packages/ui/components/recipient/recipient-action-auth-select.tsx
@@ -0,0 +1,80 @@
+'use client';
+
+import React from 'react';
+
+import type { SelectProps } from '@radix-ui/react-select';
+import { InfoIcon } from 'lucide-react';
+
+import { DOCUMENT_AUTH_TYPES } from '@documenso/lib/constants/document-auth';
+import { RecipientActionAuth } from '@documenso/lib/types/document-auth';
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from '@documenso/ui/primitives/select';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
+
+export type RecipientActionAuthSelectProps = SelectProps;
+
+export const RecipientActionAuthSelect = (props: RecipientActionAuthSelectProps) => {
+ return (
+ <Select {...props}>
+ <SelectTrigger className="bg-background text-muted-foreground">
+ <SelectValue placeholder="Inherit authentication method" />
+
+ <Tooltip>
+ <TooltipTrigger className="-mr-1 ml-auto">
+ <InfoIcon className="mx-2 h-4 w-4" />
+ </TooltipTrigger>
+
+ <TooltipContent className="text-foreground max-w-md p-4">
+ <h2>
+ <strong>Recipient action authentication</strong>
+ </h2>
+
+ <p>The authentication required for recipients to sign fields</p>
+
+ <p className="mt-2">This will override any global settings.</p>
+
+ <ul className="ml-3.5 list-outside list-disc space-y-0.5 py-2">
+ <li>
+ <strong>Inherit authentication method</strong> - Use the global action signing
+ authentication method configured in the "General Settings" step
+ </li>
+ {/* <li>
+ <strong>Require account</strong> - The recipient must be
+ signed in
+ </li> */}
+ <li>
+ <strong>Require passkey</strong> - The recipient must have an account and passkey
+ configured via their settings
+ </li>
+ <li>
+ <strong>Require 2FA</strong> - The recipient must have an account and 2FA enabled
+ via their settings
+ </li>
+ <li>
+ <strong>None</strong> - No authentication required
+ </li>
+ </ul>
+ </TooltipContent>
+ </Tooltip>
+ </SelectTrigger>
+
+ <SelectContent position="popper">
+ {/* Note: -1 is remapped in the Zod schema to the required value. */}
+ <SelectItem value="-1">Inherit authentication method</SelectItem>
+
+ {Object.values(RecipientActionAuth)
+ .filter((auth) => auth !== RecipientActionAuth.ACCOUNT)
+ .map((authType) => (
+ <SelectItem key={authType} value={authType}>
+ {DOCUMENT_AUTH_TYPES[authType].value}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ );
+};
diff --git a/packages/ui/components/recipient/recipient-role-select.tsx b/packages/ui/components/recipient/recipient-role-select.tsx
new file mode 100644
index 000000000..43d3331ae
--- /dev/null
+++ b/packages/ui/components/recipient/recipient-role-select.tsx
@@ -0,0 +1,97 @@
+'use client';
+
+import React from 'react';
+
+import type { SelectProps } from '@radix-ui/react-select';
+import { InfoIcon } from 'lucide-react';
+
+import { RecipientRole } from '@documenso/prisma/client';
+import { ROLE_ICONS } from '@documenso/ui/primitives/recipient-role-icons';
+import { Select, SelectContent, SelectItem, SelectTrigger } from '@documenso/ui/primitives/select';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@documenso/ui/primitives/tooltip';
+
+export type RecipientRoleSelectProps = SelectProps;
+
+export const RecipientRoleSelect = (props: RecipientRoleSelectProps) => {
+ return (
+ <Select {...props}>
+ <SelectTrigger className="bg-background w-[60px]">
+ {/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */}
+ {ROLE_ICONS[props.value as RecipientRole]}
+ </SelectTrigger>
+
+ <SelectContent align="end">
+ <SelectItem value={RecipientRole.SIGNER}>
+ <div className="flex items-center">
+ <div className="flex w-[150px] items-center">
+ <span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
+ Needs to sign
+ </div>
+ <Tooltip>
+ <TooltipTrigger>
+ <InfoIcon className="h-4 w-4" />
+ </TooltipTrigger>
+ <TooltipContent className="text-foreground z-9999 max-w-md p-4">
+ <p>The recipient is required to sign the document for it to be completed.</p>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </SelectItem>
+
+ <SelectItem value={RecipientRole.APPROVER}>
+ <div className="flex items-center">
+ <div className="flex w-[150px] items-center">
+ <span className="mr-2">{ROLE_ICONS[RecipientRole.APPROVER]}</span>
+ Needs to approve
+ </div>
+ <Tooltip>
+ <TooltipTrigger>
+ <InfoIcon className="h-4 w-4" />
+ </TooltipTrigger>
+ <TooltipContent className="text-foreground z-9999 max-w-md p-4">
+ <p>The recipient is required to approve the document for it to be completed.</p>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </SelectItem>
+
+ <SelectItem value={RecipientRole.VIEWER}>
+ <div className="flex items-center">
+ <div className="flex w-[150px] items-center">
+ <span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
+ Needs to view
+ </div>
+ <Tooltip>
+ <TooltipTrigger>
+ <InfoIcon className="h-4 w-4" />
+ </TooltipTrigger>
+ <TooltipContent className="text-foreground z-9999 max-w-md p-4">
+ <p>The recipient is required to view the document for it to be completed.</p>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </SelectItem>
+
+ <SelectItem value={RecipientRole.CC}>
+ <div className="flex items-center">
+ <div className="flex w-[150px] items-center">
+ <span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
+ Receives copy
+ </div>
+ <Tooltip>
+ <TooltipTrigger>
+ <InfoIcon className="h-4 w-4" />
+ </TooltipTrigger>
+ <TooltipContent className="text-foreground z-9999 max-w-md p-4">
+ <p>
+ The recipient is not required to take any action and receives a copy of the
+ document after it is completed.
+ </p>
+ </TooltipContent>
+ </Tooltip>
+ </div>
+ </SelectItem>
+ </SelectContent>
+ </Select>
+ );
+};
diff --git a/packages/ui/primitives/document-flow/add-signers.tsx b/packages/ui/primitives/document-flow/add-signers.tsx
index 2f9f2f234..cddff6bf5 100644
--- a/packages/ui/primitives/document-flow/add-signers.tsx
+++ b/packages/ui/primitives/document-flow/add-signers.tsx
@@ -4,20 +4,18 @@ import React, { useId, useMemo, useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import { motion } from 'framer-motion';
-import { InfoIcon, Plus, Trash } from 'lucide-react';
+import { Plus, Trash } from 'lucide-react';
import { useSession } from 'next-auth/react';
import { useFieldArray, useForm } from 'react-hook-form';
import { useLimits } from '@documenso/ee/server-only/limits/provider/client';
-import { DOCUMENT_AUTH_TYPES } from '@documenso/lib/constants/document-auth';
-import {
- RecipientActionAuth,
- ZRecipientAuthOptionsSchema,
-} from '@documenso/lib/types/document-auth';
+import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';
import { nanoid } from '@documenso/lib/universal/id';
import type { Field, Recipient } from '@documenso/prisma/client';
import { RecipientRole, SendStatus } from '@documenso/prisma/client';
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
+import { RecipientActionAuthSelect } from '@documenso/ui/components/recipient/recipient-action-auth-select';
+import { RecipientRoleSelect } from '@documenso/ui/components/recipient/recipient-role-select';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '../button';
@@ -25,10 +23,7 @@ import { Checkbox } from '../checkbox';
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../form/form';
import { FormErrorMessage } from '../form/form-error-message';
import { Input } from '../input';
-import { ROLE_ICONS } from '../recipient-role-icons';
-import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../select';
import { useStep } from '../stepper';
-import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip';
import { useToast } from '../use-toast';
import type { TAddSignersFormSchema } from './add-signers.types';
import { ZAddSignersFormSchema } from './add-signers.types';
@@ -274,67 +269,11 @@ export const AddSignersFormPartial = ({
render={({ field }) => (
<FormItem className="col-span-6">
<FormControl>
- <Select
+ <RecipientActionAuthSelect
{...field}
onValueChange={field.onChange}
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
- >
- <SelectTrigger className="bg-background text-muted-foreground">
- <SelectValue placeholder="Inherit authentication method" />
-
- <Tooltip>
- <TooltipTrigger className="-mr-1 ml-auto">
- <InfoIcon className="mx-2 h-4 w-4" />
- </TooltipTrigger>
-
- <TooltipContent className="text-foreground max-w-md p-4">
- <h2>
- <strong>Recipient action authentication</strong>
- </h2>
-
- <p>The authentication required for recipients to sign fields</p>
-
- <p className="mt-2">This will override any global settings.</p>
-
- <ul className="ml-3.5 list-outside list-disc space-y-0.5 py-2">
- <li>
- <strong>Inherit authentication method</strong> - Use the
- global action signing authentication method configured in
- the "General Settings" step
- </li>
- {/* <li>
- <strong>Require account</strong> - The recipient must be
- signed in
- </li> */}
- <li>
- <strong>Require passkey</strong> - The recipient must have
- an account and passkey configured via their settings
- </li>
- <li>
- <strong>Require 2FA</strong> - The recipient must have an
- account and 2FA enabled via their settings
- </li>
- <li>
- <strong>None</strong> - No authentication required
- </li>
- </ul>
- </TooltipContent>
- </Tooltip>
- </SelectTrigger>
-
- <SelectContent position="popper">
- {/* Note: -1 is remapped in the Zod schema to the required value. */}
- <SelectItem value="-1">Inherit authentication method</SelectItem>
-
- {Object.values(RecipientActionAuth)
- .filter((auth) => auth !== RecipientActionAuth.ACCOUNT)
- .map((authType) => (
- <SelectItem key={authType} value={authType}>
- {DOCUMENT_AUTH_TYPES[authType].value}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ />
</FormControl>
<FormMessage />
@@ -348,100 +287,11 @@ export const AddSignersFormPartial = ({
render={({ field }) => (
<FormItem className="col-span-1 mt-auto">
<FormControl>
- <Select
+ <RecipientRoleSelect
{...field}
onValueChange={field.onChange}
disabled={isSubmitting || hasBeenSentToRecipientId(signer.nativeId)}
- >
- <SelectTrigger className="bg-background w-[60px]">
- {/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */}
- {ROLE_ICONS[field.value as RecipientRole]}
- </SelectTrigger>
-
- <SelectContent align="end">
- <SelectItem value={RecipientRole.SIGNER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
- Needs to sign
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to sign the document for it to be
- completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.APPROVER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">
- {ROLE_ICONS[RecipientRole.APPROVER]}
- </span>
- Needs to approve
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to approve the document for it to
- be completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.VIEWER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
- Needs to view
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to view the document for it to be
- completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.CC}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
- Receives copy
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is not required to take any action and
- receives a copy of the document after it is completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
- </SelectContent>
- </Select>
+ />
</FormControl>
<FormMessage />
diff --git a/packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx b/packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx
index cd48158c4..bbed6a39a 100644
--- a/packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx
+++ b/packages/ui/primitives/template-flow/add-template-placeholder-recipients.tsx
@@ -1,20 +1,25 @@
'use client';
-import React, { useId, useState } from 'react';
+import React, { useId, useMemo, useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
-import { AnimatePresence, motion } from 'framer-motion';
-import { InfoIcon, Plus, Trash } from 'lucide-react';
+import { motion } from 'framer-motion';
+import { Plus, Trash } from 'lucide-react';
import { useSession } from 'next-auth/react';
-import { Controller, useFieldArray, useForm } from 'react-hook-form';
+import { useFieldArray, useForm } from 'react-hook-form';
+import { ZRecipientAuthOptionsSchema } from '@documenso/lib/types/document-auth';
import { nanoid } from '@documenso/lib/universal/id';
import { type Field, type Recipient, RecipientRole } from '@documenso/prisma/client';
+import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
+import { RecipientActionAuthSelect } from '@documenso/ui/components/recipient/recipient-action-auth-select';
+import { RecipientRoleSelect } from '@documenso/ui/components/recipient/recipient-role-select';
+import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
import { FormErrorMessage } from '@documenso/ui/primitives/form/form-error-message';
import { Input } from '@documenso/ui/primitives/input';
-import { Label } from '@documenso/ui/primitives/label';
+import { Checkbox } from '../checkbox';
import {
DocumentFlowFormContainerActions,
DocumentFlowFormContainerContent,
@@ -22,10 +27,8 @@ import {
DocumentFlowFormContainerStep,
} from '../document-flow/document-flow-root';
import type { DocumentFlowStep } from '../document-flow/types';
-import { ROLE_ICONS } from '../recipient-role-icons';
-import { Select, SelectContent, SelectItem, SelectTrigger } from '../select';
+import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../form/form';
import { useStep } from '../stepper';
-import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip';
import type { TAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
import { ZAddTemplatePlacholderRecipientsFormSchema } from './add-template-placeholder-recipients.types';
@@ -33,30 +36,29 @@ export type AddTemplatePlaceholderRecipientsFormProps = {
documentFlow: DocumentFlowStep;
recipients: Recipient[];
fields: Field[];
+ isTemplateOwnerEnterprise: boolean;
onSubmit: (_data: TAddTemplatePlacholderRecipientsFormSchema) => void;
};
export const AddTemplatePlaceholderRecipientsFormPartial = ({
documentFlow,
+ isTemplateOwnerEnterprise,
recipients,
fields: _fields,
onSubmit,
}: AddTemplatePlaceholderRecipientsFormProps) => {
const initialId = useId();
const { data: session } = useSession();
+
const user = session?.user;
+
const [placeholderRecipientCount, setPlaceholderRecipientCount] = useState(() =>
recipients.length > 1 ? recipients.length + 1 : 2,
);
const { currentStep, totalSteps, previousStep } = useStep();
- const {
- control,
- handleSubmit,
- getValues,
- formState: { errors, isSubmitting },
- } = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
+ const form = useForm<TAddTemplatePlacholderRecipientsFormSchema>({
resolver: zodResolver(ZAddTemplatePlacholderRecipientsFormSchema),
defaultValues: {
signers:
@@ -67,6 +69,8 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
name: recipient.name,
email: recipient.email,
role: recipient.role,
+ actionAuth:
+ ZRecipientAuthOptionsSchema.parse(recipient.authOptions)?.actionAuth ?? undefined,
}))
: [
{
@@ -74,12 +78,33 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
name: `Recipient 1`,
role: RecipientRole.SIGNER,
+ actionAuth: undefined,
},
],
},
});
- const onFormSubmit = handleSubmit(onSubmit);
+ // Always show advanced settings if any recipient has auth options.
+ const alwaysShowAdvancedSettings = useMemo(() => {
+ const recipientHasAuthOptions = recipients.find((recipient) => {
+ const recipientAuthOptions = ZRecipientAuthOptionsSchema.parse(recipient.authOptions);
+
+ return recipientAuthOptions?.accessAuth || recipientAuthOptions?.actionAuth;
+ });
+
+ const formHasActionAuth = form.getValues('signers').find((signer) => signer.actionAuth);
+
+ return recipientHasAuthOptions !== undefined || formHasActionAuth !== undefined;
+ }, [recipients, form]);
+
+ const [showAdvancedSettings, setShowAdvancedSettings] = useState(alwaysShowAdvancedSettings);
+
+ const {
+ formState: { errors, isSubmitting },
+ control,
+ } = form;
+
+ const onFormSubmit = form.handleSubmit(onSubmit);
const {
append: appendSigner,
@@ -102,8 +127,9 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
const onAddPlaceholderRecipient = () => {
appendSigner({
formId: nanoid(12),
+ // Update TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX if this is ever changed.
name: `Recipient ${placeholderRecipientCount}`,
- // Update TEMPLATE_RECIPIENT_PLACEHOLDER_REGEX if this is ever changed.
+ // Update TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX if this is ever changed.
email: `recipient.${placeholderRecipientCount}@documenso.com`,
role: RecipientRole.SIGNER,
});
@@ -118,181 +144,176 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
return (
<>
<DocumentFlowFormContainerContent>
- <div className="flex w-full flex-col gap-y-4">
- <AnimatePresence>
- {signers.map((signer, index) => (
- <motion.div
- key={signer.id}
- data-native-id={signer.nativeId}
- className="flex flex-wrap items-end gap-x-4"
- >
- <div className="flex-1">
- <Label htmlFor={`signer-${signer.id}-email`}>Email</Label>
-
- <Input
- id={`signer-${signer.id}-email`}
- type="email"
- value={signer.email}
- disabled
- className="bg-background mt-2"
+ <AnimateGenericFadeInOut motionKey={showAdvancedSettings ? 'Show' : 'Hide'}>
+ <Form {...form}>
+ <div className="flex w-full flex-col gap-y-2">
+ {signers.map((signer, index) => (
+ <motion.fieldset
+ key={signer.id}
+ data-native-id={signer.nativeId}
+ disabled={isSubmitting}
+ className={cn('grid grid-cols-8 gap-4 pb-4', {
+ 'border-b pt-2': showAdvancedSettings,
+ })}
+ >
+ <FormField
+ control={form.control}
+ name={`signers.${index}.email`}
+ render={({ field }) => (
+ <FormItem
+ className={cn('relative', {
+ 'col-span-3': !showAdvancedSettings,
+ 'col-span-4': showAdvancedSettings,
+ })}
+ >
+ {!showAdvancedSettings && index === 0 && (
+ <FormLabel required>Email</FormLabel>
+ )}
+
+ <FormControl>
+ <Input
+ type="email"
+ placeholder="Email"
+ {...field}
+ disabled={isSubmitting || signers[index].email === user?.email}
+ />
+ </FormControl>
+
+ <FormMessage />
+ </FormItem>
+ )}
/>
- </div>
- <div className="flex-1">
- <Label htmlFor={`signer-${signer.id}-name`}>Name</Label>
+ <FormField
+ control={form.control}
+ name={`signers.${index}.name`}
+ render={({ field }) => (
+ <FormItem
+ className={cn({
+ 'col-span-3': !showAdvancedSettings,
+ 'col-span-4': showAdvancedSettings,
+ })}
+ >
+ {!showAdvancedSettings && index === 0 && <FormLabel>Name</FormLabel>}
+
+ <FormControl>
+ <Input
+ placeholder="Name"
+ {...field}
+ disabled={isSubmitting || signers[index].email === user?.email}
+ />
+ </FormControl>
- <Input
- id={`signer-${signer.id}-name`}
- type="text"
- value={signer.name}
- disabled
- className="bg-background mt-2"
+ <FormMessage />
+ </FormItem>
+ )}
/>
- </div>
- <div className="w-[60px]">
- <Controller
- control={control}
+ {showAdvancedSettings && isTemplateOwnerEnterprise && (
+ <FormField
+ control={form.control}
+ name={`signers.${index}.actionAuth`}
+ render={({ field }) => (
+ <FormItem className="col-span-6">
+ <FormControl>
+ <RecipientActionAuthSelect
+ {...field}
+ onValueChange={field.onChange}
+ disabled={isSubmitting}
+ />
+ </FormControl>
+
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+
+ <FormField
name={`signers.${index}.role`}
- render={({ field: { value, onChange } }) => (
- <Select value={value} onValueChange={(x) => onChange(x)}>
- <SelectTrigger className="bg-background">{ROLE_ICONS[value]}</SelectTrigger>
-
- <SelectContent className="" align="end">
- <SelectItem value={RecipientRole.SIGNER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.SIGNER]}</span>
- Needs to sign
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to sign the document for it to be
- completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.APPROVER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.APPROVER]}</span>
- Needs to approve
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to approve the document for it to be
- completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.VIEWER}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.VIEWER]}</span>
- Needs to view
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is required to view the document for it to be
- completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
-
- <SelectItem value={RecipientRole.CC}>
- <div className="flex items-center">
- <div className="flex w-[150px] items-center">
- <span className="mr-2">{ROLE_ICONS[RecipientRole.CC]}</span>
- Receives copy
- </div>
- <Tooltip>
- <TooltipTrigger>
- <InfoIcon className="h-4 w-4" />
- </TooltipTrigger>
- <TooltipContent className="text-foreground z-9999 max-w-md p-4">
- <p>
- The recipient is not required to take any action and receives a
- copy of the document after it is completed.
- </p>
- </TooltipContent>
- </Tooltip>
- </div>
- </SelectItem>
- </SelectContent>
- </Select>
+ render={({ field }) => (
+ <FormItem className="col-span-1 mt-auto">
+ <FormControl>
+ <RecipientRoleSelect
+ {...field}
+ onValueChange={field.onChange}
+ disabled={isSubmitting}
+ />
+ </FormControl>
+
+ <FormMessage />
+ </FormItem>
)}
/>
- </div>
- <div>
<button
type="button"
- className="inline-flex h-10 w-10 items-center justify-center text-slate-500 hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50"
+ className="col-span-1 mt-auto inline-flex h-10 w-10 items-center justify-center text-slate-500 hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-50"
disabled={isSubmitting || signers.length === 1}
onClick={() => onRemoveSigner(index)}
>
<Trash className="h-5 w-5" />
</button>
- </div>
-
- <div className="w-full">
- <FormErrorMessage className="mt-2" error={errors.signers?.[index]?.email} />
- <FormErrorMessage className="mt-2" error={errors.signers?.[index]?.name} />
- </div>
- </motion.div>
- ))}
- </AnimatePresence>
- </div>
-
- <FormErrorMessage
- className="mt-2"
- // Dirty hack to handle errors when .root is populated for an array type
- error={'signers__root' in errors && errors['signers__root']}
- />
+ </motion.fieldset>
+ ))}
+ </div>
+
+ <FormErrorMessage
+ className="mt-2"
+ // Dirty hack to handle errors when .root is populated for an array type
+ error={'signers__root' in errors && errors['signers__root']}
+ />
+
+ <div
+ className={cn('mt-2 flex flex-row items-center space-x-4', {
+ 'mt-4': showAdvancedSettings,
+ })}
+ >
+ <Button
+ type="button"
+ className="flex-1"
+ disabled={isSubmitting}
+ onClick={() => onAddPlaceholderRecipient()}
+ >
+ <Plus className="-ml-1 mr-2 h-5 w-5" />
+ Add Placeholder Recipient
+ </Button>
+
+ <Button
+ type="button"
+ className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
+ variant="secondary"
+ disabled={
+ isSubmitting ||
+ form.getValues('signers').some((signer) => signer.email === user?.email)
+ }
+ onClick={() => onAddPlaceholderSelfRecipient()}
+ >
+ <Plus className="-ml-1 mr-2 h-5 w-5" />
+ Add Myself
+ </Button>
+ </div>
+
+ {!alwaysShowAdvancedSettings && isTemplateOwnerEnterprise && (
+ <div className="mt-4 flex flex-row items-center">
+ <Checkbox
+ id="showAdvancedRecipientSettings"
+ className="h-5 w-5"
+ checkClassName="dark:text-white text-primary"
+ checked={showAdvancedSettings}
+ onCheckedChange={(value) => setShowAdvancedSettings(Boolean(value))}
+ />
- <div className="mt-4 flex flex-row items-center space-x-4">
- <Button
- type="button"
- className="flex-1"
- disabled={isSubmitting}
- onClick={() => onAddPlaceholderRecipient()}
- >
- <Plus className="-ml-1 mr-2 h-5 w-5" />
- Add Placeholder Recipient
- </Button>
- <Button
- type="button"
- className="dark:bg-muted dark:hover:bg-muted/80 bg-black/5 hover:bg-black/10"
- variant="secondary"
- disabled={
- isSubmitting || getValues('signers').some((signer) => signer.email === user?.email)
- }
- onClick={() => onAddPlaceholderSelfRecipient()}
- >
- <Plus className="-ml-1 mr-2 h-5 w-5" />
- Add Myself
- </Button>
- </div>
+ <label
+ className="text-muted-foreground ml-2 text-sm"
+ htmlFor="showAdvancedRecipientSettings"
+ >
+ Show advanced settings
+ </label>
+ </div>
+ )}
+ </Form>
+ </AnimateGenericFadeInOut>
</DocumentFlowFormContainerContent>
<DocumentFlowFormContainerFooter>
diff --git a/packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts b/packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts
index d2ffc090b..18df2d33b 100644
--- a/packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts
+++ b/packages/ui/primitives/template-flow/add-template-placeholder-recipients.types.ts
@@ -1,5 +1,8 @@
import { z } from 'zod';
+import { ZRecipientActionAuthTypesSchema } from '@documenso/lib/types/document-auth';
+
+import { ZMapNegativeOneToUndefinedSchema } from '../document-flow/add-settings.types';
import { RecipientRole } from '.prisma/client';
export const ZAddTemplatePlacholderRecipientsFormSchema = z
@@ -11,6 +14,9 @@ export const ZAddTemplatePlacholderRecipientsFormSchema = z
email: z.string().min(1).email(),
name: z.string(),
role: z.nativeEnum(RecipientRole),
+ actionAuth: ZMapNegativeOneToUndefinedSchema.pipe(
+ ZRecipientActionAuthTypesSchema.optional(),
+ ),
}),
),
})