mirror of
https://github.com/documenso/documenso.git
synced 2025-11-24 21:51:40 +10:00
feat: add envelope editor
This commit is contained in:
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user