Files
documenso/apps/remix/app/utils/field-signing/text-field.ts
David Nguyen 7f09ba72f4 feat: add envelopes (#2025)
This PR is handles the changes required to support envelopes. The new
envelope editor/signing page will be hidden during release.

The core changes here is to migrate the documents and templates model to
a centralized envelopes model.

Even though Documents and Templates are removed, from the user
perspective they will still exist as we remap envelopes to documents and
templates.
2025-10-14 21:56:36 +11:00

49 lines
1.2 KiB
TypeScript

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,
};
};