fix: support dynamic external ids for direct templates (#1274)

Adds support for an `externalId` query param to be passed when linking a
user to a direct template. This external id will then be stored on the
document upon signing completion.
This commit is contained in:
Lucas Smith
2024-08-09 11:06:17 +10:00
committed by GitHub
parent c605877924
commit e5f73452b3
4 changed files with 15 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
import { useState } from 'react'; import { useState } from 'react';
import { useRouter } from 'next/navigation'; import { useRouter, useSearchParams } from 'next/navigation';
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles'; import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
import type { Field } from '@documenso/prisma/client'; import type { Field } from '@documenso/prisma/client';
@@ -39,6 +39,7 @@ export const DirectTemplatePageView = ({
directTemplateToken, directTemplateToken,
}: TemplatesDirectPageViewProps) => { }: TemplatesDirectPageViewProps) => {
const router = useRouter(); const router = useRouter();
const searchParams = useSearchParams();
const { toast } = useToast(); const { toast } = useToast();
@@ -82,8 +83,15 @@ export const DirectTemplatePageView = ({
const onSignDirectTemplateSubmit = async (fields: DirectTemplateLocalField[]) => { const onSignDirectTemplateSubmit = async (fields: DirectTemplateLocalField[]) => {
try { try {
let directTemplateExternalId = searchParams?.get('externalId') || undefined;
if (directTemplateExternalId) {
directTemplateExternalId = decodeURIComponent(directTemplateExternalId);
}
const token = await createDocumentFromDirectTemplate({ const token = await createDocumentFromDirectTemplate({
directTemplateToken, directTemplateToken,
directTemplateExternalId,
directRecipientName: fullName, directRecipientName: fullName,
directRecipientEmail: recipient.email, directRecipientEmail: recipient.email,
templateUpdatedAt: template.updatedAt, templateUpdatedAt: template.updatedAt,

View File

@@ -44,6 +44,7 @@ export type CreateDocumentFromDirectTemplateOptions = {
directRecipientName?: string; directRecipientName?: string;
directRecipientEmail: string; directRecipientEmail: string;
directTemplateToken: string; directTemplateToken: string;
directTemplateExternalId?: string;
signedFieldValues: TSignFieldWithTokenMutationSchema[]; signedFieldValues: TSignFieldWithTokenMutationSchema[];
templateUpdatedAt: Date; templateUpdatedAt: Date;
requestMetadata: RequestMetadata; requestMetadata: RequestMetadata;
@@ -63,6 +64,7 @@ export const createDocumentFromDirectTemplate = async ({
directRecipientName: initialDirectRecipientName, directRecipientName: initialDirectRecipientName,
directRecipientEmail, directRecipientEmail,
directTemplateToken, directTemplateToken,
directTemplateExternalId,
signedFieldValues, signedFieldValues,
templateUpdatedAt, templateUpdatedAt,
requestMetadata, requestMetadata,
@@ -227,6 +229,7 @@ export const createDocumentFromDirectTemplate = async ({
title: template.title, title: template.title,
createdAt: initialRequestTime, createdAt: initialRequestTime,
status: DocumentStatus.PENDING, status: DocumentStatus.PENDING,
externalId: directTemplateExternalId,
documentDataId: documentData.id, documentDataId: documentData.id,
authOptions: createDocumentAuthOptions({ authOptions: createDocumentAuthOptions({
globalAccessAuth: templateAuthOptions.globalAccessAuth, globalAccessAuth: templateAuthOptions.globalAccessAuth,

View File

@@ -66,6 +66,7 @@ export const templateRouter = router({
directRecipientName, directRecipientName,
directRecipientEmail, directRecipientEmail,
directTemplateToken, directTemplateToken,
directTemplateExternalId,
signedFieldValues, signedFieldValues,
templateUpdatedAt, templateUpdatedAt,
} = input; } = input;
@@ -76,6 +77,7 @@ export const templateRouter = router({
directRecipientName, directRecipientName,
directRecipientEmail, directRecipientEmail,
directTemplateToken, directTemplateToken,
directTemplateExternalId,
signedFieldValues, signedFieldValues,
templateUpdatedAt, templateUpdatedAt,
user: ctx.user user: ctx.user

View File

@@ -20,6 +20,7 @@ export const ZCreateDocumentFromDirectTemplateMutationSchema = z.object({
directRecipientName: z.string().optional(), directRecipientName: z.string().optional(),
directRecipientEmail: z.string().email(), directRecipientEmail: z.string().email(),
directTemplateToken: z.string().min(1), directTemplateToken: z.string().min(1),
directTemplateExternalId: z.string().optional(),
signedFieldValues: z.array(ZSignFieldWithTokenMutationSchema), signedFieldValues: z.array(ZSignFieldWithTokenMutationSchema),
templateUpdatedAt: z.date(), templateUpdatedAt: z.date(),
}); });