mirror of
https://github.com/documenso/documenso.git
synced 2025-11-22 12:41:36 +10:00
feat: add envelope editor
This commit is contained in:
48
apps/remix/app/utils/field-signing/dropdown-field.ts
Normal file
48
apps/remix/app/utils/field-signing/dropdown-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
46
apps/remix/app/utils/field-signing/email-field.ts
Normal file
46
apps/remix/app/utils/field-signing/email-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
46
apps/remix/app/utils/field-signing/initial-field.ts
Normal file
46
apps/remix/app/utils/field-signing/initial-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
48
apps/remix/app/utils/field-signing/name-field.ts
Normal file
48
apps/remix/app/utils/field-signing/name-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
48
apps/remix/app/utils/field-signing/number-field.ts
Normal file
48
apps/remix/app/utils/field-signing/number-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
56
apps/remix/app/utils/field-signing/signature-field.ts
Normal file
56
apps/remix/app/utils/field-signing/signature-field.ts
Normal 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'),
|
||||
};
|
||||
};
|
||||
48
apps/remix/app/utils/field-signing/text-field.ts
Normal file
48
apps/remix/app/utils/field-signing/text-field.ts
Normal 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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user