mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
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.
This commit is contained in:
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'),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user