mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
chore: add more field types (#1141)
Adds a number of new field types and capabilities to existing fields. A massive change with far too many moving pieces to document in a single commit.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
|
||||
import { AppError } from '@documenso/lib/errors/app-error';
|
||||
import { getFieldById } from '@documenso/lib/server-only/field/get-field-by-id';
|
||||
import { removeSignedFieldWithToken } from '@documenso/lib/server-only/field/remove-signed-field-with-token';
|
||||
import { setFieldsForDocument } from '@documenso/lib/server-only/field/set-fields-for-document';
|
||||
import { setFieldsForTemplate } from '@documenso/lib/server-only/field/set-fields-for-template';
|
||||
@ -11,6 +12,7 @@ import { authenticatedProcedure, procedure, router } from '../trpc';
|
||||
import {
|
||||
ZAddFieldsMutationSchema,
|
||||
ZAddTemplateFieldsMutationSchema,
|
||||
ZGetFieldQuerySchema,
|
||||
ZRemovedSignedFieldWithTokenMutationSchema,
|
||||
ZSignFieldWithTokenMutationSchema,
|
||||
} from './schema';
|
||||
@ -34,6 +36,7 @@ export const fieldRouter = router({
|
||||
pageY: field.pageY,
|
||||
pageWidth: field.pageWidth,
|
||||
pageHeight: field.pageHeight,
|
||||
fieldMeta: field.fieldMeta,
|
||||
})),
|
||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
});
|
||||
@ -65,6 +68,7 @@ export const fieldRouter = router({
|
||||
pageY: field.pageY,
|
||||
pageWidth: field.pageWidth,
|
||||
pageHeight: field.pageHeight,
|
||||
fieldMeta: field.fieldMeta,
|
||||
})),
|
||||
});
|
||||
} catch (err) {
|
||||
@ -116,4 +120,49 @@ export const fieldRouter = router({
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
getField: authenticatedProcedure.input(ZGetFieldQuerySchema).query(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { fieldId, teamId } = input;
|
||||
|
||||
return await getFieldById({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
fieldId,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: 'We were unable to find this field. Please try again.',
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
// This doesn't appear to be used anywhere, and it doesn't seem to support updating template fields
|
||||
// so commenting this out for now.
|
||||
// updateField: authenticatedProcedure
|
||||
// .input(ZUpdateFieldMutationSchema)
|
||||
// .mutation(async ({ input, ctx }) => {
|
||||
// try {
|
||||
// const { documentId, fieldId, fieldMeta, teamId } = input;
|
||||
|
||||
// return await updateField({
|
||||
// userId: ctx.user.id,
|
||||
// teamId,
|
||||
// fieldId,
|
||||
// documentId,
|
||||
// requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
// fieldMeta: fieldMeta,
|
||||
// });
|
||||
// } catch (err) {
|
||||
// console.error(err);
|
||||
|
||||
// throw new TRPCError({
|
||||
// code: 'BAD_REQUEST',
|
||||
// message: 'We were unable to set this field. Please try again later.',
|
||||
// });
|
||||
// }
|
||||
// }),
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZRecipientActionAuthSchema } from '@documenso/lib/types/document-auth';
|
||||
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
import { FieldType } from '@documenso/prisma/client';
|
||||
|
||||
export const ZAddFieldsMutationSchema = z.object({
|
||||
@ -16,6 +17,7 @@ export const ZAddFieldsMutationSchema = z.object({
|
||||
pageY: z.number().min(0),
|
||||
pageWidth: z.number().min(0),
|
||||
pageHeight: z.number().min(0),
|
||||
fieldMeta: ZFieldMetaSchema,
|
||||
}),
|
||||
),
|
||||
});
|
||||
@ -35,6 +37,7 @@ export const ZAddTemplateFieldsMutationSchema = z.object({
|
||||
pageY: z.number().min(0),
|
||||
pageWidth: z.number().min(0),
|
||||
pageHeight: z.number().min(0),
|
||||
fieldMeta: ZFieldMetaSchema,
|
||||
}),
|
||||
),
|
||||
});
|
||||
@ -59,3 +62,17 @@ export const ZRemovedSignedFieldWithTokenMutationSchema = z.object({
|
||||
export type TRemovedSignedFieldWithTokenMutationSchema = z.infer<
|
||||
typeof ZRemovedSignedFieldWithTokenMutationSchema
|
||||
>;
|
||||
|
||||
export const ZGetFieldQuerySchema = z.object({
|
||||
fieldId: z.number(),
|
||||
teamId: z.number().optional(),
|
||||
});
|
||||
|
||||
export type TGetFieldQuerySchema = z.infer<typeof ZGetFieldQuerySchema>;
|
||||
|
||||
export const ZUpdateFieldMutationSchema = z.object({
|
||||
fieldId: z.number(),
|
||||
documentId: z.number(),
|
||||
fieldMeta: ZFieldMetaSchema,
|
||||
teamId: z.number().optional(),
|
||||
});
|
||||
|
||||
@ -23,6 +23,10 @@ export const mapField = (
|
||||
.with(FieldType.EMAIL, () => signer.email)
|
||||
.with(FieldType.NAME, () => signer.name)
|
||||
.with(FieldType.TEXT, () => signer.customText)
|
||||
.with(FieldType.NUMBER, () => signer.customText)
|
||||
.with(FieldType.RADIO, () => signer.customText)
|
||||
.with(FieldType.CHECKBOX, () => signer.customText)
|
||||
.with(FieldType.DROPDOWN, () => signer.customText)
|
||||
.otherwise(() => '');
|
||||
|
||||
return {
|
||||
|
||||
@ -31,7 +31,7 @@ export const singleplayerRouter = router({
|
||||
.input(ZCreateSinglePlayerDocumentMutationSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
const { signer, fields, documentData, documentName } = input;
|
||||
const { signer, fields, documentData, documentName, fieldMeta } = input;
|
||||
|
||||
const document = await getFile({
|
||||
data: documentData.data,
|
||||
@ -69,6 +69,7 @@ export const singleplayerRouter = router({
|
||||
documentId: -1,
|
||||
templateId: null,
|
||||
recipientId: -1,
|
||||
fieldMeta: fieldMeta || null,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
import { DocumentDataType, FieldType } from '@documenso/prisma/client';
|
||||
|
||||
export const ZCreateSinglePlayerDocumentMutationSchema = z.object({
|
||||
@ -24,6 +25,7 @@ export const ZCreateSinglePlayerDocumentMutationSchema = z.object({
|
||||
height: z.number(),
|
||||
}),
|
||||
),
|
||||
fieldMeta: ZFieldMetaSchema,
|
||||
});
|
||||
|
||||
export type TCreateSinglePlayerDocumentMutationSchema = z.infer<
|
||||
|
||||
Reference in New Issue
Block a user