mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: add direct templates links (#1165)
## Description Direct templates links is a feature that provides template owners the ability to allow users to create documents based of their templates. ## General outline This works by allowing the template owner to configure a "direct recipient" in the template. When a user opens the direct link to the template, it will create a flow where they sign the fields configured by the template owner for the direct recipient. After these fields are signed the following will occur: - A document will be created where the owner is the template owner - The direct recipient fields will be signed - The document will be sent to any other recipients configured in the template - If there are none the document will be immediately completed ## Notes There's a custom prisma migration to migrate all documents to have 'DOCUMENT' as the source, then sets the column to required. --------- Co-authored-by: Lucas Smith <me@lucasjamessmith.me>
This commit is contained in:
44
packages/lib/utils/templates.ts
Normal file
44
packages/lib/utils/templates.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import type { Recipient } from '@documenso/prisma/client';
|
||||
|
||||
import { WEBAPP_BASE_URL } from '../constants/app';
|
||||
|
||||
export const formatDirectTemplatePath = (token: string) => {
|
||||
return `${WEBAPP_BASE_URL}/d/${token}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate a placeholder recipient using an index number.
|
||||
*
|
||||
* May collide with existing recipients.
|
||||
*
|
||||
* Note:
|
||||
* - Update TEMPLATE_RECIPIENT_EMAIL_PLACEHOLDER_REGEX if this is ever changed.
|
||||
* - Update TEMPLATE_RECIPIENT_NAME_PLACEHOLDER_REGEX if this is ever changed.
|
||||
*
|
||||
*/
|
||||
export const generateRecipientPlaceholder = (index: number) => {
|
||||
return {
|
||||
name: `Recipient ${index}`,
|
||||
email: `recipient.${index}@documenso.com`,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a placeholder that does not collide with any existing recipients.
|
||||
*
|
||||
* @param currentRecipients The current recipients that exist for a template.
|
||||
*/
|
||||
export const generateAvaliableRecipientPlaceholder = (currentRecipients: Recipient[]) => {
|
||||
const recipientEmails = currentRecipients.map((recipient) => recipient.email);
|
||||
let recipientPlaceholder = generateRecipientPlaceholder(0);
|
||||
|
||||
for (let i = 1; i <= currentRecipients.length + 1; i++) {
|
||||
recipientPlaceholder = generateRecipientPlaceholder(i);
|
||||
|
||||
if (!recipientEmails.includes(recipientPlaceholder.email)) {
|
||||
return recipientPlaceholder;
|
||||
}
|
||||
}
|
||||
|
||||
return recipientPlaceholder;
|
||||
};
|
||||
Reference in New Issue
Block a user