fix: dont flatten forms for templates (#2386)

Templates shouldn't have their form flattened until they're
converted to a document.
This commit is contained in:
Lucas Smith
2026-01-14 12:06:28 +11:00
committed by GitHub
parent 34f512bd55
commit c976e747e3
14 changed files with 918 additions and 71 deletions
@@ -1,3 +1,5 @@
import { EnvelopeType } from '@prisma/client';
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { createEnvelope } from '@documenso/lib/server-only/envelope/create-envelope';
@@ -80,11 +82,16 @@ export const createEnvelopeRoute = authenticatedProcedure
});
}
const { id: documentDataId } = await putNormalizedPdfFileServerSide({
name: file.name,
type: 'application/pdf',
arrayBuffer: async () => Promise.resolve(pdf),
});
const { id: documentDataId } = await putNormalizedPdfFileServerSide(
{
name: file.name,
type: 'application/pdf',
arrayBuffer: async () => Promise.resolve(pdf),
},
{
flattenForm: type !== EnvelopeType.TEMPLATE,
},
);
return {
title: file.name,
@@ -34,6 +34,7 @@ export const useEnvelopeRoute = authenticatedProcedure
prefillFields,
override,
attachments,
formValues,
} = payload;
ctx.logger.info({
@@ -79,7 +80,10 @@ export const useEnvelopeRoute = authenticatedProcedure
// Process uploaded files and create document data for them
const uploadedFiles = await Promise.all(
filesToUpload.map(async (file) => {
const { id: documentDataId } = await putNormalizedPdfFileServerSide(file);
// We disable flattening here since `createDocumentFromTemplate` will handle it.
const { id: documentDataId } = await putNormalizedPdfFileServerSide(file, {
flattenForm: false,
});
return {
name: file.name,
@@ -146,6 +150,7 @@ export const useEnvelopeRoute = authenticatedProcedure
prefillFields,
override,
attachments,
formValues,
});
// Distribute document if requested
@@ -2,6 +2,7 @@ import { z } from 'zod';
import { zfd } from 'zod-form-data';
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
import {
ZDocumentMetaDateFormatSchema,
ZDocumentMetaDistributionMethodSchema,
@@ -108,6 +109,8 @@ export const ZUseEnvelopePayloadSchema = z.object({
}),
)
.optional(),
formValues: ZDocumentFormValuesSchema.optional(),
});
export const ZUseEnvelopeRequestSchema = zodFormData({
@@ -197,7 +197,9 @@ export const templateRouter = router({
attachments,
} = payload;
const { id: templateDocumentDataId } = await putNormalizedPdfFileServerSide(file);
const { id: templateDocumentDataId } = await putNormalizedPdfFileServerSide(file, {
flattenForm: false,
});
ctx.logger.info({
input: {
@@ -468,6 +470,7 @@ export const templateRouter = router({
externalId,
override,
attachments,
formValues,
} = input;
ctx.logger.info({
@@ -507,6 +510,7 @@ export const templateRouter = router({
externalId,
override,
attachments,
formValues,
});
if (distributeDocument) {
@@ -8,6 +8,7 @@ import {
ZDocumentActionAuthTypesSchema,
} from '@documenso/lib/types/document-auth';
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
import {
ZDocumentMetaDateFormatSchema,
ZDocumentMetaDistributionMethodSchema,
@@ -172,6 +173,8 @@ export const ZCreateDocumentFromTemplateRequestSchema = z.object({
}),
)
.optional(),
formValues: ZDocumentFormValuesSchema.optional(),
});
export const ZCreateDocumentFromTemplateResponseSchema = ZDocumentSchema;