mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
fix: enhancements
This commit is contained in:
@ -98,8 +98,8 @@ export function UseTemplateDialog({
|
|||||||
sendDocument: false,
|
sendDocument: false,
|
||||||
recipients: recipients.map((recipient) => ({
|
recipients: recipients.map((recipient) => ({
|
||||||
id: recipient.id,
|
id: recipient.id,
|
||||||
name: recipient.name,
|
name: '',
|
||||||
email: recipient.email,
|
email: '',
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -156,15 +156,16 @@ export function UseTemplateDialog({
|
|||||||
<DialogContent className="sm:max-w-lg">
|
<DialogContent className="sm:max-w-lg">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Create document from template</DialogTitle>
|
<DialogTitle>Create document from template</DialogTitle>
|
||||||
<DialogDescription>Add the recipients to create the document with</DialogDescription>
|
<DialogDescription>
|
||||||
|
{recipients.length === 0
|
||||||
|
? 'A draft document will be created'
|
||||||
|
: 'Add the recipients to create the document with'}
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<fieldset
|
<fieldset className="flex h-full flex-col" disabled={form.formState.isSubmitting}>
|
||||||
className="flex h-full flex-col space-y-4"
|
|
||||||
disabled={form.formState.isSubmitting}
|
|
||||||
>
|
|
||||||
<div className="custom-scrollbar -m-1 max-h-[60vh] space-y-4 overflow-y-auto p-1">
|
<div className="custom-scrollbar -m-1 max-h-[60vh] space-y-4 overflow-y-auto p-1">
|
||||||
{formRecipients.map((recipient, index) => (
|
{formRecipients.map((recipient, index) => (
|
||||||
<div className="flex w-full flex-row space-x-4" key={recipient.id}>
|
<div className="flex w-full flex-row space-x-4" key={recipient.id}>
|
||||||
@ -201,46 +202,48 @@ export function UseTemplateDialog({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 flex flex-row items-center">
|
{recipients.length > 0 && (
|
||||||
<FormField
|
<div className="mt-4 flex flex-row items-center">
|
||||||
control={form.control}
|
<FormField
|
||||||
name="sendDocument"
|
control={form.control}
|
||||||
render={({ field }) => (
|
name="sendDocument"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<div className="flex flex-row items-center">
|
<FormItem>
|
||||||
<Checkbox
|
<div className="flex flex-row items-center">
|
||||||
id="sendDocument"
|
<Checkbox
|
||||||
className="h-5 w-5"
|
id="sendDocument"
|
||||||
checkClassName="dark:text-white text-primary"
|
className="h-5 w-5"
|
||||||
checked={field.value}
|
checkClassName="dark:text-white text-primary"
|
||||||
onCheckedChange={field.onChange}
|
checked={field.value}
|
||||||
/>
|
onCheckedChange={field.onChange}
|
||||||
|
/>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
className="text-muted-foreground ml-2 flex items-center text-sm"
|
className="text-muted-foreground ml-2 flex items-center text-sm"
|
||||||
htmlFor="sendDocument"
|
htmlFor="sendDocument"
|
||||||
>
|
>
|
||||||
Send document
|
Send document
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger type="button">
|
<TooltipTrigger type="button">
|
||||||
<InfoIcon className="mx-1 h-4 w-4" />
|
<InfoIcon className="mx-1 h-4 w-4" />
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
|
|
||||||
<TooltipContent className="text-muted-foreground z-[99999] max-w-md space-y-2 p-4">
|
<TooltipContent className="text-muted-foreground z-[99999] max-w-md space-y-2 p-4">
|
||||||
<p>
|
<p>
|
||||||
The document will be immediately sent to recipients if this is
|
The document will be immediately sent to recipients if this is
|
||||||
checked.
|
checked.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>Otherwise, the document will be created as a draft.</p>
|
<p>Otherwise, the document will be created as a draft.</p>
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<DialogClose asChild>
|
<DialogClose asChild>
|
||||||
@ -250,7 +253,11 @@ export function UseTemplateDialog({
|
|||||||
</DialogClose>
|
</DialogClose>
|
||||||
|
|
||||||
<Button type="submit" loading={form.formState.isSubmitting}>
|
<Button type="submit" loading={form.formState.isSubmitting}>
|
||||||
{form.getValues('sendDocument') ? 'Send' : 'Review'}
|
{recipients.length === 0
|
||||||
|
? 'Create'
|
||||||
|
: form.getValues('sendDocument')
|
||||||
|
? 'Send'
|
||||||
|
: 'Review'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|||||||
@ -56,13 +56,13 @@ export const createDocumentFromTemplate = async ({
|
|||||||
throw new Error('Template not found.');
|
throw new Error('Template not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipients.length === 0 || recipients.length !== template.Recipient.length) {
|
if (recipients.length !== template.Recipient.length) {
|
||||||
throw new Error('Invalid number of recipients.');
|
throw new Error('Invalid number of recipients.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalRecipients: Pick<Recipient, 'name' | 'email' | 'role'>[] = [];
|
let finalRecipients: Pick<Recipient, 'name' | 'email' | 'role'>[] = [];
|
||||||
|
|
||||||
if (Object.prototype.hasOwnProperty.call(recipients[0], 'id')) {
|
if (recipients.length > 0 && Object.prototype.hasOwnProperty.call(recipients[0], 'id')) {
|
||||||
finalRecipients = template.Recipient.map((templateRecipient) => {
|
finalRecipients = template.Recipient.map((templateRecipient) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
const foundRecipient = (recipients as RecipientWithId[]).find(
|
const foundRecipient = (recipients as RecipientWithId[]).find(
|
||||||
|
|||||||
@ -66,7 +66,9 @@ export const templateRouter = router({
|
|||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
teamId,
|
teamId,
|
||||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||||
}).catch(() => {
|
}).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
throw new AppError('DOCUMENT_SEND_FAILED');
|
throw new AppError('DOCUMENT_SEND_FAILED');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user