mirror of
https://github.com/documenso/documenso.git
synced 2025-11-25 06:01:35 +10:00
feat: add envelope editor
This commit is contained in:
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