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