feat: add envelope editor

This commit is contained in:
David Nguyen
2025-10-12 23:35:54 +11:00
parent bf89bc781b
commit 0da8e7dbc6
307 changed files with 24657 additions and 3681 deletions

View File

@ -0,0 +1,48 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldDropdown } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldDropdownDialog } from '~/components/dialogs/sign-field-dropdown-dialog';
type HandleDropdownFieldClickOptions = {
field: TFieldDropdown;
text: string | null;
};
export const handleDropdownFieldClick = async (
options: HandleDropdownFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.DROPDOWN }> | null> => {
const { field, text } = options;
if (field.type !== FieldType.DROPDOWN || !field.fieldMeta) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.DROPDOWN,
value: null,
};
}
let textToInsert = text;
if (!textToInsert) {
textToInsert = await SignFieldDropdownDialog.call({
fieldMeta: field.fieldMeta,
});
}
if (!textToInsert) {
return null;
}
return {
type: FieldType.DROPDOWN,
value: textToInsert,
};
};

View File

@ -0,0 +1,46 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldEmail } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldEmailDialog } from '~/components/dialogs/sign-field-email-dialog';
type HandleEmailFieldClickOptions = {
field: TFieldEmail;
email: string | null;
};
export const handleEmailFieldClick = async (
options: HandleEmailFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.EMAIL }> | null> => {
const { field, email } = options;
if (field.type !== FieldType.EMAIL) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.EMAIL,
value: null,
};
}
let emailToInsert = email;
if (!emailToInsert) {
emailToInsert = await SignFieldEmailDialog.call({});
}
if (!emailToInsert) {
return null;
}
return {
type: FieldType.EMAIL,
value: emailToInsert,
};
};

View File

@ -0,0 +1,46 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldInitials } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldInitialsDialog } from '~/components/dialogs/sign-field-initials-dialog';
type HandleInitialsFieldClickOptions = {
field: TFieldInitials;
initials: string | null;
};
export const handleInitialsFieldClick = async (
options: HandleInitialsFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.INITIALS }> | null> => {
const { field, initials } = options;
if (field.type !== FieldType.INITIALS) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.INITIALS,
value: null,
};
}
let initialsToInsert = initials;
if (!initialsToInsert) {
initialsToInsert = await SignFieldInitialsDialog.call({});
}
if (!initialsToInsert) {
return null;
}
return {
type: FieldType.INITIALS,
value: initials,
};
};

View File

@ -0,0 +1,48 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldName } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldNameDialog } from '~/components/dialogs/sign-field-name-dialog';
type HandleNameFieldClickOptions = {
field: TFieldName;
name: string | null;
};
export const handleNameFieldClick = async (
options: HandleNameFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.NAME }> | null> => {
const { field, name } = options;
if (field.type !== FieldType.NAME) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.NAME,
value: null,
};
}
let nameToInsert = name;
if (!nameToInsert) {
nameToInsert = await SignFieldNameDialog.call({
// Props here.
});
}
if (!nameToInsert) {
return null;
}
return {
type: FieldType.NAME,
value: nameToInsert,
};
};

View File

@ -0,0 +1,48 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldNumber } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldNumberDialog } from '~/components/dialogs/sign-field-number-dialog';
type HandleNumberFieldClickOptions = {
field: TFieldNumber;
number: number | null;
};
export const handleNumberFieldClick = async (
options: HandleNumberFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.NUMBER }> | null> => {
const { field, number } = options;
if (field.type !== FieldType.NUMBER) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.NUMBER,
value: null,
};
}
let numberToInsert = number;
if (!numberToInsert) {
numberToInsert = await SignFieldNumberDialog.call({
fieldMeta: field.fieldMeta,
});
}
if (!numberToInsert) {
return null;
}
return {
type: FieldType.NUMBER,
value: numberToInsert,
};
};

View File

@ -0,0 +1,56 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldSignature } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldSignatureDialog } from '~/components/dialogs/sign-field-signature-dialog';
type HandleSignatureFieldClickOptions = {
field: TFieldSignature;
signature: string | null;
typedSignatureEnabled?: boolean;
uploadSignatureEnabled?: boolean;
drawSignatureEnabled?: boolean;
};
export const handleSignatureFieldClick = async (
options: HandleSignatureFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.SIGNATURE }> | null> => {
const { field, signature, typedSignatureEnabled, uploadSignatureEnabled, drawSignatureEnabled } =
options;
if (field.type !== FieldType.SIGNATURE) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.SIGNATURE,
value: null,
isBase64: false,
};
}
let signatureToInsert = signature;
if (!signatureToInsert) {
signatureToInsert = await SignFieldSignatureDialog.call({
typedSignatureEnabled,
uploadSignatureEnabled,
drawSignatureEnabled,
});
}
if (!signatureToInsert) {
return null;
}
return {
type: FieldType.SIGNATURE,
value: signatureToInsert,
isBase64: signatureToInsert.startsWith('data:image'),
};
};

View File

@ -0,0 +1,48 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldText } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { SignFieldTextDialog } from '~/components/dialogs/sign-field-text-dialog';
type HandleTextFieldClickOptions = {
field: TFieldText;
text: string | null;
};
export const handleTextFieldClick = async (
options: HandleTextFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.TEXT }> | null> => {
const { field, text } = options;
if (field.type !== FieldType.TEXT) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.TEXT,
value: null,
};
}
let textToInsert = text;
if (!textToInsert) {
textToInsert = await SignFieldTextDialog.call({
fieldMeta: field.fieldMeta,
});
}
if (!textToInsert) {
return null;
}
return {
type: FieldType.TEXT,
value: textToInsert,
};
};