mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
feat: add envelopes api (#2105)
This commit is contained in:
@ -19,13 +19,15 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
|
|||||||
import { useCurrentTeam } from '~/providers/team';
|
import { useCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
type DocumentDuplicateDialogProps = {
|
type DocumentDuplicateDialogProps = {
|
||||||
id: number;
|
id: string;
|
||||||
|
token?: string;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (_open: boolean) => void;
|
onOpenChange: (_open: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DocumentDuplicateDialog = ({
|
export const DocumentDuplicateDialog = ({
|
||||||
id,
|
id,
|
||||||
|
token,
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
}: DocumentDuplicateDialogProps) => {
|
}: DocumentDuplicateDialogProps) => {
|
||||||
@ -36,27 +38,23 @@ export const DocumentDuplicateDialog = ({
|
|||||||
|
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
|
|
||||||
const { data: document, isLoading } = trpcReact.document.get.useQuery(
|
const { data: envelopeItemsPayload, isLoading: isLoadingEnvelopeItems } =
|
||||||
|
trpcReact.envelope.item.getManyByToken.useQuery(
|
||||||
{
|
{
|
||||||
documentId: id,
|
envelopeId: id,
|
||||||
|
access: token ? { type: 'recipient', token } : { type: 'user' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
queryHash: `document-duplicate-dialog-${id}`,
|
enabled: open,
|
||||||
enabled: open === true,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const documentData = document?.documentData
|
const envelopeItems = envelopeItemsPayload?.data || [];
|
||||||
? {
|
|
||||||
...document.documentData,
|
|
||||||
data: document.documentData.initialData,
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const documentsPath = formatDocumentsPath(team.url);
|
const documentsPath = formatDocumentsPath(team.url);
|
||||||
|
|
||||||
const { mutateAsync: duplicateDocument, isPending: isDuplicateLoading } =
|
const { mutateAsync: duplicateEnvelope, isPending: isDuplicating } =
|
||||||
trpcReact.document.duplicate.useMutation({
|
trpcReact.envelope.duplicate.useMutation({
|
||||||
onSuccess: async ({ id }) => {
|
onSuccess: async ({ id }) => {
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Document Duplicated`),
|
title: _(msg`Document Duplicated`),
|
||||||
@ -71,7 +69,7 @@ export const DocumentDuplicateDialog = ({
|
|||||||
|
|
||||||
const onDuplicate = async () => {
|
const onDuplicate = async () => {
|
||||||
try {
|
try {
|
||||||
await duplicateDocument({ documentId: id });
|
await duplicateEnvelope({ envelopeId: id });
|
||||||
} catch {
|
} catch {
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Something went wrong`),
|
title: _(msg`Something went wrong`),
|
||||||
@ -83,14 +81,14 @@ export const DocumentDuplicateDialog = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={(value) => !isLoading && onOpenChange(value)}>
|
<Dialog open={open} onOpenChange={(value) => !isDuplicating && onOpenChange(value)}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
<Trans>Duplicate</Trans>
|
<Trans>Duplicate</Trans>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{!documentData || isLoading ? (
|
{isLoadingEnvelopeItems || !envelopeItems || envelopeItems.length === 0 ? (
|
||||||
<div className="mx-auto -mt-4 flex w-full max-w-screen-xl flex-col px-4 md:px-8">
|
<div className="mx-auto -mt-4 flex w-full max-w-screen-xl flex-col px-4 md:px-8">
|
||||||
<h1 className="mt-4 grow-0 truncate text-2xl font-semibold md:text-3xl">
|
<h1 className="mt-4 grow-0 truncate text-2xl font-semibold md:text-3xl">
|
||||||
<Trans>Loading Document...</Trans>
|
<Trans>Loading Document...</Trans>
|
||||||
@ -98,7 +96,12 @@ export const DocumentDuplicateDialog = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="p-2 [&>div]:h-[50vh] [&>div]:overflow-y-scroll">
|
<div className="p-2 [&>div]:h-[50vh] [&>div]:overflow-y-scroll">
|
||||||
<PDFViewer key={document?.id} documentData={documentData} />
|
<PDFViewer
|
||||||
|
key={envelopeItems[0].id}
|
||||||
|
envelopeItem={envelopeItems[0]}
|
||||||
|
token={undefined}
|
||||||
|
version="original"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -115,8 +118,8 @@ export const DocumentDuplicateDialog = ({
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={isDuplicateLoading || isLoading}
|
disabled={isDuplicating}
|
||||||
loading={isDuplicateLoading}
|
loading={isDuplicating}
|
||||||
onClick={onDuplicate}
|
onClick={onDuplicate}
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
>
|
>
|
||||||
|
|||||||
@ -2,11 +2,10 @@ import { useState } from 'react';
|
|||||||
|
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { type DocumentData, DocumentStatus, type EnvelopeItem } from '@prisma/client';
|
import { DocumentStatus, type EnvelopeItem } from '@prisma/client';
|
||||||
import { DownloadIcon, FileTextIcon } from 'lucide-react';
|
import { DownloadIcon, FileTextIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { downloadFile } from '@documenso/lib/client-only/download-file';
|
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
@ -20,9 +19,7 @@ import {
|
|||||||
import { Skeleton } from '@documenso/ui/primitives/skeleton';
|
import { Skeleton } from '@documenso/ui/primitives/skeleton';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
type EnvelopeItemToDownload = Pick<EnvelopeItem, 'id' | 'title' | 'order'> & {
|
type EnvelopeItemToDownload = Pick<EnvelopeItem, 'id' | 'envelopeId' | 'title' | 'order'>;
|
||||||
documentData: DocumentData;
|
|
||||||
};
|
|
||||||
|
|
||||||
type EnvelopeDownloadDialogProps = {
|
type EnvelopeDownloadDialogProps = {
|
||||||
envelopeId: string;
|
envelopeId: string;
|
||||||
@ -64,12 +61,12 @@ export const EnvelopeDownloadDialog = ({
|
|||||||
access: token ? { type: 'recipient', token } : { type: 'user' },
|
access: token ? { type: 'recipient', token } : { type: 'user' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
initialData: initialEnvelopeItems ? { envelopeItems: initialEnvelopeItems } : undefined,
|
initialData: initialEnvelopeItems ? { data: initialEnvelopeItems } : undefined,
|
||||||
enabled: open,
|
enabled: open,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const envelopeItems = envelopeItemsPayload?.envelopeItems || [];
|
const envelopeItems = envelopeItemsPayload?.data || [];
|
||||||
|
|
||||||
const onDownload = async (
|
const onDownload = async (
|
||||||
envelopeItem: EnvelopeItemToDownload,
|
envelopeItem: EnvelopeItemToDownload,
|
||||||
@ -87,25 +84,11 @@ export const EnvelopeDownloadDialog = ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await getFile({
|
await downloadPDF({
|
||||||
type: envelopeItem.documentData.type,
|
envelopeItem,
|
||||||
data:
|
token,
|
||||||
version === 'signed'
|
fileName: envelopeItem.title,
|
||||||
? envelopeItem.documentData.data
|
version,
|
||||||
: envelopeItem.documentData.initialData,
|
|
||||||
});
|
|
||||||
|
|
||||||
const blob = new Blob([data], {
|
|
||||||
type: 'application/pdf',
|
|
||||||
});
|
|
||||||
|
|
||||||
const baseTitle = envelopeItem.title.replace(/\.pdf$/, '');
|
|
||||||
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
|
||||||
const filename = `${baseTitle}${suffix}`;
|
|
||||||
|
|
||||||
downloadFile({
|
|
||||||
filename,
|
|
||||||
data: blob,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsDownloadingState((prev) => ({
|
setIsDownloadingState((prev) => ({
|
||||||
@ -146,7 +129,7 @@ export const EnvelopeDownloadDialog = ({
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{isLoadingEnvelopeItems ? (
|
{isLoadingEnvelopeItems ? (
|
||||||
<>
|
<>
|
||||||
{Array.from({ length: 2 }).map((_, index) => (
|
{Array.from({ length: 1 }).map((_, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className="border-border bg-card flex items-center gap-2 rounded-lg border p-4"
|
className="border-border bg-card flex items-center gap-2 rounded-lg border p-4"
|
||||||
@ -175,6 +158,7 @@ export const EnvelopeDownloadDialog = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
|
{/* Todo: Envelopes - Fix overflow */}
|
||||||
<h4 className="text-foreground truncate text-sm font-medium">{item.title}</h4>
|
<h4 className="text-foreground truncate text-sm font-medium">{item.title}</h4>
|
||||||
<p className="text-muted-foreground mt-0.5 text-xs">
|
<p className="text-muted-foreground mt-0.5 text-xs">
|
||||||
<Trans>PDF Document</Trans>
|
<Trans>PDF Document</Trans>
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export const EnvelopeDuplicateDialog = ({
|
|||||||
|
|
||||||
const { mutateAsync: duplicateEnvelope, isPending: isDuplicating } =
|
const { mutateAsync: duplicateEnvelope, isPending: isDuplicating } =
|
||||||
trpc.envelope.duplicate.useMutation({
|
trpc.envelope.duplicate.useMutation({
|
||||||
onSuccess: async ({ duplicatedEnvelopeId }) => {
|
onSuccess: async ({ id }) => {
|
||||||
toast({
|
toast({
|
||||||
title: t`Envelope Duplicated`,
|
title: t`Envelope Duplicated`,
|
||||||
description: t`Your envelope has been successfully duplicated.`,
|
description: t`Your envelope has been successfully duplicated.`,
|
||||||
@ -55,7 +55,7 @@ export const EnvelopeDuplicateDialog = ({
|
|||||||
? formatDocumentsPath(team.url)
|
? formatDocumentsPath(team.url)
|
||||||
: formatTemplatesPath(team.url);
|
: formatTemplatesPath(team.url);
|
||||||
|
|
||||||
await navigate(`${path}/${duplicatedEnvelopeId}/edit`);
|
await navigate(`${path}/${id}/edit`);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,9 +7,9 @@ import { FilePlus, Loader } from 'lucide-react';
|
|||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { formatTemplatesPath } from '@documenso/lib/utils/teams';
|
import { formatTemplatesPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateTemplatePayloadSchema } from '@documenso/trpc/server/template-router/schema';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@ -54,13 +54,17 @@ export const TemplateCreateDialog = ({ folderId }: TemplateCreateDialogProps) =>
|
|||||||
setIsUploadingFile(true);
|
setIsUploadingFile(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await putPdfFile(file);
|
const payload = {
|
||||||
|
|
||||||
const { legacyTemplateId: id } = await createTemplate({
|
|
||||||
title: file.name,
|
title: file.name,
|
||||||
templateDocumentDataId: response.id,
|
|
||||||
folderId: folderId,
|
folderId: folderId,
|
||||||
});
|
} satisfies TCreateTemplatePayloadSchema;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const { envelopeId: id } = await createTemplate(formData);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Template document uploaded`),
|
title: _(msg`Template document uploaded`),
|
||||||
|
|||||||
@ -143,7 +143,7 @@ export function TemplateUseDialog({
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const envelopeItems = response?.envelopeItems ?? [];
|
const envelopeItems = response?.data ?? [];
|
||||||
|
|
||||||
const { mutateAsync: createDocumentFromTemplate } =
|
const { mutateAsync: createDocumentFromTemplate } =
|
||||||
trpc.template.createDocumentFromTemplate.useMutation();
|
trpc.template.createDocumentFromTemplate.useMutation();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { useLingui } from '@lingui/react';
|
|||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentData, FieldType } from '@prisma/client';
|
import type { DocumentData, FieldType } from '@prisma/client';
|
||||||
import { ReadStatus, type Recipient, SendStatus, SigningStatus } from '@prisma/client';
|
import { ReadStatus, type Recipient, SendStatus, SigningStatus } from '@prisma/client';
|
||||||
|
import { base64 } from '@scure/base';
|
||||||
import { ChevronsUpDown } from 'lucide-react';
|
import { ChevronsUpDown } from 'lucide-react';
|
||||||
import { useFieldArray, useForm } from 'react-hook-form';
|
import { useFieldArray, useForm } from 'react-hook-form';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
@ -12,7 +13,6 @@ import { getBoundingClientRect } from '@documenso/lib/client-only/get-bounding-c
|
|||||||
import { useDocumentElement } from '@documenso/lib/client-only/hooks/use-document-element';
|
import { useDocumentElement } from '@documenso/lib/client-only/hooks/use-document-element';
|
||||||
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
||||||
import { type TFieldMetaSchema, ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
import { type TFieldMetaSchema, ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||||
import { base64 } from '@documenso/lib/universal/base64';
|
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import { ADVANCED_FIELD_TYPES_WITH_OPTIONAL_SETTING } from '@documenso/lib/utils/advanced-fields-helpers';
|
import { ADVANCED_FIELD_TYPES_WITH_OPTIONAL_SETTING } from '@documenso/lib/utils/advanced-fields-helpers';
|
||||||
import { useRecipientColors } from '@documenso/ui/lib/recipient-colors';
|
import { useRecipientColors } from '@documenso/ui/lib/recipient-colors';
|
||||||
@ -83,21 +83,14 @@ export const ConfigureFieldsView = ({
|
|||||||
|
|
||||||
const normalizedDocumentData = useMemo(() => {
|
const normalizedDocumentData = useMemo(() => {
|
||||||
if (documentData) {
|
if (documentData) {
|
||||||
return documentData;
|
return documentData.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configData.documentData) {
|
if (!configData.documentData) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = base64.encode(configData.documentData?.data);
|
return base64.encode(configData.documentData.data);
|
||||||
|
|
||||||
return {
|
|
||||||
id: 'preview',
|
|
||||||
type: 'BYTES_64',
|
|
||||||
data,
|
|
||||||
initialData: data,
|
|
||||||
} satisfies DocumentData;
|
|
||||||
}, [configData.documentData]);
|
}, [configData.documentData]);
|
||||||
|
|
||||||
const recipients = useMemo(() => {
|
const recipients = useMemo(() => {
|
||||||
@ -541,7 +534,15 @@ export const ConfigureFieldsView = ({
|
|||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
{normalizedDocumentData && (
|
{normalizedDocumentData && (
|
||||||
<div>
|
<div>
|
||||||
<PDFViewer documentData={normalizedDocumentData} />
|
<PDFViewer
|
||||||
|
overrideData={normalizedDocumentData}
|
||||||
|
envelopeItem={{
|
||||||
|
id: '',
|
||||||
|
envelopeId: '',
|
||||||
|
}}
|
||||||
|
token={undefined}
|
||||||
|
version="signed"
|
||||||
|
/>
|
||||||
|
|
||||||
<ElementVisible
|
<ElementVisible
|
||||||
target={`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${highestPageNumber}"]`}
|
target={`${PDF_VIEWER_PAGE_SELECTOR}[data-page-number="${highestPageNumber}"]`}
|
||||||
|
|||||||
@ -3,8 +3,8 @@ import { useEffect, useLayoutEffect, useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentMeta, Recipient, Signature } from '@prisma/client';
|
import type { DocumentMeta, EnvelopeItem, Recipient, Signature } from '@prisma/client';
|
||||||
import { type DocumentData, type Field, FieldType } from '@prisma/client';
|
import { type Field, FieldType } from '@prisma/client';
|
||||||
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
import { useSearchParams } from 'react-router';
|
import { useSearchParams } from 'react-router';
|
||||||
@ -47,7 +47,7 @@ export type EmbedDirectTemplateClientPageProps = {
|
|||||||
token: string;
|
token: string;
|
||||||
envelopeId: string;
|
envelopeId: string;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
documentData: DocumentData;
|
envelopeItems: Pick<EnvelopeItem, 'id' | 'envelopeId'>[];
|
||||||
recipient: Recipient;
|
recipient: Recipient;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
metadata?: DocumentMeta | null;
|
metadata?: DocumentMeta | null;
|
||||||
@ -59,7 +59,7 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
token,
|
token,
|
||||||
envelopeId,
|
envelopeId,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
documentData,
|
envelopeItems,
|
||||||
recipient,
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
metadata,
|
metadata,
|
||||||
@ -335,7 +335,9 @@ export const EmbedDirectTemplateClientPage = ({
|
|||||||
{/* Viewer */}
|
{/* Viewer */}
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
documentData={documentData}
|
envelopeItem={envelopeItems[0]}
|
||||||
|
token={token}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => setHasDocumentLoaded(true)}
|
onDocumentLoad={() => setHasDocumentLoaded(true)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -3,14 +3,8 @@ import { useEffect, useId, useLayoutEffect, useMemo, useState } from 'react';
|
|||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentMeta } from '@prisma/client';
|
import type { DocumentMeta, EnvelopeItem } from '@prisma/client';
|
||||||
import {
|
import { type Field, FieldType, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
type DocumentData,
|
|
||||||
type Field,
|
|
||||||
FieldType,
|
|
||||||
RecipientRole,
|
|
||||||
SigningStatus,
|
|
||||||
} from '@prisma/client';
|
|
||||||
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
import { LucideChevronDown, LucideChevronUp } from 'lucide-react';
|
||||||
|
|
||||||
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
import { useThrottleFn } from '@documenso/lib/client-only/hooks/use-throttle-fn';
|
||||||
@ -46,11 +40,11 @@ import { EmbedDocumentCompleted } from './embed-document-completed';
|
|||||||
import { EmbedDocumentFields } from './embed-document-fields';
|
import { EmbedDocumentFields } from './embed-document-fields';
|
||||||
import { EmbedDocumentRejected } from './embed-document-rejected';
|
import { EmbedDocumentRejected } from './embed-document-rejected';
|
||||||
|
|
||||||
export type EmbedSignDocumentClientPageProps = {
|
export type EmbedSignDocumentV1ClientPageProps = {
|
||||||
token: string;
|
token: string;
|
||||||
documentId: number;
|
documentId: number;
|
||||||
envelopeId: string;
|
envelopeId: string;
|
||||||
documentData: DocumentData;
|
envelopeItems: Pick<EnvelopeItem, 'id' | 'envelopeId'>[];
|
||||||
recipient: RecipientWithFields;
|
recipient: RecipientWithFields;
|
||||||
fields: Field[];
|
fields: Field[];
|
||||||
completedFields: DocumentField[];
|
completedFields: DocumentField[];
|
||||||
@ -61,11 +55,11 @@ export type EmbedSignDocumentClientPageProps = {
|
|||||||
allRecipients?: RecipientWithFields[];
|
allRecipients?: RecipientWithFields[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EmbedSignDocumentClientPage = ({
|
export const EmbedSignDocumentV1ClientPage = ({
|
||||||
token,
|
token,
|
||||||
documentId,
|
documentId,
|
||||||
envelopeId,
|
envelopeId,
|
||||||
documentData,
|
envelopeItems,
|
||||||
recipient,
|
recipient,
|
||||||
fields,
|
fields,
|
||||||
completedFields,
|
completedFields,
|
||||||
@ -74,7 +68,7 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
hidePoweredBy = false,
|
hidePoweredBy = false,
|
||||||
allowWhitelabelling = false,
|
allowWhitelabelling = false,
|
||||||
allRecipients = [],
|
allRecipients = [],
|
||||||
}: EmbedSignDocumentClientPageProps) => {
|
}: EmbedSignDocumentV1ClientPageProps) => {
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
@ -293,7 +287,9 @@ export const EmbedSignDocumentClientPage = ({
|
|||||||
{/* Viewer */}
|
{/* Viewer */}
|
||||||
<div className="embed--DocumentViewer flex-1">
|
<div className="embed--DocumentViewer flex-1">
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
documentData={documentData}
|
envelopeItem={envelopeItems[0]}
|
||||||
|
token={token}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => setHasDocumentLoaded(true)}
|
onDocumentLoad={() => setHasDocumentLoaded(true)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -0,0 +1,232 @@
|
|||||||
|
import { useEffect, useLayoutEffect, useState } from 'react';
|
||||||
|
|
||||||
|
import { useLingui } from '@lingui/react';
|
||||||
|
|
||||||
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
|
|
||||||
|
import { ZSignDocumentEmbedDataSchema } from '~/types/embed-document-sign-schema';
|
||||||
|
import { injectCss } from '~/utils/css-vars';
|
||||||
|
|
||||||
|
import { DocumentSigningPageViewV2 } from '../general/document-signing/document-signing-page-view-v2';
|
||||||
|
import { useRequiredEnvelopeSigningContext } from '../general/document-signing/envelope-signing-provider';
|
||||||
|
import { EmbedClientLoading } from './embed-client-loading';
|
||||||
|
import { EmbedDocumentCompleted } from './embed-document-completed';
|
||||||
|
import { EmbedDocumentRejected } from './embed-document-rejected';
|
||||||
|
import { EmbedSigningProvider } from './embed-signing-context';
|
||||||
|
|
||||||
|
export type EmbedSignDocumentV2ClientPageProps = {
|
||||||
|
hidePoweredBy?: boolean;
|
||||||
|
allowWhitelabelling?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const EmbedSignDocumentV2ClientPage = ({
|
||||||
|
hidePoweredBy = false,
|
||||||
|
allowWhitelabelling = false,
|
||||||
|
}: EmbedSignDocumentV2ClientPageProps) => {
|
||||||
|
const { _ } = useLingui();
|
||||||
|
|
||||||
|
const { envelope, recipient, envelopeData, setFullName, fullName } =
|
||||||
|
useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
|
const { isCompleted, isRejected, recipientSignature } = envelopeData;
|
||||||
|
|
||||||
|
// !: Not used at the moment, may be removed in the future.
|
||||||
|
// const [hasDocumentLoaded, setHasDocumentLoaded] = useState(false);
|
||||||
|
const [hasFinishedInit, setHasFinishedInit] = useState(false);
|
||||||
|
const [allowDocumentRejection, setAllowDocumentRejection] = useState(false);
|
||||||
|
const [isNameLocked, setIsNameLocked] = useState(false);
|
||||||
|
|
||||||
|
const onDocumentCompleted = (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
}) => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'document-completed',
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDocumentError = () => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'document-error',
|
||||||
|
data: null,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDocumentReady = () => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'document-ready',
|
||||||
|
data: null,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFieldSigned = (data: { fieldId?: number; value?: string; isBase64?: boolean }) => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'field-signed',
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFieldUnsigned = (data: { fieldId?: number }) => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'field-unsigned',
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDocumentRejected = (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
reason?: string;
|
||||||
|
}) => {
|
||||||
|
if (window.parent) {
|
||||||
|
window.parent.postMessage(
|
||||||
|
{
|
||||||
|
action: 'document-rejected',
|
||||||
|
data,
|
||||||
|
},
|
||||||
|
'*',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const hash = window.location.hash.slice(1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = ZSignDocumentEmbedDataSchema.parse(JSON.parse(decodeURIComponent(atob(hash))));
|
||||||
|
|
||||||
|
if (!isCompleted && data.name) {
|
||||||
|
setFullName(data.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since a recipient can be provided a name we can lock it without requiring
|
||||||
|
// a to be provided by the parent application, unlike direct templates.
|
||||||
|
setIsNameLocked(!!data.lockName);
|
||||||
|
setAllowDocumentRejection(!!data.allowDocumentRejection);
|
||||||
|
|
||||||
|
if (data.darkModeDisabled) {
|
||||||
|
document.documentElement.classList.add('dark-mode-disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allowWhitelabelling) {
|
||||||
|
injectCss({
|
||||||
|
css: data.css,
|
||||||
|
cssVars: data.cssVars,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
setHasFinishedInit(true);
|
||||||
|
|
||||||
|
// !: While the setters are stable we still want to ensure we're avoiding
|
||||||
|
// !: re-renders.
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [allowWhitelabelling]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasFinishedInit) {
|
||||||
|
onDocumentReady();
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [hasFinishedInit]);
|
||||||
|
|
||||||
|
// Listen for document completion events from the envelope signing context
|
||||||
|
useEffect(() => {
|
||||||
|
if (isCompleted) {
|
||||||
|
onDocumentCompleted({
|
||||||
|
token: recipient.token,
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
recipientId: recipient.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isCompleted, envelope.id, recipient.id, recipient.token]);
|
||||||
|
|
||||||
|
// Listen for document rejection events
|
||||||
|
useEffect(() => {
|
||||||
|
if (isRejected) {
|
||||||
|
onDocumentRejected({
|
||||||
|
token: recipient.token,
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
recipientId: recipient.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isRejected, envelope.id, recipient.id, recipient.token]);
|
||||||
|
|
||||||
|
if (isRejected) {
|
||||||
|
return <EmbedDocumentRejected />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCompleted) {
|
||||||
|
return (
|
||||||
|
<EmbedDocumentCompleted
|
||||||
|
name={fullName}
|
||||||
|
signature={
|
||||||
|
recipientSignature
|
||||||
|
? {
|
||||||
|
id: 1,
|
||||||
|
fieldId: 1,
|
||||||
|
recipientId: recipient.id,
|
||||||
|
created: new Date(),
|
||||||
|
signatureImageAsBase64: recipientSignature.signatureImageAsBase64,
|
||||||
|
typedSignature: recipientSignature.typedSignature,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EmbedSigningProvider
|
||||||
|
isNameLocked={isNameLocked}
|
||||||
|
hidePoweredBy={hidePoweredBy}
|
||||||
|
allowDocumentRejection={allowDocumentRejection}
|
||||||
|
onDocumentCompleted={onDocumentCompleted}
|
||||||
|
onDocumentError={onDocumentError}
|
||||||
|
onDocumentRejected={onDocumentRejected}
|
||||||
|
onDocumentReady={onDocumentReady}
|
||||||
|
onFieldSigned={onFieldSigned}
|
||||||
|
onFieldUnsigned={onFieldUnsigned}
|
||||||
|
>
|
||||||
|
<div className="embed--Root relative">
|
||||||
|
{!hasFinishedInit && <EmbedClientLoading />}
|
||||||
|
|
||||||
|
<DocumentSigningPageViewV2 />
|
||||||
|
</div>
|
||||||
|
</EmbedSigningProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
101
apps/remix/app/components/embed/embed-signing-context.tsx
Normal file
101
apps/remix/app/components/embed/embed-signing-context.tsx
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import { createContext, useContext } from 'react';
|
||||||
|
|
||||||
|
export type EmbedSigningContextValue = {
|
||||||
|
isEmbed: true;
|
||||||
|
allowDocumentRejection: boolean;
|
||||||
|
isNameLocked: boolean;
|
||||||
|
isEmailLocked: boolean;
|
||||||
|
hidePoweredBy: boolean;
|
||||||
|
onDocumentCompleted: (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
}) => void;
|
||||||
|
onDocumentError: () => void;
|
||||||
|
onDocumentRejected: (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
reason?: string;
|
||||||
|
}) => void;
|
||||||
|
onDocumentReady: () => void;
|
||||||
|
onFieldSigned: (data: { fieldId?: number; value?: string; isBase64?: boolean }) => void;
|
||||||
|
onFieldUnsigned: (data: { fieldId?: number }) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmbedSigningContext = createContext<EmbedSigningContextValue | null>(null);
|
||||||
|
|
||||||
|
export const useEmbedSigningContext = () => {
|
||||||
|
return useContext(EmbedSigningContext);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useRequiredEmbedSigningContext = () => {
|
||||||
|
const context = useEmbedSigningContext();
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useRequiredEmbedSigningContext must be used within EmbedSigningProvider');
|
||||||
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EmbedSigningProviderProps = {
|
||||||
|
allowDocumentRejection?: boolean;
|
||||||
|
isNameLocked?: boolean;
|
||||||
|
isEmailLocked?: boolean;
|
||||||
|
hidePoweredBy?: boolean;
|
||||||
|
onDocumentCompleted: (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
}) => void;
|
||||||
|
onDocumentError: () => void;
|
||||||
|
onDocumentRejected: (data: {
|
||||||
|
token: string;
|
||||||
|
documentId: number;
|
||||||
|
envelopeId: string;
|
||||||
|
recipientId: number;
|
||||||
|
reason?: string;
|
||||||
|
}) => void;
|
||||||
|
onDocumentReady: () => void;
|
||||||
|
onFieldSigned: (data: { fieldId?: number; value?: string; isBase64?: boolean }) => void;
|
||||||
|
onFieldUnsigned: (data: { fieldId?: number }) => void;
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const EmbedSigningProvider = ({
|
||||||
|
allowDocumentRejection = false,
|
||||||
|
isNameLocked = false,
|
||||||
|
isEmailLocked = true,
|
||||||
|
hidePoweredBy = false,
|
||||||
|
onDocumentCompleted,
|
||||||
|
onDocumentError,
|
||||||
|
onDocumentRejected,
|
||||||
|
onDocumentReady,
|
||||||
|
onFieldSigned,
|
||||||
|
onFieldUnsigned,
|
||||||
|
children,
|
||||||
|
}: EmbedSigningProviderProps) => {
|
||||||
|
return (
|
||||||
|
<EmbedSigningContext.Provider
|
||||||
|
value={{
|
||||||
|
isEmbed: true,
|
||||||
|
allowDocumentRejection,
|
||||||
|
isNameLocked,
|
||||||
|
isEmailLocked,
|
||||||
|
hidePoweredBy,
|
||||||
|
onDocumentCompleted,
|
||||||
|
onDocumentError,
|
||||||
|
onDocumentRejected,
|
||||||
|
onDocumentReady,
|
||||||
|
onFieldSigned,
|
||||||
|
onFieldUnsigned,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</EmbedSigningContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -226,7 +226,9 @@ export const MultiSignDocumentSigningView = ({
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
documentData={document.documentData}
|
envelopeItem={document.envelopeItems[0]}
|
||||||
|
token={token}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => {
|
onDocumentLoad={() => {
|
||||||
setHasDocumentLoaded(true);
|
setHasDocumentLoaded(true);
|
||||||
onDocumentReady?.();
|
onDocumentReady?.();
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { Trans, useLingui } from '@lingui/react/macro';
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import type { TeamGlobalSettings } from '@prisma/client';
|
import type { TeamGlobalSettings } from '@prisma/client';
|
||||||
import { Loader } from 'lucide-react';
|
import { Loader } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
||||||
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
@ -29,6 +29,8 @@ import {
|
|||||||
} from '@documenso/ui/primitives/select';
|
} from '@documenso/ui/primitives/select';
|
||||||
import { Textarea } from '@documenso/ui/primitives/textarea';
|
import { Textarea } from '@documenso/ui/primitives/textarea';
|
||||||
|
|
||||||
|
import { useOptionalCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
||||||
const ACCEPTED_FILE_TYPES = ['image/jpeg', 'image/png', 'image/webp'];
|
const ACCEPTED_FILE_TYPES = ['image/jpeg', 'image/png', 'image/webp'];
|
||||||
|
|
||||||
@ -68,6 +70,9 @@ export function BrandingPreferencesForm({
|
|||||||
}: BrandingPreferencesFormProps) {
|
}: BrandingPreferencesFormProps) {
|
||||||
const { t } = useLingui();
|
const { t } = useLingui();
|
||||||
|
|
||||||
|
const team = useOptionalCurrentTeam();
|
||||||
|
const organisation = useCurrentOrganisation();
|
||||||
|
|
||||||
const [previewUrl, setPreviewUrl] = useState<string>('');
|
const [previewUrl, setPreviewUrl] = useState<string>('');
|
||||||
const [hasLoadedPreview, setHasLoadedPreview] = useState(false);
|
const [hasLoadedPreview, setHasLoadedPreview] = useState(false);
|
||||||
|
|
||||||
@ -88,14 +93,13 @@ export function BrandingPreferencesForm({
|
|||||||
const file = JSON.parse(settings.brandingLogo);
|
const file = JSON.parse(settings.brandingLogo);
|
||||||
|
|
||||||
if ('type' in file && 'data' in file) {
|
if ('type' in file && 'data' in file) {
|
||||||
void getFile(file).then((binaryData) => {
|
const logoUrl =
|
||||||
const objectUrl = URL.createObjectURL(new Blob([binaryData]));
|
context === 'Team'
|
||||||
|
? `${NEXT_PUBLIC_WEBAPP_URL()}/api/branding/logo/team/${team?.id}`
|
||||||
|
: `${NEXT_PUBLIC_WEBAPP_URL()}/api/branding/logo/organisation/${organisation?.id}`;
|
||||||
|
|
||||||
setPreviewUrl(objectUrl);
|
setPreviewUrl(logoUrl);
|
||||||
setHasLoadedPreview(true);
|
setHasLoadedPreview(true);
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -152,6 +152,18 @@ export const EditorFieldTextForm = ({
|
|||||||
className="h-auto"
|
className="h-auto"
|
||||||
placeholder={t`Add text to the field`}
|
placeholder={t`Add text to the field`}
|
||||||
{...field}
|
{...field}
|
||||||
|
onChange={(e) => {
|
||||||
|
const values = form.getValues();
|
||||||
|
const characterLimit = values.characterLimit || 0;
|
||||||
|
let textValue = e.target.value;
|
||||||
|
|
||||||
|
if (characterLimit > 0 && textValue.length > characterLimit) {
|
||||||
|
textValue = textValue.slice(0, characterLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.target.value = textValue;
|
||||||
|
field.onChange(e);
|
||||||
|
}}
|
||||||
rows={1}
|
rows={1}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
@ -175,6 +187,18 @@ export const EditorFieldTextForm = ({
|
|||||||
className="bg-background"
|
className="bg-background"
|
||||||
placeholder={t`Field character limit`}
|
placeholder={t`Field character limit`}
|
||||||
{...field}
|
{...field}
|
||||||
|
onChange={(e) => {
|
||||||
|
field.onChange(e);
|
||||||
|
|
||||||
|
const values = form.getValues();
|
||||||
|
const characterLimit = parseInt(e.target.value, 10) || 0;
|
||||||
|
|
||||||
|
const textValue = values.text || '';
|
||||||
|
|
||||||
|
if (characterLimit > 0 && textValue.length > characterLimit) {
|
||||||
|
form.setValue('text', textValue.slice(0, characterLimit));
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@ -153,7 +153,9 @@ export const DirectTemplatePageView = ({
|
|||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
key={template.id}
|
key={template.id}
|
||||||
documentData={template.templateDocumentData}
|
envelopeItem={template.envelopeItems[0]}
|
||||||
|
token={directTemplateRecipient.token}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import {
|
|||||||
} from '@documenso/ui/primitives/form/form';
|
} from '@documenso/ui/primitives/form/form';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
|
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
import { AccessAuth2FAForm } from '~/components/general/document-signing/access-auth-2fa-form';
|
import { AccessAuth2FAForm } from '~/components/general/document-signing/access-auth-2fa-form';
|
||||||
import { DocumentSigningDisclosure } from '~/components/general/document-signing/document-signing-disclosure';
|
import { DocumentSigningDisclosure } from '~/components/general/document-signing/document-signing-disclosure';
|
||||||
|
|
||||||
@ -102,6 +103,8 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
|
|
||||||
const { derivedRecipientAccessAuth } = useRequiredDocumentSigningAuthContext();
|
const { derivedRecipientAccessAuth } = useRequiredDocumentSigningAuthContext();
|
||||||
|
|
||||||
|
const { isNameLocked, isEmailLocked } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
const form = useForm<TNextSignerFormSchema>({
|
const form = useForm<TNextSignerFormSchema>({
|
||||||
resolver: allowDictateNextSigner ? zodResolver(ZNextSignerFormSchema) : undefined,
|
resolver: allowDictateNextSigner ? zodResolver(ZNextSignerFormSchema) : undefined,
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@ -267,7 +270,12 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
<Trans>Your Name</Trans>
|
<Trans>Your Name</Trans>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} className="mt-2" placeholder={t`Enter your name`} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
className="mt-2"
|
||||||
|
placeholder={t`Enter your name`}
|
||||||
|
disabled={isNameLocked}
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
@ -289,6 +297,7 @@ export const DocumentSigningCompleteDialog = ({
|
|||||||
type="email"
|
type="email"
|
||||||
className="mt-2"
|
className="mt-2"
|
||||||
placeholder={t`Enter your email`}
|
placeholder={t`Enter your email`}
|
||||||
|
disabled={!!field.value && isEmailLocked}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import { match } from 'ts-pattern';
|
|||||||
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
|
|
||||||
|
import { BrandingLogo } from '../branding-logo';
|
||||||
import EnvelopeSignerForm from '../envelope-signing/envelope-signer-form';
|
import EnvelopeSignerForm from '../envelope-signing/envelope-signer-form';
|
||||||
import { EnvelopeSignerCompleteDialog } from '../envelope-signing/envelope-signing-complete-dialog';
|
import { EnvelopeSignerCompleteDialog } from '../envelope-signing/envelope-signing-complete-dialog';
|
||||||
import { useRequiredEnvelopeSigningContext } from './envelope-signing-provider';
|
import { useRequiredEnvelopeSigningContext } from './envelope-signing-provider';
|
||||||
@ -15,6 +18,8 @@ import { useRequiredEnvelopeSigningContext } from './envelope-signing-provider';
|
|||||||
export const DocumentSigningMobileWidget = () => {
|
export const DocumentSigningMobileWidget = () => {
|
||||||
const [isExpanded, setIsExpanded] = useState(false);
|
const [isExpanded, setIsExpanded] = useState(false);
|
||||||
|
|
||||||
|
const { hidePoweredBy = true } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
const { recipientFieldsRemaining, recipient, requiredRecipientFields } =
|
const { recipientFieldsRemaining, recipient, requiredRecipientFields } =
|
||||||
useRequiredEnvelopeSigningContext();
|
useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
@ -29,7 +34,7 @@ export const DocumentSigningMobileWidget = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pointer-events-none fixed bottom-0 left-0 right-0 z-50 flex justify-center px-2 pb-2 sm:px-4 sm:pb-6">
|
<div className="pointer-events-none fixed bottom-0 left-0 right-0 z-50 flex justify-center px-2 pb-2 sm:px-4 sm:pb-6">
|
||||||
<div className="pointer-events-auto w-full max-w-2xl">
|
<div className="pointer-events-auto w-full max-w-[760px]">
|
||||||
<div className="bg-card border-border overflow-hidden rounded-xl border shadow-2xl">
|
<div className="bg-card border-border overflow-hidden rounded-xl border shadow-2xl">
|
||||||
{/* Main Header Bar */}
|
{/* Main Header Bar */}
|
||||||
<div className="flex items-center justify-between gap-4 p-4">
|
<div className="flex items-center justify-between gap-4 p-4">
|
||||||
@ -114,6 +119,13 @@ export const DocumentSigningMobileWidget = () => {
|
|||||||
{isExpanded && (
|
{isExpanded && (
|
||||||
<div className="border-border animate-in slide-in-from-bottom-2 border-t p-4 duration-200">
|
<div className="border-border animate-in slide-in-from-bottom-2 border-t p-4 duration-200">
|
||||||
<EnvelopeSignerForm />
|
<EnvelopeSignerForm />
|
||||||
|
|
||||||
|
{!hidePoweredBy && (
|
||||||
|
<div className="bg-primary text-primary-foreground mt-2 inline-block rounded px-2 py-1 text-xs font-medium opacity-60 hover:opacity-100 lg:hidden">
|
||||||
|
<span>Powered by</span>
|
||||||
|
<BrandingLogo className="ml-2 inline-block h-[14px]" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -245,7 +245,12 @@ export const DocumentSigningPageViewV1 = ({
|
|||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<Card className="rounded-xl before:rounded-xl" gradient>
|
<Card className="rounded-xl before:rounded-xl" gradient>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewer key={documentData.id} documentData={documentData} document={document} />
|
<PDFViewer
|
||||||
|
key={document.envelopeItems[0].id}
|
||||||
|
envelopeItem={document.envelopeItems[0]}
|
||||||
|
token={recipient.token}
|
||||||
|
version="signed"
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -22,7 +22,9 @@ import { SignFieldNameDialog } from '~/components/dialogs/sign-field-name-dialog
|
|||||||
import { SignFieldNumberDialog } from '~/components/dialogs/sign-field-number-dialog';
|
import { SignFieldNumberDialog } from '~/components/dialogs/sign-field-number-dialog';
|
||||||
import { SignFieldSignatureDialog } from '~/components/dialogs/sign-field-signature-dialog';
|
import { SignFieldSignatureDialog } from '~/components/dialogs/sign-field-signature-dialog';
|
||||||
import { SignFieldTextDialog } from '~/components/dialogs/sign-field-text-dialog';
|
import { SignFieldTextDialog } from '~/components/dialogs/sign-field-text-dialog';
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
|
|
||||||
|
import { BrandingLogo } from '../branding-logo';
|
||||||
import { DocumentSigningAttachmentsPopover } from '../document-signing/document-signing-attachments-popover';
|
import { DocumentSigningAttachmentsPopover } from '../document-signing/document-signing-attachments-popover';
|
||||||
import { EnvelopeItemSelector } from '../envelope-editor/envelope-file-selector';
|
import { EnvelopeItemSelector } from '../envelope-editor/envelope-file-selector';
|
||||||
import EnvelopeSignerForm from '../envelope-signing/envelope-signer-form';
|
import EnvelopeSignerForm from '../envelope-signing/envelope-signer-form';
|
||||||
@ -48,6 +50,13 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
selectedAssistantRecipientFields,
|
selectedAssistantRecipientFields,
|
||||||
} = useRequiredEnvelopeSigningContext();
|
} = useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
|
const {
|
||||||
|
isEmbed = false,
|
||||||
|
allowDocumentRejection = true,
|
||||||
|
hidePoweredBy = true,
|
||||||
|
onDocumentRejected,
|
||||||
|
} = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The total remaining fields remaining for the current recipient or selected assistant recipient.
|
* The total remaining fields remaining for the current recipient or selected assistant recipient.
|
||||||
*
|
*
|
||||||
@ -77,7 +86,7 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
{/* Main Content Area */}
|
{/* Main Content Area */}
|
||||||
<div className="flex h-[calc(100vh-4rem)] w-screen">
|
<div className="flex h-[calc(100vh-4rem)] w-screen">
|
||||||
{/* Left Section - Step Navigation */}
|
{/* Left Section - Step Navigation */}
|
||||||
<div className="bg-background border-border hidden w-80 flex-shrink-0 flex-col overflow-y-auto border-r py-4 lg:flex">
|
<div className="embed--DocumentWidgetContainer bg-background border-border hidden w-80 flex-shrink-0 flex-col overflow-y-auto border-r py-4 lg:flex">
|
||||||
<div className="px-4">
|
<div className="px-4">
|
||||||
<h3 className="text-foreground flex items-end justify-between text-sm font-semibold">
|
<h3 className="text-foreground flex items-end justify-between text-sm font-semibold">
|
||||||
{match(recipient.role)
|
{match(recipient.role)
|
||||||
@ -107,7 +116,7 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-6 space-y-3">
|
<div className="embed--DocumentWidgetContent mt-6 space-y-3">
|
||||||
<EnvelopeSignerForm />
|
<EnvelopeSignerForm />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -116,7 +125,7 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
|
|
||||||
{/* Quick Actions. */}
|
{/* Quick Actions. */}
|
||||||
{!isDirectTemplate && (
|
{!isDirectTemplate && (
|
||||||
<div className="space-y-3 px-4">
|
<div className="embed--Actions space-y-3 px-4">
|
||||||
<h4 className="text-foreground text-sm font-semibold">
|
<h4 className="text-foreground text-sm font-semibold">
|
||||||
<Trans>Actions</Trans>
|
<Trans>Actions</Trans>
|
||||||
</h4>
|
</h4>
|
||||||
@ -145,10 +154,21 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{envelope.type === EnvelopeType.DOCUMENT && (
|
{envelope.type === EnvelopeType.DOCUMENT && allowDocumentRejection && (
|
||||||
<DocumentSigningRejectDialog
|
<DocumentSigningRejectDialog
|
||||||
documentId={mapSecondaryIdToDocumentId(envelope.secondaryId)}
|
documentId={mapSecondaryIdToDocumentId(envelope.secondaryId)}
|
||||||
token={recipient.token}
|
token={recipient.token}
|
||||||
|
onRejected={
|
||||||
|
onDocumentRejected &&
|
||||||
|
((reason) =>
|
||||||
|
onDocumentRejected({
|
||||||
|
token: recipient.token,
|
||||||
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
recipientId: recipient.id,
|
||||||
|
reason,
|
||||||
|
}))
|
||||||
|
}
|
||||||
trigger={
|
trigger={
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
@ -164,7 +184,9 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="embed--DocumentWidgetFooter">
|
||||||
{/* Footer of left sidebar. */}
|
{/* Footer of left sidebar. */}
|
||||||
|
{!isEmbed && (
|
||||||
<div className="mt-auto px-4">
|
<div className="mt-auto px-4">
|
||||||
<Button asChild variant="ghost" className="w-full justify-start">
|
<Button asChild variant="ghost" className="w-full justify-start">
|
||||||
<Link to="/">
|
<Link to="/">
|
||||||
@ -173,9 +195,11 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 overflow-y-auto">
|
<div className="embed--DocumentContainer flex-1 overflow-y-auto">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
{/* Horizontal envelope item selector */}
|
{/* Horizontal envelope item selector */}
|
||||||
{envelopeItems.length > 1 && (
|
{envelopeItems.length > 1 && (
|
||||||
@ -202,11 +226,11 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Document View */}
|
{/* Document View */}
|
||||||
<div className="flex flex-col items-center justify-center p-2 sm:mt-4 sm:p-4">
|
<div className="embed--DocumentViewer flex flex-col items-center justify-center p-2 sm:mt-4 sm:p-4">
|
||||||
{currentEnvelopeItem ? (
|
{currentEnvelopeItem ? (
|
||||||
<PDFViewerKonvaLazy
|
<PDFViewerKonvaLazy
|
||||||
|
renderer="signing"
|
||||||
key={currentEnvelopeItem.id}
|
key={currentEnvelopeItem.id}
|
||||||
documentDataId={currentEnvelopeItem.documentDataId}
|
|
||||||
customPageRenderer={EnvelopeSignerPageRenderer}
|
customPageRenderer={EnvelopeSignerPageRenderer}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@ -218,9 +242,20 @@ export const DocumentSigningPageViewV2 = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Mobile widget - Additional padding to allow users to scroll */}
|
{/* Mobile widget - Additional padding to allow users to scroll */}
|
||||||
<div className="block pb-16 md:hidden">
|
<div className="block pb-28 lg:hidden">
|
||||||
<DocumentSigningMobileWidget />
|
<DocumentSigningMobileWidget />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{!hidePoweredBy && (
|
||||||
|
<a
|
||||||
|
href="https://documenso.com"
|
||||||
|
target="_blank"
|
||||||
|
className="bg-primary text-primary-foreground fixed bottom-0 right-0 z-40 hidden cursor-pointer rounded-tl px-2 py-1 text-xs font-medium opacity-60 hover:opacity-100 lg:block"
|
||||||
|
>
|
||||||
|
<span>Powered by</span>
|
||||||
|
<BrandingLogo className="ml-2 inline-block h-[14px]" />
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import { prop, sortBy } from 'remeda';
|
|||||||
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
||||||
import { DO_NOT_INVALIDATE_QUERY_ON_MUTATION } from '@documenso/lib/constants/trpc';
|
import { DO_NOT_INVALIDATE_QUERY_ON_MUTATION } from '@documenso/lib/constants/trpc';
|
||||||
import type { EnvelopeForSigningResponse } from '@documenso/lib/server-only/envelope/get-envelope-for-recipient-signing';
|
import type { EnvelopeForSigningResponse } from '@documenso/lib/server-only/envelope/get-envelope-for-recipient-signing';
|
||||||
|
import type { TRecipientActionAuth } from '@documenso/lib/types/document-auth';
|
||||||
import {
|
import {
|
||||||
isFieldUnsignedAndRequired,
|
isFieldUnsignedAndRequired,
|
||||||
isRequiredField,
|
isRequiredField,
|
||||||
@ -51,7 +52,11 @@ export type EnvelopeSigningContextValue = {
|
|||||||
setSelectedAssistantRecipientId: (_value: number | null) => void;
|
setSelectedAssistantRecipientId: (_value: number | null) => void;
|
||||||
selectedAssistantRecipient: EnvelopeForSigningResponse['envelope']['recipients'][number] | null;
|
selectedAssistantRecipient: EnvelopeForSigningResponse['envelope']['recipients'][number] | null;
|
||||||
|
|
||||||
signField: (_fieldId: number, _value: TSignEnvelopeFieldValue) => Promise<void>;
|
signField: (
|
||||||
|
_fieldId: number,
|
||||||
|
_value: TSignEnvelopeFieldValue,
|
||||||
|
authOptions?: TRecipientActionAuth,
|
||||||
|
) => Promise<Pick<Field, 'id' | 'inserted'>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const EnvelopeSigningContext = createContext<EnvelopeSigningContextValue | null>(null);
|
const EnvelopeSigningContext = createContext<EnvelopeSigningContextValue | null>(null);
|
||||||
@ -284,19 +289,26 @@ export const EnvelopeSigningProvider = ({
|
|||||||
: null;
|
: null;
|
||||||
}, [envelope.documentMeta?.signingOrder, envelope.recipients, recipient.id]);
|
}, [envelope.documentMeta?.signingOrder, envelope.recipients, recipient.id]);
|
||||||
|
|
||||||
const signField = async (fieldId: number, fieldValue: TSignEnvelopeFieldValue) => {
|
const signField = async (
|
||||||
|
fieldId: number,
|
||||||
|
fieldValue: TSignEnvelopeFieldValue,
|
||||||
|
authOptions?: TRecipientActionAuth,
|
||||||
|
) => {
|
||||||
// Set the field locally for direct templates.
|
// Set the field locally for direct templates.
|
||||||
if (isDirectTemplate) {
|
if (isDirectTemplate) {
|
||||||
handleDirectTemplateFieldInsertion(fieldId, fieldValue);
|
const signedField = handleDirectTemplateFieldInsertion(fieldId, fieldValue);
|
||||||
return;
|
|
||||||
|
return signedField;
|
||||||
}
|
}
|
||||||
|
|
||||||
await signEnvelopeField({
|
const { signedField } = await signEnvelopeField({
|
||||||
token: envelopeData.recipient.token,
|
token: envelopeData.recipient.token,
|
||||||
fieldId,
|
fieldId,
|
||||||
fieldValue,
|
fieldValue,
|
||||||
authOptions: undefined,
|
authOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return signedField;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDirectTemplateFieldInsertion = (
|
const handleDirectTemplateFieldInsertion = (
|
||||||
@ -354,6 +366,8 @@ export const EnvelopeSigningProvider = ({
|
|||||||
fields: prev.recipient.fields.map((field) => (field.id === fieldId ? updatedField : field)),
|
fields: prev.recipient.fields.map((field) => (field.id === fieldId ? updatedField : field)),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
return updatedField;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import type { DocumentData, EnvelopeItem } from '@prisma/client';
|
import { type DocumentData, DocumentStatus, type EnvelopeItem } from '@prisma/client';
|
||||||
|
import { DownloadIcon } from 'lucide-react';
|
||||||
import { DateTime } from 'luxon';
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -22,9 +23,10 @@ import {
|
|||||||
} from '@documenso/ui/primitives/dialog';
|
} from '@documenso/ui/primitives/dialog';
|
||||||
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
import { PDFViewer } from '@documenso/ui/primitives/pdf-viewer';
|
||||||
|
|
||||||
|
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
||||||
|
|
||||||
import { EnvelopeRendererFileSelector } from '../envelope-editor/envelope-file-selector';
|
import { EnvelopeRendererFileSelector } from '../envelope-editor/envelope-file-selector';
|
||||||
import EnvelopeGenericPageRenderer from '../envelope-editor/envelope-generic-page-renderer';
|
import EnvelopeGenericPageRenderer from '../envelope-editor/envelope-generic-page-renderer';
|
||||||
import { ShareDocumentDownloadButton } from '../share-document-download-button';
|
|
||||||
|
|
||||||
export type DocumentCertificateQRViewProps = {
|
export type DocumentCertificateQRViewProps = {
|
||||||
documentId: number;
|
documentId: number;
|
||||||
@ -34,6 +36,7 @@ export type DocumentCertificateQRViewProps = {
|
|||||||
documentTeamUrl: string;
|
documentTeamUrl: string;
|
||||||
recipientCount?: number;
|
recipientCount?: number;
|
||||||
completedDate?: Date;
|
completedDate?: Date;
|
||||||
|
token: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DocumentCertificateQRView = ({
|
export const DocumentCertificateQRView = ({
|
||||||
@ -44,6 +47,7 @@ export const DocumentCertificateQRView = ({
|
|||||||
documentTeamUrl,
|
documentTeamUrl,
|
||||||
recipientCount = 0,
|
recipientCount = 0,
|
||||||
completedDate,
|
completedDate,
|
||||||
|
token,
|
||||||
}: DocumentCertificateQRViewProps) => {
|
}: DocumentCertificateQRViewProps) => {
|
||||||
const { data: documentViaUser } = trpc.document.get.useQuery({
|
const { data: documentViaUser } = trpc.document.get.useQuery({
|
||||||
documentId,
|
documentId,
|
||||||
@ -96,11 +100,12 @@ export const DocumentCertificateQRView = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{internalVersion === 2 ? (
|
{internalVersion === 2 ? (
|
||||||
<EnvelopeRenderProvider envelope={{ envelopeItems }}>
|
<EnvelopeRenderProvider envelope={{ envelopeItems }} token={token}>
|
||||||
<DocumentCertificateQrV2
|
<DocumentCertificateQrV2
|
||||||
title={title}
|
title={title}
|
||||||
recipientCount={recipientCount}
|
recipientCount={recipientCount}
|
||||||
formattedDate={formattedDate}
|
formattedDate={formattedDate}
|
||||||
|
token={token}
|
||||||
/>
|
/>
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
) : (
|
) : (
|
||||||
@ -119,14 +124,27 @@ export const DocumentCertificateQRView = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ShareDocumentDownloadButton
|
<EnvelopeDownloadDialog
|
||||||
title={title}
|
envelopeId={envelopeItems[0].envelopeId}
|
||||||
documentData={envelopeItems[0].documentData}
|
envelopeStatus={DocumentStatus.COMPLETED}
|
||||||
|
envelopeItems={envelopeItems}
|
||||||
|
token={token}
|
||||||
|
trigger={
|
||||||
|
<Button type="button" variant="outline" className="flex-1">
|
||||||
|
<DownloadIcon className="mr-2 h-5 w-5" />
|
||||||
|
<Trans>Download</Trans>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-12 w-full">
|
<div className="mt-12 w-full">
|
||||||
<PDFViewer key={envelopeItems[0].id} documentData={envelopeItems[0].documentData} />
|
<PDFViewer
|
||||||
|
key={envelopeItems[0].id}
|
||||||
|
envelopeItem={envelopeItems[0]}
|
||||||
|
token={token}
|
||||||
|
version="signed"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@ -138,14 +156,16 @@ type DocumentCertificateQrV2Props = {
|
|||||||
title: string;
|
title: string;
|
||||||
recipientCount: number;
|
recipientCount: number;
|
||||||
formattedDate: string;
|
formattedDate: string;
|
||||||
|
token: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DocumentCertificateQrV2 = ({
|
const DocumentCertificateQrV2 = ({
|
||||||
title,
|
title,
|
||||||
recipientCount,
|
recipientCount,
|
||||||
formattedDate,
|
formattedDate,
|
||||||
|
token,
|
||||||
}: DocumentCertificateQrV2Props) => {
|
}: DocumentCertificateQrV2Props) => {
|
||||||
const { currentEnvelopeItem } = useCurrentEnvelopeRender();
|
const { currentEnvelopeItem, envelopeItems } = useCurrentEnvelopeRender();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen flex-col items-start">
|
<div className="flex min-h-screen flex-col items-start">
|
||||||
@ -163,18 +183,24 @@ const DocumentCertificateQrV2 = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{currentEnvelopeItem && (
|
<EnvelopeDownloadDialog
|
||||||
<ShareDocumentDownloadButton
|
envelopeId={envelopeItems[0].envelopeId}
|
||||||
title={title}
|
envelopeStatus={DocumentStatus.COMPLETED}
|
||||||
documentData={currentEnvelopeItem.documentData}
|
envelopeItems={envelopeItems}
|
||||||
|
token={token}
|
||||||
|
trigger={
|
||||||
|
<Button type="button" variant="outline" className="flex-1">
|
||||||
|
<DownloadIcon className="mr-2 h-5 w-5" />
|
||||||
|
<Trans>Download</Trans>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-12 w-full">
|
<div className="mt-12 w-full">
|
||||||
<EnvelopeRendererFileSelector className="mb-4 p-0" fields={[]} secondaryOverride={''} />
|
<EnvelopeRendererFileSelector className="mb-4 p-0" fields={[]} secondaryOverride={''} />
|
||||||
|
|
||||||
<PDFViewerKonvaLazy customPageRenderer={EnvelopeGenericPageRenderer} />
|
<PDFViewerKonvaLazy renderer="preview" customPageRenderer={EnvelopeGenericPageRenderer} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -16,9 +16,9 @@ import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT, IS_BILLING_ENABLED } from '@documenso/l
|
|||||||
import { DEFAULT_DOCUMENT_TIME_ZONE, TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
import { DEFAULT_DOCUMENT_TIME_ZONE, TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions';
|
import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateDocumentPayloadSchema } from '@documenso/trpc/server/document-router/create-document.types';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
@ -62,14 +62,18 @@ export const DocumentDropZoneWrapper = ({ children, className }: DocumentDropZon
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const response = await putPdfFile(file);
|
const payload = {
|
||||||
|
|
||||||
const { legacyDocumentId: id } = await createDocument({
|
|
||||||
title: file.name,
|
title: file.name,
|
||||||
documentDataId: response.id,
|
timezone: userTimezone,
|
||||||
timezone: userTimezone, // Note: When migrating to v2 document upload remember to pass this through as a 'userTimezone' field.
|
|
||||||
folderId: folderId ?? undefined,
|
folderId: folderId ?? undefined,
|
||||||
});
|
} satisfies TCreateDocumentPayloadSchema;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const { envelopeId: id } = await createDocument(formData);
|
||||||
|
|
||||||
void refreshLimits();
|
void refreshLimits();
|
||||||
|
|
||||||
|
|||||||
@ -441,9 +441,10 @@ export const DocumentEditForm = ({
|
|||||||
>
|
>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
key={document.documentData.id}
|
key={document.envelopeItems[0].id}
|
||||||
documentData={document.documentData}
|
envelopeItem={document.envelopeItems[0]}
|
||||||
document={document}
|
token={undefined}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@ -1,18 +1,14 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
import { CheckCircle, Download, EyeIcon, Pencil } from 'lucide-react';
|
import { CheckCircle, Download, EyeIcon, Pencil } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
||||||
|
|
||||||
@ -23,9 +19,6 @@ export type DocumentPageViewButtonProps = {
|
|||||||
export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps) => {
|
export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps) => {
|
||||||
const { user } = useSession();
|
const { user } = useSession();
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const recipient = envelope.recipients.find((recipient) => recipient.email === user.email);
|
const recipient = envelope.recipients.find((recipient) => recipient.email === user.email);
|
||||||
|
|
||||||
const isRecipient = !!recipient;
|
const isRecipient = !!recipient;
|
||||||
@ -37,25 +30,6 @@ export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps
|
|||||||
const documentsPath = formatDocumentsPath(envelope.team.url);
|
const documentsPath = formatDocumentsPath(envelope.team.url);
|
||||||
const formatPath = `${documentsPath}/${envelope.id}/edit`;
|
const formatPath = `${documentsPath}/${envelope.id}/edit`;
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
// Todo; Envelopes - Support multiple items
|
|
||||||
const envelopeItem = envelope.envelopeItems[0];
|
|
||||||
|
|
||||||
if (!envelopeItem.documentData) {
|
|
||||||
throw new Error('No document available');
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData: envelopeItem.documentData, fileName: envelopeItem.title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return match({
|
return match({
|
||||||
isRecipient,
|
isRecipient,
|
||||||
isPending,
|
isPending,
|
||||||
@ -95,7 +69,7 @@ export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps
|
|||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
))
|
))
|
||||||
.with({ isComplete: true, internalVersion: 2 }, () => (
|
.with({ isComplete: true }, () => (
|
||||||
<EnvelopeDownloadDialog
|
<EnvelopeDownloadDialog
|
||||||
envelopeId={envelope.id}
|
envelopeId={envelope.id}
|
||||||
envelopeStatus={envelope.status}
|
envelopeStatus={envelope.status}
|
||||||
@ -109,11 +83,5 @@ export const DocumentPageViewButton = ({ envelope }: DocumentPageViewButtonProps
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.with({ isComplete: true }, () => (
|
|
||||||
<Button className="w-full" onClick={onDownloadClick}>
|
|
||||||
<Download className="-ml-1 mr-2 inline h-4 w-4" />
|
|
||||||
<Trans>Download</Trans>
|
|
||||||
</Button>
|
|
||||||
))
|
|
||||||
.otherwise(() => null);
|
.otherwise(() => null);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus } from '@prisma/client';
|
import { DocumentStatus } from '@prisma/client';
|
||||||
@ -16,13 +15,11 @@ import {
|
|||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { Link, useNavigate } from 'react-router';
|
import { Link, useNavigate } from 'react-router';
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@ -67,64 +64,6 @@ export const DocumentPageViewDropdown = ({ envelope }: DocumentPageViewDropdownP
|
|||||||
|
|
||||||
const documentsPath = formatDocumentsPath(team.url);
|
const documentsPath = formatDocumentsPath(team.url);
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
const documentWithData = await trpcClient.document.get.query(
|
|
||||||
{
|
|
||||||
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
teamId: team?.id?.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const documentData = documentWithData?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: envelope.title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDownloadOriginalClick = async () => {
|
|
||||||
try {
|
|
||||||
const documentWithData = await trpcClient.document.get.query(
|
|
||||||
{
|
|
||||||
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
teamId: team?.id?.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const documentData = documentWithData?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: envelope.title, version: 'original' });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nonSignedRecipients = envelope.recipients.filter((item) => item.signingStatus !== 'SIGNED');
|
const nonSignedRecipients = envelope.recipients.filter((item) => item.signingStatus !== 'SIGNED');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -147,7 +86,6 @@ export const DocumentPageViewDropdown = ({ envelope }: DocumentPageViewDropdownP
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{envelope.internalVersion === 2 ? (
|
|
||||||
<EnvelopeDownloadDialog
|
<EnvelopeDownloadDialog
|
||||||
envelopeId={envelope.id}
|
envelopeId={envelope.id}
|
||||||
envelopeStatus={envelope.status}
|
envelopeStatus={envelope.status}
|
||||||
@ -162,21 +100,6 @@ export const DocumentPageViewDropdown = ({ envelope }: DocumentPageViewDropdownP
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{isComplete && (
|
|
||||||
<DropdownMenuItem onClick={onDownloadClick}>
|
|
||||||
<Download className="mr-2 h-4 w-4" />
|
|
||||||
<Trans>Download</Trans>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<DropdownMenuItem onClick={onDownloadOriginalClick}>
|
|
||||||
<Download className="mr-2 h-4 w-4" />
|
|
||||||
<Trans>Download Original</Trans>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<DropdownMenuItem asChild>
|
<DropdownMenuItem asChild>
|
||||||
<Link to={`${documentsPath}/${envelope.id}/logs`}>
|
<Link to={`${documentsPath}/${envelope.id}/logs`}>
|
||||||
@ -250,7 +173,8 @@ export const DocumentPageViewDropdown = ({ envelope }: DocumentPageViewDropdownP
|
|||||||
|
|
||||||
{isDuplicateDialogOpen && (
|
{isDuplicateDialogOpen && (
|
||||||
<DocumentDuplicateDialog
|
<DocumentDuplicateDialog
|
||||||
id={mapSecondaryIdToDocumentId(envelope.secondaryId)}
|
id={envelope.id}
|
||||||
|
token={recipient?.token}
|
||||||
open={isDuplicateDialogOpen}
|
open={isDuplicateDialogOpen}
|
||||||
onOpenChange={setDuplicateDialogOpen}
|
onOpenChange={setDuplicateDialogOpen}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -13,9 +13,9 @@ import { useSession } from '@documenso/lib/client-only/providers/session';
|
|||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
import { DEFAULT_DOCUMENT_TIME_ZONE, TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
import { DEFAULT_DOCUMENT_TIME_ZONE, TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateDocumentPayloadSchema } from '@documenso/trpc/server/document-router/create-document.types';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { DocumentDropzone } from '@documenso/ui/primitives/document-upload';
|
import { DocumentDropzone } from '@documenso/ui/primitives/document-upload';
|
||||||
import {
|
import {
|
||||||
@ -73,14 +73,18 @@ export const DocumentUploadButton = ({ className }: DocumentUploadButtonProps) =
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const response = await putPdfFile(file);
|
const payload = {
|
||||||
|
|
||||||
const { legacyDocumentId: id } = await createDocument({
|
|
||||||
title: file.name,
|
title: file.name,
|
||||||
documentDataId: response.id,
|
|
||||||
timezone: userTimezone,
|
timezone: userTimezone,
|
||||||
folderId: folderId ?? undefined,
|
folderId: folderId ?? undefined,
|
||||||
});
|
} satisfies TCreateDocumentPayloadSchema;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const { envelopeId: id } = await createDocument(formData);
|
||||||
|
|
||||||
void refreshLimits();
|
void refreshLimits();
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,9 @@ import { useSession } from '@documenso/lib/client-only/providers/session';
|
|||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
import { TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
import { TIME_ZONES } from '@documenso/lib/constants/time-zones';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath, formatTemplatesPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateEnvelopePayload } from '@documenso/trpc/server/envelope-router/create-envelope.types';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { DocumentDropzone } from '@documenso/ui/primitives/document-upload';
|
import { DocumentDropzone } from '@documenso/ui/primitives/document-upload';
|
||||||
import {
|
import {
|
||||||
@ -78,35 +78,24 @@ export const EnvelopeUploadButton = ({ className, type, folderId }: EnvelopeUplo
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const result = await Promise.all(
|
const payload = {
|
||||||
files.map(async (file) => {
|
|
||||||
try {
|
|
||||||
const response = await putPdfFile(file);
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: file.name,
|
|
||||||
documentDataId: response.id,
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
throw new Error('Failed to upload document');
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const envelopeItemsToCreate = result.filter(
|
|
||||||
(item): item is { title: string; documentDataId: string } => item !== undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { id } = await createEnvelope({
|
|
||||||
folderId,
|
folderId,
|
||||||
type,
|
type,
|
||||||
title: files[0].name,
|
title: files[0].name,
|
||||||
items: envelopeItemsToCreate,
|
|
||||||
meta: {
|
meta: {
|
||||||
timezone: userTimezone,
|
timezone: userTimezone,
|
||||||
},
|
},
|
||||||
}).catch((error) => {
|
} satisfies TCreateEnvelopePayload;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
formData.append('files', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = await createEnvelope(formData).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import { fieldButtonList } from './envelope-editor-fields-drag-drop';
|
|||||||
export default function EnvelopeEditorFieldsPageRenderer() {
|
export default function EnvelopeEditorFieldsPageRenderer() {
|
||||||
const { t, i18n } = useLingui();
|
const { t, i18n } = useLingui();
|
||||||
const { envelope, editorFields, getRecipientColorKey } = useCurrentEnvelopeEditor();
|
const { envelope, editorFields, getRecipientColorKey } = useCurrentEnvelopeEditor();
|
||||||
const { currentEnvelopeItem } = useCurrentEnvelopeRender();
|
const { currentEnvelopeItem, setRenderError } = useCurrentEnvelopeRender();
|
||||||
|
|
||||||
const interactiveTransformer = useRef<Transformer | null>(null);
|
const interactiveTransformer = useRef<Transformer | null>(null);
|
||||||
|
|
||||||
@ -103,7 +103,6 @@ export default function EnvelopeEditorFieldsPageRenderer() {
|
|||||||
fieldUpdates.height = fieldPageHeight;
|
fieldUpdates.height = fieldPageHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Todo: envelopes Use id
|
|
||||||
editorFields.updateFieldByFormId(fieldFormId, fieldUpdates);
|
editorFields.updateFieldByFormId(fieldFormId, fieldUpdates);
|
||||||
|
|
||||||
// Select the field if it is not already selected.
|
// Select the field if it is not already selected.
|
||||||
@ -114,7 +113,7 @@ export default function EnvelopeEditorFieldsPageRenderer() {
|
|||||||
pageLayer.current?.batchDraw();
|
pageLayer.current?.batchDraw();
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderFieldOnLayer = (field: TLocalField) => {
|
const unsafeRenderFieldOnLayer = (field: TLocalField) => {
|
||||||
if (!pageLayer.current) {
|
if (!pageLayer.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -160,6 +159,15 @@ export default function EnvelopeEditorFieldsPageRenderer() {
|
|||||||
fieldGroup.on('dragend', handleResizeOrMove);
|
fieldGroup.on('dragend', handleResizeOrMove);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderFieldOnLayer = (field: TLocalField) => {
|
||||||
|
try {
|
||||||
|
unsafeRenderFieldOnLayer(field);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
setRenderError(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the Konva page canvas and all fields and interactions.
|
* Initialize the Konva page canvas and all fields and interactions.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,7 +27,8 @@ import type {
|
|||||||
import { canRecipientFieldsBeModified } from '@documenso/lib/utils/recipients';
|
import { canRecipientFieldsBeModified } from '@documenso/lib/utils/recipients';
|
||||||
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
||||||
import PDFViewerKonvaLazy from '@documenso/ui/components/pdf-viewer/pdf-viewer-konva-lazy';
|
import PDFViewerKonvaLazy from '@documenso/ui/components/pdf-viewer/pdf-viewer-konva-lazy';
|
||||||
import { Alert, AlertDescription } from '@documenso/ui/primitives/alert';
|
import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert';
|
||||||
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { RecipientSelector } from '@documenso/ui/primitives/recipient-selector';
|
import { RecipientSelector } from '@documenso/ui/primitives/recipient-selector';
|
||||||
import { Separator } from '@documenso/ui/primitives/separator';
|
import { Separator } from '@documenso/ui/primitives/separator';
|
||||||
|
|
||||||
@ -112,9 +113,34 @@ export const EnvelopeEditorFieldsPage = () => {
|
|||||||
<EnvelopeRendererFileSelector fields={editorFields.localFields} />
|
<EnvelopeRendererFileSelector fields={editorFields.localFields} />
|
||||||
|
|
||||||
{/* Document View */}
|
{/* Document View */}
|
||||||
<div className="mt-4 flex h-full justify-center p-4">
|
<div className="mt-4 flex flex-col items-center justify-center">
|
||||||
|
{envelope.recipients.length === 0 && (
|
||||||
|
<Alert
|
||||||
|
variant="neutral"
|
||||||
|
className="border-border bg-background mb-4 flex max-w-[800px] flex-row items-center justify-between space-y-0 rounded-sm border"
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<AlertTitle>
|
||||||
|
<Trans>Missing Recipients</Trans>
|
||||||
|
</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
<Trans>You need at least one recipient to add fields</Trans>
|
||||||
|
</AlertDescription>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button asChild variant="outline">
|
||||||
|
<Link to={`${relativePath.editorPath}`}>
|
||||||
|
<Trans>Add Recipients</Trans>
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
{currentEnvelopeItem !== null ? (
|
{currentEnvelopeItem !== null ? (
|
||||||
<PDFViewerKonvaLazy customPageRenderer={EnvelopeEditorFieldsPageRenderer} />
|
<PDFViewerKonvaLazy
|
||||||
|
renderer="editor"
|
||||||
|
customPageRenderer={EnvelopeEditorFieldsPageRenderer}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col items-center justify-center py-32">
|
<div className="flex flex-col items-center justify-center py-32">
|
||||||
<FileTextIcon className="text-muted-foreground h-10 w-10" />
|
<FileTextIcon className="text-muted-foreground h-10 w-10" />
|
||||||
@ -130,7 +156,7 @@ export const EnvelopeEditorFieldsPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right Section - Form Fields Panel */}
|
{/* Right Section - Form Fields Panel */}
|
||||||
{currentEnvelopeItem && (
|
{currentEnvelopeItem && envelope.recipients.length > 0 && (
|
||||||
<div className="bg-background border-border sticky top-0 h-full w-80 flex-shrink-0 overflow-y-auto border-l py-4">
|
<div className="bg-background border-border sticky top-0 h-full w-80 flex-shrink-0 overflow-y-auto border-l py-4">
|
||||||
{/* Recipient selector section. */}
|
{/* Recipient selector section. */}
|
||||||
<section className="px-4">
|
<section className="px-4">
|
||||||
@ -138,19 +164,6 @@ export const EnvelopeEditorFieldsPage = () => {
|
|||||||
<Trans>Selected Recipient</Trans>
|
<Trans>Selected Recipient</Trans>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
{envelope.recipients.length === 0 ? (
|
|
||||||
<Alert variant="warning">
|
|
||||||
<AlertDescription className="flex flex-col gap-2">
|
|
||||||
<Trans>You need at least one recipient to add fields</Trans>
|
|
||||||
|
|
||||||
<Link to={`${relativePath.editorPath}`} className="text-sm">
|
|
||||||
<p>
|
|
||||||
<Trans>Click here to add a recipient</Trans>
|
|
||||||
</p>
|
|
||||||
</Link>
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
) : (
|
|
||||||
<RecipientSelector
|
<RecipientSelector
|
||||||
selectedRecipient={editorFields.selectedRecipient}
|
selectedRecipient={editorFields.selectedRecipient}
|
||||||
onSelectedRecipientChange={(recipient) =>
|
onSelectedRecipientChange={(recipient) =>
|
||||||
@ -160,7 +173,6 @@ export const EnvelopeEditorFieldsPage = () => {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
align="end"
|
align="end"
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
|
|
||||||
{editorFields.selectedRecipient &&
|
{editorFields.selectedRecipient &&
|
||||||
!canRecipientFieldsBeModified(editorFields.selectedRecipient, envelope.fields) && (
|
!canRecipientFieldsBeModified(editorFields.selectedRecipient, envelope.fields) && (
|
||||||
|
|||||||
@ -1,10 +1,20 @@
|
|||||||
import { lazy, useEffect, useState } from 'react';
|
import { lazy, useEffect, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
import { faker } from '@faker-js/faker/locale/en';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { ConstructionIcon, FileTextIcon } from 'lucide-react';
|
import { FieldType } from '@prisma/client';
|
||||||
|
import { FileTextIcon } from 'lucide-react';
|
||||||
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { useCurrentEnvelopeEditor } from '@documenso/lib/client-only/providers/envelope-editor-provider';
|
import { useCurrentEnvelopeEditor } from '@documenso/lib/client-only/providers/envelope-editor-provider';
|
||||||
import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
import {
|
||||||
|
EnvelopeRenderProvider,
|
||||||
|
useCurrentEnvelopeRender,
|
||||||
|
} from '@documenso/lib/client-only/providers/envelope-render-provider';
|
||||||
|
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
||||||
|
import { extractFieldInsertionValues } from '@documenso/lib/utils/envelope-signing';
|
||||||
|
import { toCheckboxCustomText } from '@documenso/lib/utils/fields';
|
||||||
|
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
||||||
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
import { AnimateGenericFadeInOut } from '@documenso/ui/components/animate/animate-generic-fade-in-out';
|
||||||
import PDFViewerKonvaLazy from '@documenso/ui/components/pdf-viewer/pdf-viewer-konva-lazy';
|
import PDFViewerKonvaLazy from '@documenso/ui/components/pdf-viewer/pdf-viewer-konva-lazy';
|
||||||
import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert';
|
import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert';
|
||||||
@ -15,15 +25,169 @@ import { EnvelopeRendererFileSelector } from './envelope-file-selector';
|
|||||||
|
|
||||||
const EnvelopeGenericPageRenderer = lazy(async () => import('./envelope-generic-page-renderer'));
|
const EnvelopeGenericPageRenderer = lazy(async () => import('./envelope-generic-page-renderer'));
|
||||||
|
|
||||||
|
// Todo: Envelopes - Dynamically import faker
|
||||||
export const EnvelopeEditorPreviewPage = () => {
|
export const EnvelopeEditorPreviewPage = () => {
|
||||||
const { envelope, editorFields } = useCurrentEnvelopeEditor();
|
const { envelope, editorFields } = useCurrentEnvelopeEditor();
|
||||||
|
|
||||||
const { currentEnvelopeItem } = useCurrentEnvelopeRender();
|
const { currentEnvelopeItem, fields } = useCurrentEnvelopeRender();
|
||||||
|
|
||||||
const [selectedPreviewMode, setSelectedPreviewMode] = useState<'recipient' | 'signed'>(
|
const [selectedPreviewMode, setSelectedPreviewMode] = useState<'recipient' | 'signed'>(
|
||||||
'recipient',
|
'recipient',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const fieldsWithPlaceholders = useMemo(() => {
|
||||||
|
return fields.map((field) => {
|
||||||
|
const fieldMeta = ZFieldAndMetaSchema.parse(field);
|
||||||
|
|
||||||
|
const recipient = envelope.recipients.find((recipient) => recipient.id === field.recipientId);
|
||||||
|
|
||||||
|
if (!recipient) {
|
||||||
|
throw new Error('Recipient not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
faker.seed(recipient.id);
|
||||||
|
|
||||||
|
const recipientName = recipient.name || faker.person.fullName();
|
||||||
|
const recipientEmail = recipient.email || faker.internet.email();
|
||||||
|
|
||||||
|
faker.seed(recipient.id + field.id);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...field,
|
||||||
|
inserted: true,
|
||||||
|
...match(fieldMeta)
|
||||||
|
.with({ type: FieldType.TEXT }, ({ fieldMeta }) => {
|
||||||
|
let text = fieldMeta?.text || faker.lorem.words(5);
|
||||||
|
|
||||||
|
if (fieldMeta?.characterLimit) {
|
||||||
|
text = text.slice(0, fieldMeta?.characterLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText: text,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.NUMBER }, ({ fieldMeta }) => {
|
||||||
|
let number = fieldMeta?.value ?? '';
|
||||||
|
|
||||||
|
if (number === '') {
|
||||||
|
number = faker.number
|
||||||
|
.int({
|
||||||
|
min: fieldMeta?.minValue ?? 0,
|
||||||
|
max: fieldMeta?.maxValue ?? 1000,
|
||||||
|
})
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText: number,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.DATE }, () => {
|
||||||
|
const date = extractFieldInsertionValues({
|
||||||
|
fieldValue: {
|
||||||
|
type: FieldType.DATE,
|
||||||
|
value: true,
|
||||||
|
},
|
||||||
|
field,
|
||||||
|
documentMeta: envelope.documentMeta,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText: date.customText,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.EMAIL }, () => {
|
||||||
|
return {
|
||||||
|
customText: recipientEmail,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.NAME }, () => {
|
||||||
|
return {
|
||||||
|
customText: recipientName,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.INITIALS }, () => {
|
||||||
|
return {
|
||||||
|
customText: extractInitials(recipientName),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.RADIO }, ({ fieldMeta }) => {
|
||||||
|
const values = fieldMeta?.values ?? [];
|
||||||
|
|
||||||
|
if (values.length === 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
let customText = '';
|
||||||
|
|
||||||
|
const preselectedValue = values.findIndex((value) => value.checked);
|
||||||
|
|
||||||
|
if (preselectedValue !== -1) {
|
||||||
|
customText = preselectedValue.toString();
|
||||||
|
} else {
|
||||||
|
const randomIndex = faker.number.int({ min: 0, max: values.length - 1 });
|
||||||
|
customText = randomIndex.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.CHECKBOX }, ({ fieldMeta }) => {
|
||||||
|
let checkedValues: number[] = [];
|
||||||
|
|
||||||
|
const values = fieldMeta?.values ?? [];
|
||||||
|
|
||||||
|
values.forEach((value, index) => {
|
||||||
|
if (value.checked) {
|
||||||
|
checkedValues.push(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkedValues.length === 0 && values.length > 0) {
|
||||||
|
const numberOfValues = fieldMeta?.validationLength || 1;
|
||||||
|
|
||||||
|
checkedValues = Array.from({ length: numberOfValues }, (_, index) => index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText: toCheckboxCustomText(checkedValues),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.DROPDOWN }, ({ fieldMeta }) => {
|
||||||
|
const values = fieldMeta?.values ?? [];
|
||||||
|
|
||||||
|
let customText = fieldMeta?.defaultValue || '';
|
||||||
|
|
||||||
|
if (!customText && values.length > 0) {
|
||||||
|
const randomIndex = faker.number.int({ min: 0, max: values.length - 1 });
|
||||||
|
customText = values[randomIndex].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
customText,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.SIGNATURE }, () => {
|
||||||
|
return {
|
||||||
|
customText: '',
|
||||||
|
signature: {
|
||||||
|
signatureImageAsBase64: '',
|
||||||
|
typedSignature: recipientName,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.with({ type: FieldType.FREE_SIGNATURE }, () => {
|
||||||
|
return {
|
||||||
|
customText: '',
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.exhaustive(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [fields, envelope, envelope.recipients, envelope.documentMeta]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the selected recipient to the first recipient in the envelope.
|
* Set the selected recipient to the first recipient in the envelope.
|
||||||
*/
|
*/
|
||||||
@ -31,7 +195,17 @@ export const EnvelopeEditorPreviewPage = () => {
|
|||||||
editorFields.setSelectedRecipient(envelope.recipients[0]?.id ?? null);
|
editorFields.setSelectedRecipient(envelope.recipients[0]?.id ?? null);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Override the parent renderer provider so we can inject custom fields.
|
||||||
return (
|
return (
|
||||||
|
<EnvelopeRenderProvider
|
||||||
|
envelope={envelope}
|
||||||
|
token={undefined}
|
||||||
|
fields={fieldsWithPlaceholders}
|
||||||
|
recipients={envelope.recipients}
|
||||||
|
overrideSettings={{
|
||||||
|
mode: 'export',
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div className="relative flex h-full">
|
<div className="relative flex h-full">
|
||||||
<div className="flex w-full flex-col overflow-y-auto">
|
<div className="flex w-full flex-col overflow-y-auto">
|
||||||
{/* Horizontal envelope item selector */}
|
{/* Horizontal envelope item selector */}
|
||||||
@ -48,23 +222,11 @@ export const EnvelopeEditorPreviewPage = () => {
|
|||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
{/* Coming soon section */}
|
|
||||||
<div className="border-border bg-card hover:bg-accent/10 flex w-full max-w-[800px] items-center gap-4 rounded-lg border p-4 transition-colors">
|
|
||||||
<div className="flex w-full flex-col items-center justify-center gap-2 py-32">
|
|
||||||
<ConstructionIcon className="text-muted-foreground h-10 w-10" />
|
|
||||||
<h3 className="text-foreground text-sm font-semibold">
|
|
||||||
<Trans>Coming soon</Trans>
|
|
||||||
</h3>
|
|
||||||
<p className="text-muted-foreground text-sm">
|
|
||||||
<Trans>This feature is coming soon</Trans>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Todo: Envelopes - Remove div after preview mode is implemented */}
|
|
||||||
<div className="hidden">
|
|
||||||
{currentEnvelopeItem !== null ? (
|
{currentEnvelopeItem !== null ? (
|
||||||
<PDFViewerKonvaLazy customPageRenderer={EnvelopeGenericPageRenderer} />
|
<PDFViewerKonvaLazy
|
||||||
|
renderer="editor"
|
||||||
|
customPageRenderer={EnvelopeGenericPageRenderer}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col items-center justify-center py-32">
|
<div className="flex flex-col items-center justify-center py-32">
|
||||||
<FileTextIcon className="text-muted-foreground h-10 w-10" />
|
<FileTextIcon className="text-muted-foreground h-10 w-10" />
|
||||||
@ -78,7 +240,6 @@ export const EnvelopeEditorPreviewPage = () => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Right Section - Form Fields Panel */}
|
{/* Right Section - Form Fields Panel */}
|
||||||
{currentEnvelopeItem && false && (
|
{currentEnvelopeItem && false && (
|
||||||
@ -94,7 +255,9 @@ export const EnvelopeEditorPreviewPage = () => {
|
|||||||
<Trans>Preview Mode</Trans>
|
<Trans>Preview Mode</Trans>
|
||||||
</AlertTitle>
|
</AlertTitle>
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
<Trans>Preview what the signed document will look like with placeholder data</Trans>
|
<Trans>
|
||||||
|
Preview what the signed document will look like with placeholder data
|
||||||
|
</Trans>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
@ -168,5 +331,6 @@ export const EnvelopeEditorPreviewPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</EnvelopeRenderProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -482,30 +482,46 @@ export const EnvelopeEditorRecipientForm = () => {
|
|||||||
|
|
||||||
const { data } = validatedFormValues;
|
const { data } = validatedFormValues;
|
||||||
|
|
||||||
|
// Weird edge case where the whole envelope is created via API
|
||||||
|
// with no signing order. If they come to this page it will show an error
|
||||||
|
// since they aren't equal and the recipient is no longer editable.
|
||||||
|
const envelopeRecipients = data.signers.map((recipient) => {
|
||||||
|
if (!canRecipientBeModified(recipient.id)) {
|
||||||
|
return {
|
||||||
|
...recipient,
|
||||||
|
signingOrder: recipient.signingOrder,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return recipient;
|
||||||
|
});
|
||||||
|
|
||||||
const hasSigningOrderChanged = envelope.documentMeta.signingOrder !== data.signingOrder;
|
const hasSigningOrderChanged = envelope.documentMeta.signingOrder !== data.signingOrder;
|
||||||
const hasAllowDictateNextSignerChanged =
|
const hasAllowDictateNextSignerChanged =
|
||||||
envelope.documentMeta.allowDictateNextSigner !== data.allowDictateNextSigner;
|
envelope.documentMeta.allowDictateNextSigner !== data.allowDictateNextSigner;
|
||||||
|
|
||||||
const hasSignersChanged =
|
const hasSignersChanged =
|
||||||
data.signers.length !== recipients.length ||
|
envelopeRecipients.length !== recipients.length ||
|
||||||
data.signers.some((signer) => {
|
envelopeRecipients.some((signer) => {
|
||||||
const recipient = recipients.find((recipient) => recipient.id === signer.id);
|
const recipient = recipients.find((recipient) => recipient.id === signer.id);
|
||||||
|
|
||||||
if (!recipient) {
|
if (!recipient) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const signerActionAuth = signer.actionAuth;
|
||||||
|
const recipientActionAuth = recipient.authOptions?.actionAuth || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
signer.email !== recipient.email ||
|
signer.email !== recipient.email ||
|
||||||
signer.name !== recipient.name ||
|
signer.name !== recipient.name ||
|
||||||
signer.role !== recipient.role ||
|
signer.role !== recipient.role ||
|
||||||
signer.signingOrder !== recipient.signingOrder ||
|
signer.signingOrder !== recipient.signingOrder ||
|
||||||
!isDeepEqual(signer.actionAuth, recipient.authOptions?.actionAuth)
|
!isDeepEqual(signerActionAuth, recipientActionAuth)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasSignersChanged) {
|
if (hasSignersChanged) {
|
||||||
setRecipientsDebounced(validatedFormValues.data.signers);
|
setRecipientsDebounced(envelopeRecipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSigningOrderChanged || hasAllowDictateNextSignerChanged) {
|
if (hasSigningOrderChanged || hasAllowDictateNextSignerChanged) {
|
||||||
|
|||||||
@ -174,7 +174,7 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
const { t, i18n } = useLingui();
|
const { t, i18n } = useLingui();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
const { envelope } = useCurrentEnvelopeEditor();
|
const { envelope, updateEnvelopeAsync } = useCurrentEnvelopeEditor();
|
||||||
|
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
const organisation = useCurrentOrganisation();
|
const organisation = useCurrentOrganisation();
|
||||||
@ -186,14 +186,12 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
documentAuth: envelope.authOptions,
|
documentAuth: envelope.authOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = useForm<TAddSettingsFormSchema>({
|
const createDefaultValues = () => {
|
||||||
resolver: zodResolver(ZAddSettingsFormSchema),
|
return {
|
||||||
defaultValues: {
|
externalId: envelope.externalId || '',
|
||||||
externalId: envelope.externalId || '', // Todo: String or undefined?
|
|
||||||
visibility: envelope.visibility || '',
|
visibility: envelope.visibility || '',
|
||||||
globalAccessAuth: documentAuthOption?.globalAccessAuth || [],
|
globalAccessAuth: documentAuthOption?.globalAccessAuth || [],
|
||||||
globalActionAuth: documentAuthOption?.globalActionAuth || [],
|
globalActionAuth: documentAuthOption?.globalActionAuth || [],
|
||||||
|
|
||||||
meta: {
|
meta: {
|
||||||
subject: envelope.documentMeta.subject ?? '',
|
subject: envelope.documentMeta.subject ?? '',
|
||||||
message: envelope.documentMeta.message ?? '',
|
message: envelope.documentMeta.message ?? '',
|
||||||
@ -210,10 +208,13 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
emailSettings: ZDocumentEmailSettingsSchema.parse(envelope.documentMeta.emailSettings),
|
emailSettings: ZDocumentEmailSettingsSchema.parse(envelope.documentMeta.emailSettings),
|
||||||
signatureTypes: extractTeamSignatureSettings(envelope.documentMeta),
|
signatureTypes: extractTeamSignatureSettings(envelope.documentMeta),
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
const { mutateAsync: updateEnvelope } = trpc.envelope.update.useMutation();
|
const form = useForm<TAddSettingsFormSchema>({
|
||||||
|
resolver: zodResolver(ZAddSettingsFormSchema),
|
||||||
|
defaultValues: createDefaultValues(),
|
||||||
|
});
|
||||||
|
|
||||||
const envelopeHasBeenSent =
|
const envelopeHasBeenSent =
|
||||||
envelope.type === EnvelopeType.DOCUMENT &&
|
envelope.type === EnvelopeType.DOCUMENT &&
|
||||||
@ -229,7 +230,6 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
|
|
||||||
const emails = emailData?.data || [];
|
const emails = emailData?.data || [];
|
||||||
|
|
||||||
// Todo: Envelopes this doesn't make sense (look at previous)
|
|
||||||
const canUpdateVisibility = canAccessTeamDocument(team.currentTeamRole, envelope.visibility);
|
const canUpdateVisibility = canAccessTeamDocument(team.currentTeamRole, envelope.visibility);
|
||||||
|
|
||||||
const onFormSubmit = async (data: TAddSettingsFormSchema) => {
|
const onFormSubmit = async (data: TAddSettingsFormSchema) => {
|
||||||
@ -240,9 +240,7 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
.safeParse(data.globalAccessAuth);
|
.safeParse(data.globalAccessAuth);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateEnvelope({
|
await updateEnvelopeAsync({
|
||||||
envelopeId: envelope.id,
|
|
||||||
envelopeType: envelope.type,
|
|
||||||
data: {
|
data: {
|
||||||
externalId: data.externalId || null,
|
externalId: data.externalId || null,
|
||||||
visibility: data.visibility,
|
visibility: data.visibility,
|
||||||
@ -297,7 +295,7 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
form.reset();
|
form.reset(createDefaultValues());
|
||||||
setActiveTab('general');
|
setActiveTab('general');
|
||||||
}, [open, form]);
|
}, [open, form]);
|
||||||
|
|
||||||
@ -323,7 +321,7 @@ export const EnvelopeEditorSettingsDialog = ({
|
|||||||
|
|
||||||
<DialogContent className="flex w-full !max-w-5xl flex-row gap-0 p-0">
|
<DialogContent className="flex w-full !max-w-5xl flex-row gap-0 p-0">
|
||||||
{/* Sidebar. */}
|
{/* Sidebar. */}
|
||||||
<div className="flex w-80 flex-col border-r bg-gray-50">
|
<div className="bg-accent/20 flex w-80 flex-col border-r">
|
||||||
<DialogHeader className="p-6 pb-4">
|
<DialogHeader className="p-6 pb-4">
|
||||||
<DialogTitle>Document Settings</DialogTitle>
|
<DialogTitle>Document Settings</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|||||||
@ -18,9 +18,9 @@ import {
|
|||||||
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
import { nanoid } from '@documenso/lib/universal/id';
|
import { nanoid } from '@documenso/lib/universal/id';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { canEnvelopeItemsBeModified } from '@documenso/lib/utils/envelope';
|
import { canEnvelopeItemsBeModified } from '@documenso/lib/utils/envelope';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateEnvelopeItemsPayload } from '@documenso/trpc/server/envelope-router/create-envelope-items.types';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@ -67,8 +67,8 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
|
|
||||||
const { mutateAsync: createEnvelopeItems, isPending: isCreatingEnvelopeItems } =
|
const { mutateAsync: createEnvelopeItems, isPending: isCreatingEnvelopeItems } =
|
||||||
trpc.envelope.item.createMany.useMutation({
|
trpc.envelope.item.createMany.useMutation({
|
||||||
onSuccess: (data) => {
|
onSuccess: ({ data }) => {
|
||||||
const createdEnvelopes = data.createdEnvelopeItems.filter(
|
const createdEnvelopes = data.filter(
|
||||||
(item) => !envelope.envelopeItems.find((envelopeItem) => envelopeItem.id === item.id),
|
(item) => !envelope.envelopeItems.find((envelopeItem) => envelopeItem.id === item.id),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -79,10 +79,10 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { mutateAsync: updateEnvelopeItems } = trpc.envelope.item.updateMany.useMutation({
|
const { mutateAsync: updateEnvelopeItems } = trpc.envelope.item.updateMany.useMutation({
|
||||||
onSuccess: (data) => {
|
onSuccess: ({ data }) => {
|
||||||
setLocalEnvelope({
|
setLocalEnvelope({
|
||||||
envelopeItems: envelope.envelopeItems.map((originalItem) => {
|
envelopeItems: envelope.envelopeItems.map((originalItem) => {
|
||||||
const updatedItem = data.updatedEnvelopeItems.find((item) => item.id === originalItem.id);
|
const updatedItem = data.find((item) => item.id === originalItem.id);
|
||||||
|
|
||||||
if (updatedItem) {
|
if (updatedItem) {
|
||||||
return {
|
return {
|
||||||
@ -114,36 +114,19 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
|
|
||||||
setLocalFiles((prev) => [...prev, ...newUploadingFiles]);
|
setLocalFiles((prev) => [...prev, ...newUploadingFiles]);
|
||||||
|
|
||||||
const result = await Promise.all(
|
const payload = {
|
||||||
files.map(async (file, index) => {
|
|
||||||
try {
|
|
||||||
const response = await putPdfFile(file);
|
|
||||||
|
|
||||||
// Mark as uploaded (remove from uploading state)
|
|
||||||
return {
|
|
||||||
title: file.name,
|
|
||||||
documentDataId: response.id,
|
|
||||||
};
|
|
||||||
} catch (_error) {
|
|
||||||
setLocalFiles((prev) =>
|
|
||||||
prev.map((uploadingFile) =>
|
|
||||||
uploadingFile.id === newUploadingFiles[index].id
|
|
||||||
? { ...uploadingFile, isError: true, isUploading: false }
|
|
||||||
: uploadingFile,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const envelopeItemsToCreate = result.filter(
|
|
||||||
(item): item is { title: string; documentDataId: string } => item !== undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { createdEnvelopeItems } = await createEnvelopeItems({
|
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
items: envelopeItemsToCreate,
|
} satisfies TCreateEnvelopeItemsPayload;
|
||||||
}).catch((error) => {
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
formData.append('files', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await createEnvelopeItems(formData).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
// Set error state on files in batch upload.
|
// Set error state on files in batch upload.
|
||||||
@ -165,7 +148,7 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return filteredFiles.concat(
|
return filteredFiles.concat(
|
||||||
createdEnvelopeItems.map((item) => ({
|
data.map((item) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
envelopeItemId: item.id,
|
envelopeItemId: item.id,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
@ -203,7 +186,6 @@ export const EnvelopeEditorUploadPage = () => {
|
|||||||
debouncedUpdateEnvelopeItems(items);
|
debouncedUpdateEnvelopeItems(items);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Todo: Envelopes - Sync into envelopes data
|
|
||||||
const debouncedUpdateEnvelopeItems = useDebounceFunction((files: LocalFile[]) => {
|
const debouncedUpdateEnvelopeItems = useDebounceFunction((files: LocalFile[]) => {
|
||||||
void updateEnvelopeItems({
|
void updateEnvelopeItems({
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
|
|||||||
@ -29,7 +29,7 @@ export const EnvelopeItemSelector = ({
|
|||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`flex h-6 w-6 items-center justify-center rounded-full text-xs font-medium ${
|
className={`flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full text-xs font-medium ${
|
||||||
isSelected ? 'bg-green-100 text-green-600' : 'bg-gray-200 text-gray-600'
|
isSelected ? 'bg-green-100 text-green-600' : 'bg-gray-200 text-gray-600'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useMemo } from 'react';
|
import { useEffect, useMemo } from 'react';
|
||||||
|
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
|
import { type Recipient, SigningStatus } from '@prisma/client';
|
||||||
import type Konva from 'konva';
|
import type Konva from 'konva';
|
||||||
|
|
||||||
import { usePageRenderer } from '@documenso/lib/client-only/hooks/use-page-renderer';
|
import { usePageRenderer } from '@documenso/lib/client-only/hooks/use-page-renderer';
|
||||||
@ -8,11 +9,23 @@ import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/e
|
|||||||
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
import type { TEnvelope } from '@documenso/lib/types/envelope';
|
||||||
import { renderField } from '@documenso/lib/universal/field-renderer/render-field';
|
import { renderField } from '@documenso/lib/universal/field-renderer/render-field';
|
||||||
import { getClientSideFieldTranslations } from '@documenso/lib/utils/fields';
|
import { getClientSideFieldTranslations } from '@documenso/lib/utils/fields';
|
||||||
|
import { EnvelopeRecipientFieldTooltip } from '@documenso/ui/components/document/envelope-recipient-field-tooltip';
|
||||||
|
|
||||||
|
type GenericLocalField = TEnvelope['fields'][number] & {
|
||||||
|
recipient: Pick<Recipient, 'id' | 'name' | 'email' | 'signingStatus'>;
|
||||||
|
};
|
||||||
|
|
||||||
export default function EnvelopeGenericPageRenderer() {
|
export default function EnvelopeGenericPageRenderer() {
|
||||||
const { i18n } = useLingui();
|
const { i18n } = useLingui();
|
||||||
|
|
||||||
const { currentEnvelopeItem, fields, getRecipientColorKey } = useCurrentEnvelopeRender();
|
const {
|
||||||
|
currentEnvelopeItem,
|
||||||
|
fields,
|
||||||
|
recipients,
|
||||||
|
getRecipientColorKey,
|
||||||
|
setRenderError,
|
||||||
|
overrideSettings,
|
||||||
|
} = useCurrentEnvelopeRender();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
stage,
|
stage,
|
||||||
@ -28,44 +41,73 @@ export default function EnvelopeGenericPageRenderer() {
|
|||||||
|
|
||||||
const { _className, scale } = pageContext;
|
const { _className, scale } = pageContext;
|
||||||
|
|
||||||
const localPageFields = useMemo(
|
const localPageFields = useMemo((): GenericLocalField[] => {
|
||||||
() =>
|
return fields
|
||||||
fields.filter(
|
.filter(
|
||||||
(field) =>
|
(field) =>
|
||||||
field.page === pageContext.pageNumber && field.envelopeItemId === currentEnvelopeItem?.id,
|
field.page === pageContext.pageNumber && field.envelopeItemId === currentEnvelopeItem?.id,
|
||||||
),
|
)
|
||||||
[fields, pageContext.pageNumber],
|
.map((field) => {
|
||||||
);
|
const recipient = recipients.find((recipient) => recipient.id === field.recipientId);
|
||||||
|
|
||||||
const renderFieldOnLayer = (field: TEnvelope['fields'][number]) => {
|
if (!recipient) {
|
||||||
|
throw new Error(`Recipient not found for field ${field.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...field,
|
||||||
|
recipient,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, [fields, pageContext.pageNumber, currentEnvelopeItem?.id, recipients]);
|
||||||
|
|
||||||
|
const unsafeRenderFieldOnLayer = (field: GenericLocalField) => {
|
||||||
if (!pageLayer.current) {
|
if (!pageLayer.current) {
|
||||||
console.error('Layer not loaded yet');
|
console.error('Layer not loaded yet');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { recipient } = field;
|
||||||
|
|
||||||
|
const fieldTranslations = getClientSideFieldTranslations(i18n);
|
||||||
|
|
||||||
|
const isInserted = recipient.signingStatus === SigningStatus.SIGNED && field.inserted;
|
||||||
|
|
||||||
renderField({
|
renderField({
|
||||||
scale,
|
scale,
|
||||||
pageLayer: pageLayer.current,
|
pageLayer: pageLayer.current,
|
||||||
field: {
|
field: {
|
||||||
renderId: field.id.toString(),
|
renderId: field.id.toString(),
|
||||||
...field,
|
...field,
|
||||||
customText: '',
|
|
||||||
width: Number(field.width),
|
width: Number(field.width),
|
||||||
height: Number(field.height),
|
height: Number(field.height),
|
||||||
positionX: Number(field.positionX),
|
positionX: Number(field.positionX),
|
||||||
positionY: Number(field.positionY),
|
positionY: Number(field.positionY),
|
||||||
inserted: false,
|
customText: isInserted ? field.customText : '',
|
||||||
fieldMeta: field.fieldMeta,
|
fieldMeta: field.fieldMeta,
|
||||||
|
signature: {
|
||||||
|
signatureImageAsBase64: '',
|
||||||
|
typedSignature: fieldTranslations.SIGNATURE,
|
||||||
},
|
},
|
||||||
translations: getClientSideFieldTranslations(i18n),
|
},
|
||||||
|
translations: fieldTranslations,
|
||||||
pageWidth: unscaledViewport.width,
|
pageWidth: unscaledViewport.width,
|
||||||
pageHeight: unscaledViewport.height,
|
pageHeight: unscaledViewport.height,
|
||||||
color: getRecipientColorKey(field.recipientId),
|
color: getRecipientColorKey(field.recipientId),
|
||||||
editable: false,
|
editable: false,
|
||||||
mode: 'sign',
|
mode: overrideSettings?.mode ?? 'sign',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderFieldOnLayer = (field: GenericLocalField) => {
|
||||||
|
try {
|
||||||
|
unsafeRenderFieldOnLayer(field);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
setRenderError(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the Konva page canvas and all fields and interactions.
|
* Initialize the Konva page canvas and all fields and interactions.
|
||||||
*/
|
*/
|
||||||
@ -113,6 +155,16 @@ export default function EnvelopeGenericPageRenderer() {
|
|||||||
className="relative w-full"
|
className="relative w-full"
|
||||||
key={`${currentEnvelopeItem.id}-renderer-${pageContext.pageNumber}`}
|
key={`${currentEnvelopeItem.id}-renderer-${pageContext.pageNumber}`}
|
||||||
>
|
>
|
||||||
|
{overrideSettings?.showRecipientTooltip &&
|
||||||
|
localPageFields.map((field) => (
|
||||||
|
<EnvelopeRecipientFieldTooltip
|
||||||
|
key={field.id}
|
||||||
|
field={field}
|
||||||
|
showFieldStatus={overrideSettings?.showRecipientSigningStatus}
|
||||||
|
showRecipientTooltip={overrideSettings?.showRecipientTooltip}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
|
||||||
{/* The element Konva will inject it's canvas into. */}
|
{/* The element Konva will inject it's canvas into. */}
|
||||||
<div className="konva-container absolute inset-0 z-10 w-full" ref={konvaContainer}></div>
|
<div className="konva-container absolute inset-0 z-10 w-full" ref={konvaContainer}></div>
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,8 @@ import { Label } from '@documenso/ui/primitives/label';
|
|||||||
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
import { RadioGroup, RadioGroupItem } from '@documenso/ui/primitives/radio-group';
|
||||||
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
import { SignaturePadDialog } from '@documenso/ui/primitives/signature-pad/signature-pad-dialog';
|
||||||
|
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
|
|
||||||
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
||||||
|
|
||||||
export default function EnvelopeSignerForm() {
|
export default function EnvelopeSignerForm() {
|
||||||
@ -25,6 +27,8 @@ export default function EnvelopeSignerForm() {
|
|||||||
setSelectedAssistantRecipientId,
|
setSelectedAssistantRecipientId,
|
||||||
} = useRequiredEnvelopeSigningContext();
|
} = useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
|
const { isNameLocked, isEmailLocked } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
const hasSignatureField = useMemo(() => {
|
const hasSignatureField = useMemo(() => {
|
||||||
return recipientFields.some((field) => field.type === FieldType.SIGNATURE);
|
return recipientFields.some((field) => field.type === FieldType.SIGNATURE);
|
||||||
}, [recipientFields]);
|
}, [recipientFields]);
|
||||||
@ -37,7 +41,7 @@ export default function EnvelopeSignerForm() {
|
|||||||
|
|
||||||
if (recipient.role === RecipientRole.ASSISTANT) {
|
if (recipient.role === RecipientRole.ASSISTANT) {
|
||||||
return (
|
return (
|
||||||
<fieldset className="dark:bg-background border-border rounded-2xl sm:border sm:p-3">
|
<fieldset className="embed--DocumentWidgetForm dark:bg-background border-border rounded-2xl sm:border sm:p-3">
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
className="gap-0 space-y-2 shadow-none sm:space-y-3"
|
className="gap-0 space-y-2 shadow-none sm:space-y-3"
|
||||||
value={selectedAssistantRecipient?.id?.toString()}
|
value={selectedAssistantRecipient?.id?.toString()}
|
||||||
@ -101,7 +105,8 @@ export default function EnvelopeSignerForm() {
|
|||||||
id="full-name"
|
id="full-name"
|
||||||
className="bg-background mt-2"
|
className="bg-background mt-2"
|
||||||
value={fullName}
|
value={fullName}
|
||||||
onChange={(e) => setFullName(e.target.value.trimStart())}
|
disabled={isNameLocked}
|
||||||
|
onChange={(e) => !isNameLocked && setFullName(e.target.value.trimStart())}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import {
|
|||||||
import { Separator } from '@documenso/ui/primitives/separator';
|
import { Separator } from '@documenso/ui/primitives/separator';
|
||||||
|
|
||||||
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
import { BrandingLogo } from '~/components/general/branding-logo';
|
import { BrandingLogo } from '~/components/general/branding-logo';
|
||||||
|
|
||||||
import { BrandingLogoIcon } from '../branding-logo-icon';
|
import { BrandingLogoIcon } from '../branding-logo-icon';
|
||||||
@ -28,7 +29,7 @@ export const EnvelopeSignerHeader = () => {
|
|||||||
useRequiredEnvelopeSigningContext();
|
useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className="bg-background border-border max-w-screen flex flex-row justify-between border-b px-4 py-3 md:px-6">
|
<nav className="embed--DocumentWidgetHeader bg-background border-border max-w-screen flex flex-row justify-between border-b px-4 py-3 md:px-6">
|
||||||
{/* Left side - Logo and title */}
|
{/* Left side - Logo and title */}
|
||||||
<div className="flex min-w-0 flex-1 items-center space-x-2 md:w-auto md:flex-none">
|
<div className="flex min-w-0 flex-1 items-center space-x-2 md:w-auto md:flex-none">
|
||||||
<Link to="/" className="flex-shrink-0">
|
<Link to="/" className="flex-shrink-0">
|
||||||
@ -72,7 +73,7 @@ export const EnvelopeSignerHeader = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right side - Desktop content */}
|
{/* Right side - Desktop content */}
|
||||||
<div className="hidden items-center space-x-2 md:flex">
|
<div className="hidden items-center space-x-2 lg:flex">
|
||||||
<p className="text-muted-foreground mr-2 flex-shrink-0 text-sm">
|
<p className="text-muted-foreground mr-2 flex-shrink-0 text-sm">
|
||||||
<Plural
|
<Plural
|
||||||
one="1 Field Remaining"
|
one="1 Field Remaining"
|
||||||
@ -85,7 +86,7 @@ export const EnvelopeSignerHeader = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile Actions button */}
|
{/* Mobile Actions button */}
|
||||||
<div className="flex-shrink-0 md:hidden">
|
<div className="flex-shrink-0 lg:hidden">
|
||||||
<MobileDropdownMenu />
|
<MobileDropdownMenu />
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@ -95,6 +96,8 @@ export const EnvelopeSignerHeader = () => {
|
|||||||
const MobileDropdownMenu = () => {
|
const MobileDropdownMenu = () => {
|
||||||
const { envelope, recipient } = useRequiredEnvelopeSigningContext();
|
const { envelope, recipient } = useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
|
const { allowDocumentRejection } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@ -119,7 +122,7 @@ const MobileDropdownMenu = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{envelope.type === EnvelopeType.DOCUMENT && (
|
{envelope.type === EnvelopeType.DOCUMENT && allowDocumentRejection !== false && (
|
||||||
<DocumentSigningRejectDialog
|
<DocumentSigningRejectDialog
|
||||||
documentId={mapSecondaryIdToDocumentId(envelope.secondaryId)}
|
documentId={mapSecondaryIdToDocumentId(envelope.secondaryId)}
|
||||||
token={recipient.token}
|
token={recipient.token}
|
||||||
|
|||||||
@ -10,15 +10,20 @@ import { usePageRenderer } from '@documenso/lib/client-only/hooks/use-page-rende
|
|||||||
import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
||||||
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
import { useOptionalSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { DIRECT_TEMPLATE_RECIPIENT_EMAIL } from '@documenso/lib/constants/direct-templates';
|
import { DIRECT_TEMPLATE_RECIPIENT_EMAIL } from '@documenso/lib/constants/direct-templates';
|
||||||
|
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
||||||
|
import type { TRecipientActionAuth } from '@documenso/lib/types/document-auth';
|
||||||
import { ZFullFieldSchema } from '@documenso/lib/types/field';
|
import { ZFullFieldSchema } from '@documenso/lib/types/field';
|
||||||
import { createSpinner } from '@documenso/lib/universal/field-renderer/field-generic-items';
|
import { createSpinner } from '@documenso/lib/universal/field-renderer/field-generic-items';
|
||||||
import { renderField } from '@documenso/lib/universal/field-renderer/render-field';
|
import { renderField } from '@documenso/lib/universal/field-renderer/render-field';
|
||||||
import { isFieldUnsignedAndRequired } from '@documenso/lib/utils/advanced-fields-helpers';
|
import { isFieldUnsignedAndRequired } from '@documenso/lib/utils/advanced-fields-helpers';
|
||||||
import { getClientSideFieldTranslations } from '@documenso/lib/utils/fields';
|
import { getClientSideFieldTranslations } from '@documenso/lib/utils/fields';
|
||||||
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
import { extractInitials } from '@documenso/lib/utils/recipient-formatter';
|
||||||
|
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
|
||||||
import { EnvelopeFieldToolTip } from '@documenso/ui/components/field/envelope-field-tooltip';
|
import { EnvelopeFieldToolTip } from '@documenso/ui/components/field/envelope-field-tooltip';
|
||||||
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
||||||
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
import { handleCheckboxFieldClick } from '~/utils/field-signing/checkbox-field';
|
import { handleCheckboxFieldClick } from '~/utils/field-signing/checkbox-field';
|
||||||
import { handleDropdownFieldClick } from '~/utils/field-signing/dropdown-field';
|
import { handleDropdownFieldClick } from '~/utils/field-signing/dropdown-field';
|
||||||
import { handleEmailFieldClick } from '~/utils/field-signing/email-field';
|
import { handleEmailFieldClick } from '~/utils/field-signing/email-field';
|
||||||
@ -28,20 +33,24 @@ import { handleNumberFieldClick } from '~/utils/field-signing/number-field';
|
|||||||
import { handleSignatureFieldClick } from '~/utils/field-signing/signature-field';
|
import { handleSignatureFieldClick } from '~/utils/field-signing/signature-field';
|
||||||
import { handleTextFieldClick } from '~/utils/field-signing/text-field';
|
import { handleTextFieldClick } from '~/utils/field-signing/text-field';
|
||||||
|
|
||||||
|
import { useRequiredDocumentSigningAuthContext } from '../document-signing/document-signing-auth-provider';
|
||||||
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
||||||
|
|
||||||
export default function EnvelopeSignerPageRenderer() {
|
export default function EnvelopeSignerPageRenderer() {
|
||||||
const { i18n } = useLingui();
|
const { t, i18n } = useLingui();
|
||||||
const { currentEnvelopeItem } = useCurrentEnvelopeRender();
|
const { currentEnvelopeItem, setRenderError } = useCurrentEnvelopeRender();
|
||||||
const { sessionData } = useOptionalSession();
|
const { sessionData } = useOptionalSession();
|
||||||
|
|
||||||
|
const { executeActionAuthProcedure } = useRequiredDocumentSigningAuthContext();
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
envelopeData,
|
envelopeData,
|
||||||
recipient,
|
recipient,
|
||||||
recipientFields,
|
recipientFields,
|
||||||
recipientFieldsRemaining,
|
recipientFieldsRemaining,
|
||||||
showPendingFieldTooltip,
|
showPendingFieldTooltip,
|
||||||
signField,
|
signField: signFieldInternal,
|
||||||
email,
|
email,
|
||||||
setEmail,
|
setEmail,
|
||||||
fullName,
|
fullName,
|
||||||
@ -53,6 +62,8 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
isDirectTemplate,
|
isDirectTemplate,
|
||||||
} = useRequiredEnvelopeSigningContext();
|
} = useRequiredEnvelopeSigningContext();
|
||||||
|
|
||||||
|
const { onFieldSigned, onFieldUnsigned } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
stage,
|
stage,
|
||||||
pageLayer,
|
pageLayer,
|
||||||
@ -80,7 +91,7 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
);
|
);
|
||||||
}, [recipientFields, selectedAssistantRecipientFields, pageContext.pageNumber]);
|
}, [recipientFields, selectedAssistantRecipientFields, pageContext.pageNumber]);
|
||||||
|
|
||||||
const renderFieldOnLayer = (unparsedField: Field & { signature?: Signature | null }) => {
|
const unsafeRenderFieldOnLayer = (unparsedField: Field & { signature?: Signature | null }) => {
|
||||||
if (!pageLayer.current) {
|
if (!pageLayer.current) {
|
||||||
console.error('Layer not loaded yet');
|
console.error('Layer not loaded yet');
|
||||||
return;
|
return;
|
||||||
@ -237,7 +248,7 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
.then(async (payload) => {
|
.then(async (payload) => {
|
||||||
if (payload) {
|
if (payload) {
|
||||||
fieldGroup.add(loadingSpinnerGroup);
|
fieldGroup.add(loadingSpinnerGroup);
|
||||||
await signField(field.id, payload); // Todo: Envelopes - Handle errors
|
await signField(field.id, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload?.value) {
|
if (payload?.value) {
|
||||||
@ -318,7 +329,6 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
* SIGNATURE FIELD.
|
* SIGNATURE FIELD.
|
||||||
*/
|
*/
|
||||||
.with({ type: FieldType.SIGNATURE }, (field) => {
|
.with({ type: FieldType.SIGNATURE }, (field) => {
|
||||||
// Todo: Envelopes - Reauth
|
|
||||||
handleSignatureFieldClick({
|
handleSignatureFieldClick({
|
||||||
field,
|
field,
|
||||||
signature,
|
signature,
|
||||||
@ -329,11 +339,21 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
.then(async (payload) => {
|
.then(async (payload) => {
|
||||||
if (payload) {
|
if (payload) {
|
||||||
fieldGroup.add(loadingSpinnerGroup);
|
fieldGroup.add(loadingSpinnerGroup);
|
||||||
|
|
||||||
|
if (payload.value) {
|
||||||
|
void executeActionAuthProcedure({
|
||||||
|
onReauthFormSubmit: async (authOptions) => {
|
||||||
|
await signField(field.id, payload, authOptions);
|
||||||
|
|
||||||
|
loadingSpinnerGroup.destroy();
|
||||||
|
},
|
||||||
|
actionTarget: field.type,
|
||||||
|
});
|
||||||
|
|
||||||
|
setSignature(payload.value);
|
||||||
|
} else {
|
||||||
await signField(field.id, payload);
|
await signField(field.id, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload?.value) {
|
|
||||||
setSignature(payload.value);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
@ -347,13 +367,54 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
fieldGroup.on('pointerdown', handleFieldGroupClick);
|
fieldGroup.on('pointerdown', handleFieldGroupClick);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renderFieldOnLayer = (unparsedField: Field & { signature?: Signature | null }) => {
|
||||||
|
try {
|
||||||
|
unsafeRenderFieldOnLayer(unparsedField);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
setRenderError(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const signField = async (
|
||||||
|
fieldId: number,
|
||||||
|
payload: TSignEnvelopeFieldValue,
|
||||||
|
authOptions?: TRecipientActionAuth,
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const { inserted } = await signFieldInternal(fieldId, payload, authOptions);
|
||||||
|
|
||||||
|
// ?: The two callbacks below are used within the embedding context
|
||||||
|
if (inserted && onFieldSigned) {
|
||||||
|
const value = payload.value ? JSON.stringify(payload.value) : undefined;
|
||||||
|
const isBase64 = value ? isBase64Image(value) : undefined;
|
||||||
|
|
||||||
|
onFieldSigned({ fieldId, value, isBase64 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inserted && onFieldUnsigned) {
|
||||||
|
onFieldUnsigned({ fieldId });
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t`Error`,
|
||||||
|
description: t`An error occurred while signing the field.`,
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the Konva page canvas and all fields and interactions.
|
* Initialize the Konva page canvas and all fields and interactions.
|
||||||
*/
|
*/
|
||||||
const createPageCanvas = (currentStage: Konva.Stage, currentPageLayer: Konva.Layer) => {
|
const createPageCanvas = (currentStage: Konva.Stage, currentPageLayer: Konva.Layer) => {
|
||||||
// Render the fields.
|
// Render the fields.
|
||||||
for (const field of localPageFields) {
|
for (const field of localPageFields) {
|
||||||
renderFieldOnLayer(field); // Todo: Envelopes - [CRITICAL] Handle errors which prevent rendering
|
renderFieldOnLayer(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPageLayer.batchDraw();
|
currentPageLayer.batchDraw();
|
||||||
@ -368,8 +429,7 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
localPageFields.forEach((field) => {
|
localPageFields.forEach((field) => {
|
||||||
console.log('Field changed/inserted, rendering on canvas');
|
renderFieldOnLayer(field);
|
||||||
renderFieldOnLayer(field); // Todo: Envelopes - [CRITICAL] Handle errors which prevent rendering
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pageLayer.current.batchDraw();
|
pageLayer.current.batchDraw();
|
||||||
@ -387,7 +447,7 @@ export default function EnvelopeSignerPageRenderer() {
|
|||||||
pageLayer.current.destroyChildren();
|
pageLayer.current.destroyChildren();
|
||||||
|
|
||||||
localPageFields.forEach((field) => {
|
localPageFields.forEach((field) => {
|
||||||
renderFieldOnLayer(field); // Todo: Envelopes - [CRITICAL] Handle errors which prevent rendering
|
renderFieldOnLayer(field);
|
||||||
});
|
});
|
||||||
|
|
||||||
pageLayer.current.batchDraw();
|
pageLayer.current.batchDraw();
|
||||||
|
|||||||
@ -2,16 +2,19 @@ import { useMemo } from 'react';
|
|||||||
|
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { useLingui } from '@lingui/react/macro';
|
||||||
import { FieldType } from '@prisma/client';
|
import { FieldType } from '@prisma/client';
|
||||||
import { useNavigate, useSearchParams } from 'react-router';
|
import { useNavigate, useRevalidator, useSearchParams } from 'react-router';
|
||||||
|
|
||||||
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';
|
||||||
import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
import { useCurrentEnvelopeRender } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
||||||
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
import { isBase64Image } from '@documenso/lib/constants/signatures';
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import type { TRecipientAccessAuth } from '@documenso/lib/types/document-auth';
|
import type { TRecipientAccessAuth } from '@documenso/lib/types/document-auth';
|
||||||
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
|
import { useEmbedSigningContext } from '~/components/embed/embed-signing-context';
|
||||||
|
|
||||||
import { DocumentSigningCompleteDialog } from '../document-signing/document-signing-complete-dialog';
|
import { DocumentSigningCompleteDialog } from '../document-signing/document-signing-complete-dialog';
|
||||||
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
import { useRequiredEnvelopeSigningContext } from '../document-signing/envelope-signing-provider';
|
||||||
|
|
||||||
@ -19,8 +22,9 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const analytics = useAnalytics();
|
const analytics = useAnalytics();
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { t } = useLingui();
|
const { t } = useLingui();
|
||||||
|
const { toast } = useToast();
|
||||||
|
const { revalidate } = useRevalidator();
|
||||||
|
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
|
||||||
@ -37,6 +41,8 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
|
|
||||||
const { currentEnvelopeItem, setCurrentEnvelopeItem } = useCurrentEnvelopeRender();
|
const { currentEnvelopeItem, setCurrentEnvelopeItem } = useCurrentEnvelopeRender();
|
||||||
|
|
||||||
|
const { onDocumentCompleted, onDocumentError } = useEmbedSigningContext() || {};
|
||||||
|
|
||||||
const { mutateAsync: completeDocument, isPending } =
|
const { mutateAsync: completeDocument, isPending } =
|
||||||
trpc.recipient.completeDocumentWithToken.useMutation();
|
trpc.recipient.completeDocumentWithToken.useMutation();
|
||||||
|
|
||||||
@ -68,6 +74,7 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
nextSigner?: { name: string; email: string },
|
nextSigner?: { name: string; email: string },
|
||||||
accessAuthOptions?: TRecipientAccessAuth,
|
accessAuthOptions?: TRecipientAccessAuth,
|
||||||
) => {
|
) => {
|
||||||
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
@ -83,11 +90,39 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (onDocumentCompleted) {
|
||||||
|
onDocumentCompleted({
|
||||||
|
token: recipient.token,
|
||||||
|
documentId: mapSecondaryIdToDocumentId(envelope.secondaryId),
|
||||||
|
recipientId: recipient.id,
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await revalidate();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (envelope.documentMeta.redirectUrl) {
|
if (envelope.documentMeta.redirectUrl) {
|
||||||
window.location.href = envelope.documentMeta.redirectUrl;
|
window.location.href = envelope.documentMeta.redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
await navigate(`/sign/${recipient.token}/complete`);
|
await navigate(`/sign/${recipient.token}/complete`);
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const error = AppError.parseError(err);
|
||||||
|
|
||||||
|
if (error.code !== AppErrorCode.TWO_FACTOR_AUTH_FAILED) {
|
||||||
|
toast({
|
||||||
|
title: t`Something went wrong`,
|
||||||
|
description: t`We were unable to submit this document at this time. Please try again later.`,
|
||||||
|
variant: 'destructive',
|
||||||
|
});
|
||||||
|
|
||||||
|
onDocumentError?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,8 +140,12 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
directTemplateExternalId = decodeURIComponent(directTemplateExternalId);
|
directTemplateExternalId = decodeURIComponent(directTemplateExternalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!recipient.directToken) {
|
||||||
|
throw new Error('Recipient direct token is required');
|
||||||
|
}
|
||||||
|
|
||||||
const { token } = await createDocumentFromDirectTemplate({
|
const { token } = await createDocumentFromDirectTemplate({
|
||||||
directTemplateToken: recipient.token, // The direct template token is inserted into the recipient token for ease of use.
|
directTemplateToken: recipient.directToken, // The direct template token is inserted into the recipient token for ease of use.
|
||||||
directTemplateExternalId,
|
directTemplateExternalId,
|
||||||
directRecipientName: recipientDetails?.name || fullName,
|
directRecipientName: recipientDetails?.name || fullName,
|
||||||
directRecipientEmail: recipientDetails?.email || email,
|
directRecipientEmail: recipientDetails?.email || email,
|
||||||
@ -132,18 +171,31 @@ export const EnvelopeSignerCompleteDialog = () => {
|
|||||||
|
|
||||||
const redirectUrl = envelope.documentMeta.redirectUrl;
|
const redirectUrl = envelope.documentMeta.redirectUrl;
|
||||||
|
|
||||||
|
if (onDocumentCompleted) {
|
||||||
|
await navigate({
|
||||||
|
pathname: `/embed/sign/${token}`,
|
||||||
|
search: window.location.search,
|
||||||
|
hash: window.location.hash,
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (redirectUrl) {
|
if (redirectUrl) {
|
||||||
window.location.href = redirectUrl;
|
window.location.href = redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
await navigate(`/sign/${token}/complete`);
|
await navigate(`/sign/${token}/complete`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log('err', err);
|
||||||
toast({
|
toast({
|
||||||
title: t`Something went wrong`,
|
title: t`Something went wrong`,
|
||||||
description: t`We were unable to submit this document at this time. Please try again later.`,
|
description: t`We were unable to submit this document at this time. Please try again later.`,
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDocumentError?.();
|
||||||
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
|
||||||
import { Download } from 'lucide-react';
|
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import type { DocumentData } from '@documenso/prisma/client';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
export type ShareDocumentDownloadButtonProps = {
|
|
||||||
title: string;
|
|
||||||
documentData: DocumentData;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ShareDocumentDownloadButton = ({
|
|
||||||
title,
|
|
||||||
documentData,
|
|
||||||
}: ShareDocumentDownloadButtonProps) => {
|
|
||||||
const { _ } = useLingui();
|
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
const [isDownloading, setIsDownloading] = useState(false);
|
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
setIsDownloading(true);
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsDownloading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Button loading={isDownloading} onClick={onDownloadClick}>
|
|
||||||
{!isDownloading && <Download className="mr-2 h-4 w-4" />}
|
|
||||||
<Trans>Download</Trans>
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -10,9 +10,9 @@ import { match } from 'ts-pattern';
|
|||||||
|
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions';
|
import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions';
|
||||||
import { putPdfFile } from '@documenso/lib/universal/upload/put-file';
|
|
||||||
import { formatTemplatesPath } from '@documenso/lib/utils/teams';
|
import { formatTemplatesPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
|
import type { TCreateTemplatePayloadSchema } from '@documenso/trpc/server/template-router/schema';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||||
|
|
||||||
@ -40,13 +40,17 @@ export const TemplateDropZoneWrapper = ({ children, className }: TemplateDropZon
|
|||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const documentData = await putPdfFile(file);
|
const payload = {
|
||||||
|
|
||||||
const { legacyTemplateId: id } = await createTemplate({
|
|
||||||
title: file.name,
|
title: file.name,
|
||||||
templateDocumentDataId: documentData.id,
|
|
||||||
folderId: folderId ?? undefined,
|
folderId: folderId ?? undefined,
|
||||||
});
|
} satisfies TCreateTemplatePayloadSchema;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
formData.append('file', file);
|
||||||
|
|
||||||
|
const { envelopeId: id } = await createTemplate(formData);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: _(msg`Template uploaded`),
|
title: _(msg`Template uploaded`),
|
||||||
|
|||||||
@ -313,8 +313,10 @@ export const TemplateEditForm = ({
|
|||||||
>
|
>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
key={templateDocumentData.id}
|
key={template.envelopeItems[0].id}
|
||||||
documentData={templateDocumentData}
|
envelopeItem={template.envelopeItems[0]}
|
||||||
|
token={undefined}
|
||||||
|
version="signed"
|
||||||
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
onDocumentLoad={() => setIsDocumentPdfLoaded(true)}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@ -1,19 +1,14 @@
|
|||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
import { DocumentStatus, RecipientRole, SigningStatus } from '@prisma/client';
|
||||||
import { CheckCircle, Download, Edit, EyeIcon, Pencil } from 'lucide-react';
|
import { CheckCircle, Download, Edit, EyeIcon, Pencil } from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import type { TDocumentMany as TDocumentRow } from '@documenso/lib/types/document';
|
import type { TDocumentMany as TDocumentRow } from '@documenso/lib/types/document';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { useCurrentTeam } from '~/providers/team';
|
import { useCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
@ -25,8 +20,6 @@ export type DocumentsTableActionButtonProps = {
|
|||||||
|
|
||||||
export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonProps) => {
|
export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonProps) => {
|
||||||
const { user } = useSession();
|
const { user } = useSession();
|
||||||
const { toast } = useToast();
|
|
||||||
const { _ } = useLingui();
|
|
||||||
|
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
|
|
||||||
@ -44,39 +37,6 @@ export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonPr
|
|||||||
const documentsPath = formatDocumentsPath(team.url);
|
const documentsPath = formatDocumentsPath(team.url);
|
||||||
const formatPath = `${documentsPath}/${row.envelopeId}/edit`;
|
const formatPath = `${documentsPath}/${row.envelopeId}/edit`;
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
const document = !recipient
|
|
||||||
? await trpcClient.document.get.query(
|
|
||||||
{
|
|
||||||
documentId: row.id,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
context: {
|
|
||||||
teamId: team?.id?.toString(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: await trpcClient.document.getDocumentByToken.query({
|
|
||||||
token: recipient.token,
|
|
||||||
});
|
|
||||||
|
|
||||||
const documentData = document?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
throw Error('No document available');
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: row.title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Consider if want to keep this logic for hiding viewing for CC'ers
|
// TODO: Consider if want to keep this logic for hiding viewing for CC'ers
|
||||||
if (recipient?.role === RecipientRole.CC && isComplete === false) {
|
if (recipient?.role === RecipientRole.CC && isComplete === false) {
|
||||||
return null;
|
return null;
|
||||||
@ -134,7 +94,7 @@ export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonPr
|
|||||||
<Trans>View</Trans>
|
<Trans>View</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
))
|
))
|
||||||
.with({ isComplete: true, internalVersion: 2 }, () => (
|
.with({ isComplete: true }, () => (
|
||||||
<EnvelopeDownloadDialog
|
<EnvelopeDownloadDialog
|
||||||
envelopeId={row.envelopeId}
|
envelopeId={row.envelopeId}
|
||||||
envelopeStatus={row.status}
|
envelopeStatus={row.status}
|
||||||
@ -147,11 +107,5 @@ export const DocumentsTableActionButton = ({ row }: DocumentsTableActionButtonPr
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.with({ isComplete: true }, () => (
|
|
||||||
<Button className="w-32" onClick={onDownloadClick}>
|
|
||||||
<Download className="-ml-1 mr-2 inline h-4 w-4" />
|
|
||||||
<Trans>Download</Trans>
|
|
||||||
</Button>
|
|
||||||
))
|
|
||||||
.otherwise(() => <div></div>);
|
.otherwise(() => <div></div>);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import {
|
|||||||
Download,
|
Download,
|
||||||
Edit,
|
Edit,
|
||||||
EyeIcon,
|
EyeIcon,
|
||||||
FileDown,
|
|
||||||
FolderInput,
|
FolderInput,
|
||||||
Loader,
|
Loader,
|
||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
@ -20,12 +19,10 @@ import {
|
|||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import type { TDocumentMany as TDocumentRow } from '@documenso/lib/types/document';
|
import type { TDocumentMany as TDocumentRow } from '@documenso/lib/types/document';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
import { formatDocumentsPath } from '@documenso/lib/utils/teams';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@ -34,7 +31,6 @@ import {
|
|||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@documenso/ui/primitives/dropdown-menu';
|
} from '@documenso/ui/primitives/dropdown-menu';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
import { DocumentDeleteDialog } from '~/components/dialogs/document-delete-dialog';
|
import { DocumentDeleteDialog } from '~/components/dialogs/document-delete-dialog';
|
||||||
import { DocumentDuplicateDialog } from '~/components/dialogs/document-duplicate-dialog';
|
import { DocumentDuplicateDialog } from '~/components/dialogs/document-duplicate-dialog';
|
||||||
@ -56,7 +52,6 @@ export const DocumentsTableActionDropdown = ({
|
|||||||
const { user } = useSession();
|
const { user } = useSession();
|
||||||
const team = useCurrentTeam();
|
const team = useCurrentTeam();
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
const { _ } = useLingui();
|
const { _ } = useLingui();
|
||||||
|
|
||||||
const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
const [isDeleteDialogOpen, setDeleteDialogOpen] = useState(false);
|
||||||
@ -76,58 +71,6 @@ export const DocumentsTableActionDropdown = ({
|
|||||||
const documentsPath = formatDocumentsPath(team.url);
|
const documentsPath = formatDocumentsPath(team.url);
|
||||||
const formatPath = `${documentsPath}/${row.envelopeId}/edit`;
|
const formatPath = `${documentsPath}/${row.envelopeId}/edit`;
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
const document = !recipient
|
|
||||||
? await trpcClient.document.get.query({
|
|
||||||
documentId: row.id,
|
|
||||||
})
|
|
||||||
: await trpcClient.document.getDocumentByToken.query({
|
|
||||||
token: recipient.token,
|
|
||||||
});
|
|
||||||
|
|
||||||
const documentData = document?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: row.title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDownloadOriginalClick = async () => {
|
|
||||||
try {
|
|
||||||
const document = !recipient
|
|
||||||
? await trpcClient.document.get.query({
|
|
||||||
documentId: row.id,
|
|
||||||
})
|
|
||||||
: await trpcClient.document.getDocumentByToken.query({
|
|
||||||
token: recipient.token,
|
|
||||||
});
|
|
||||||
|
|
||||||
const documentData = document?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: row.title, version: 'original' });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nonSignedRecipients = row.recipients.filter((item) => item.signingStatus !== 'SIGNED');
|
const nonSignedRecipients = row.recipients.filter((item) => item.signingStatus !== 'SIGNED');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -178,7 +121,6 @@ export const DocumentsTableActionDropdown = ({
|
|||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
{row.internalVersion === 2 ? (
|
|
||||||
<EnvelopeDownloadDialog
|
<EnvelopeDownloadDialog
|
||||||
envelopeId={row.envelopeId}
|
envelopeId={row.envelopeId}
|
||||||
envelopeStatus={row.status}
|
envelopeStatus={row.status}
|
||||||
@ -192,19 +134,6 @@ export const DocumentsTableActionDropdown = ({
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<DropdownMenuItem disabled={!isComplete} onClick={onDownloadClick}>
|
|
||||||
<Download className="mr-2 h-4 w-4" />
|
|
||||||
<Trans>Download</Trans>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuItem onClick={onDownloadOriginalClick}>
|
|
||||||
<FileDown className="mr-2 h-4 w-4" />
|
|
||||||
<Trans>Download Original</Trans>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<DropdownMenuItem onClick={() => setDuplicateDialogOpen(true)}>
|
<DropdownMenuItem onClick={() => setDuplicateDialogOpen(true)}>
|
||||||
<Copy className="mr-2 h-4 w-4" />
|
<Copy className="mr-2 h-4 w-4" />
|
||||||
@ -273,7 +202,8 @@ export const DocumentsTableActionDropdown = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DocumentDuplicateDialog
|
<DocumentDuplicateDialog
|
||||||
id={row.id}
|
id={row.envelopeId}
|
||||||
|
token={recipient?.token}
|
||||||
open={isDuplicateDialogOpen}
|
open={isDuplicateDialogOpen}
|
||||||
onOpenChange={setDuplicateDialogOpen}
|
onOpenChange={setDuplicateDialogOpen}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -10,11 +10,9 @@ import { DateTime } from 'luxon';
|
|||||||
import { Link, useSearchParams } from 'react-router';
|
import { Link, useSearchParams } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { downloadPDF } from '@documenso/lib/client-only/download-pdf';
|
|
||||||
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
import { useUpdateSearchParams } from '@documenso/lib/client-only/hooks/use-update-search-params';
|
||||||
import { useSession } from '@documenso/lib/client-only/providers/session';
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { trpc as trpcClient } from '@documenso/trpc/client';
|
|
||||||
import { trpc } from '@documenso/trpc/react';
|
import { trpc } from '@documenso/trpc/react';
|
||||||
import type { TFindInboxResponse } from '@documenso/trpc/server/document-router/find-inbox.types';
|
import type { TFindInboxResponse } from '@documenso/trpc/server/document-router/find-inbox.types';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
@ -28,6 +26,7 @@ import { useToast } from '@documenso/ui/primitives/use-toast';
|
|||||||
import { DocumentStatus } from '~/components/general/document/document-status';
|
import { DocumentStatus } from '~/components/general/document/document-status';
|
||||||
import { useOptionalCurrentTeam } from '~/providers/team';
|
import { useOptionalCurrentTeam } from '~/providers/team';
|
||||||
|
|
||||||
|
import { EnvelopeDownloadDialog } from '../dialogs/envelope-download-dialog';
|
||||||
import { StackAvatarsWithTooltip } from '../general/stack-avatars-with-tooltip';
|
import { StackAvatarsWithTooltip } from '../general/stack-avatars-with-tooltip';
|
||||||
|
|
||||||
export type DocumentsTableProps = {
|
export type DocumentsTableProps = {
|
||||||
@ -199,28 +198,6 @@ export const InboxTableActionButton = ({ row }: InboxTableActionButtonProps) =>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onDownloadClick = async () => {
|
|
||||||
try {
|
|
||||||
const document = await trpcClient.document.getDocumentByToken.query({
|
|
||||||
token: recipient.token,
|
|
||||||
});
|
|
||||||
|
|
||||||
const documentData = document?.documentData;
|
|
||||||
|
|
||||||
if (!documentData) {
|
|
||||||
throw Error('No document available');
|
|
||||||
}
|
|
||||||
|
|
||||||
await downloadPDF({ documentData, fileName: row.title });
|
|
||||||
} catch (err) {
|
|
||||||
toast({
|
|
||||||
title: _(msg`Something went wrong`),
|
|
||||||
description: _(msg`An error occurred while downloading your document.`),
|
|
||||||
variant: 'destructive',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Consider if want to keep this logic for hiding viewing for CC'ers
|
// TODO: Consider if want to keep this logic for hiding viewing for CC'ers
|
||||||
if (recipient?.role === RecipientRole.CC && isComplete === false) {
|
if (recipient?.role === RecipientRole.CC && isComplete === false) {
|
||||||
return null;
|
return null;
|
||||||
@ -230,6 +207,7 @@ export const InboxTableActionButton = ({ row }: InboxTableActionButtonProps) =>
|
|||||||
isPending,
|
isPending,
|
||||||
isComplete,
|
isComplete,
|
||||||
isSigned,
|
isSigned,
|
||||||
|
internalVersion: row.internalVersion,
|
||||||
})
|
})
|
||||||
.with({ isPending: true, isSigned: false }, () => (
|
.with({ isPending: true, isSigned: false }, () => (
|
||||||
<Button className="w-32" asChild>
|
<Button className="w-32" asChild>
|
||||||
@ -263,10 +241,17 @@ export const InboxTableActionButton = ({ row }: InboxTableActionButtonProps) =>
|
|||||||
</Button>
|
</Button>
|
||||||
))
|
))
|
||||||
.with({ isComplete: true }, () => (
|
.with({ isComplete: true }, () => (
|
||||||
<Button className="w-32" onClick={onDownloadClick}>
|
<EnvelopeDownloadDialog
|
||||||
|
envelopeId={row.envelopeId}
|
||||||
|
envelopeStatus={row.status}
|
||||||
|
token={recipient?.token}
|
||||||
|
trigger={
|
||||||
|
<Button className="w-32">
|
||||||
<DownloadIcon className="-ml-1 mr-2 inline h-4 w-4" />
|
<DownloadIcon className="-ml-1 mr-2 inline h-4 w-4" />
|
||||||
<Trans>Download</Trans>
|
<Trans>Download</Trans>
|
||||||
</Button>
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
))
|
))
|
||||||
.otherwise(() => <div></div>);
|
.otherwise(() => <div></div>);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -147,8 +147,13 @@ export default function DocumentPage({ params }: Route.ComponentProps) {
|
|||||||
<div className="relative col-span-12 lg:col-span-6 xl:col-span-7">
|
<div className="relative col-span-12 lg:col-span-6 xl:col-span-7">
|
||||||
<EnvelopeRenderProvider
|
<EnvelopeRenderProvider
|
||||||
envelope={envelope}
|
envelope={envelope}
|
||||||
fields={envelope.status == DocumentStatus.COMPLETED ? [] : envelope.fields}
|
token={undefined}
|
||||||
recipientIds={envelope.recipients.map((recipient) => recipient.id)}
|
fields={envelope.fields}
|
||||||
|
recipients={envelope.recipients}
|
||||||
|
overrideSettings={{
|
||||||
|
showRecipientSigningStatus: true,
|
||||||
|
showRecipientTooltip: true,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{isMultiEnvelopeItem && (
|
{isMultiEnvelopeItem && (
|
||||||
<EnvelopeRendererFileSelector fields={envelope.fields} className="mb-4 p-0" />
|
<EnvelopeRendererFileSelector fields={envelope.fields} className="mb-4 p-0" />
|
||||||
@ -156,7 +161,10 @@ export default function DocumentPage({ params }: Route.ComponentProps) {
|
|||||||
|
|
||||||
<Card className="rounded-xl before:rounded-xl" gradient>
|
<Card className="rounded-xl before:rounded-xl" gradient>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewerKonvaLazy customPageRenderer={EnvelopeGenericPageRenderer} />
|
<PDFViewerKonvaLazy
|
||||||
|
renderer="preview"
|
||||||
|
customPageRenderer={EnvelopeGenericPageRenderer}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
@ -178,9 +186,10 @@ export default function DocumentPage({ params }: Route.ComponentProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
document={envelope}
|
envelopeItem={envelope.envelopeItems[0]}
|
||||||
|
token={undefined}
|
||||||
key={envelope.envelopeItems[0].id}
|
key={envelope.envelopeItems[0].id}
|
||||||
documentData={envelope.envelopeItems[0].documentData}
|
version="signed"
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@ -101,8 +101,9 @@ export default function EnvelopeEditorPage({ params }: Route.ComponentProps) {
|
|||||||
<EnvelopeEditorProvider initialEnvelope={envelope}>
|
<EnvelopeEditorProvider initialEnvelope={envelope}>
|
||||||
<EnvelopeRenderProvider
|
<EnvelopeRenderProvider
|
||||||
envelope={envelope}
|
envelope={envelope}
|
||||||
|
token={undefined}
|
||||||
fields={envelope.fields}
|
fields={envelope.fields}
|
||||||
recipientIds={envelope.recipients.map((recipient) => recipient.id)}
|
recipients={envelope.recipients}
|
||||||
>
|
>
|
||||||
<EnvelopeEditor />
|
<EnvelopeEditor />
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
|
|||||||
@ -170,8 +170,12 @@ export default function TemplatePage({ params }: Route.ComponentProps) {
|
|||||||
<div className="relative col-span-12 lg:col-span-6 xl:col-span-7">
|
<div className="relative col-span-12 lg:col-span-6 xl:col-span-7">
|
||||||
<EnvelopeRenderProvider
|
<EnvelopeRenderProvider
|
||||||
envelope={envelope}
|
envelope={envelope}
|
||||||
|
token={undefined}
|
||||||
fields={envelope.fields}
|
fields={envelope.fields}
|
||||||
recipientIds={envelope.recipients.map((recipient) => recipient.id)}
|
recipients={envelope.recipients}
|
||||||
|
overrideSettings={{
|
||||||
|
showRecipientTooltip: true,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{isMultiEnvelopeItem && (
|
{isMultiEnvelopeItem && (
|
||||||
<EnvelopeRendererFileSelector fields={envelope.fields} className="mb-4 p-0" />
|
<EnvelopeRendererFileSelector fields={envelope.fields} className="mb-4 p-0" />
|
||||||
@ -179,7 +183,10 @@ export default function TemplatePage({ params }: Route.ComponentProps) {
|
|||||||
|
|
||||||
<Card className="rounded-xl before:rounded-xl" gradient>
|
<Card className="rounded-xl before:rounded-xl" gradient>
|
||||||
<CardContent className="p-2">
|
<CardContent className="p-2">
|
||||||
<PDFViewerKonvaLazy customPageRenderer={EnvelopeGenericPageRenderer} />
|
<PDFViewerKonvaLazy
|
||||||
|
renderer="preview"
|
||||||
|
customPageRenderer={EnvelopeGenericPageRenderer}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
@ -200,9 +207,10 @@ export default function TemplatePage({ params }: Route.ComponentProps) {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<PDFViewer
|
<PDFViewer
|
||||||
document={envelope}
|
envelopeItem={envelope.envelopeItems[0]}
|
||||||
|
token={undefined}
|
||||||
|
version="signed"
|
||||||
key={envelope.envelopeItems[0].id}
|
key={envelope.envelopeItems[0].id}
|
||||||
documentData={envelope.envelopeItems[0].documentData}
|
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@ -245,7 +245,7 @@ const DirectSigningPageV2 = ({ data }: { data: Awaited<ReturnType<typeof handleV
|
|||||||
recipient={recipient}
|
recipient={recipient}
|
||||||
user={user}
|
user={user}
|
||||||
>
|
>
|
||||||
<EnvelopeRenderProvider envelope={envelope}>
|
<EnvelopeRenderProvider envelope={envelope} token={recipient.token}>
|
||||||
<DocumentSigningPageViewV2 />
|
<DocumentSigningPageViewV2 />
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
</DocumentSigningAuthProvider>
|
</DocumentSigningAuthProvider>
|
||||||
|
|||||||
@ -492,7 +492,7 @@ const SigningPageV2 = ({ data }: { data: Awaited<ReturnType<typeof handleV2Loade
|
|||||||
recipient={recipient}
|
recipient={recipient}
|
||||||
user={user}
|
user={user}
|
||||||
>
|
>
|
||||||
<EnvelopeRenderProvider envelope={envelope}>
|
<EnvelopeRenderProvider envelope={envelope} token={recipient.token}>
|
||||||
<DocumentSigningPageViewV2 />
|
<DocumentSigningPageViewV2 />
|
||||||
</EnvelopeRenderProvider>
|
</EnvelopeRenderProvider>
|
||||||
</DocumentSigningAuthProvider>
|
</DocumentSigningAuthProvider>
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { msg } from '@lingui/core/macro';
|
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
import { DocumentStatus, FieldType, RecipientRole } from '@prisma/client';
|
import { DocumentStatus, FieldType, RecipientRole } from '@prisma/client';
|
||||||
import { CheckCircle2, Clock8, FileSearch } from 'lucide-react';
|
import { CheckCircle2, Clock8, DownloadIcon } from 'lucide-react';
|
||||||
import { Link, useRevalidator } from 'react-router';
|
import { Link, useRevalidator } from 'react-router';
|
||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
@ -20,14 +19,13 @@ import { getUserByEmail } from '@documenso/lib/server-only/user/get-user-by-emai
|
|||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
import { env } from '@documenso/lib/utils/env';
|
import { env } from '@documenso/lib/utils/env';
|
||||||
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
import type { Document } from '@documenso/prisma/types/document-legacy-schema';
|
||||||
import DocumentDialog from '@documenso/ui/components/document/document-dialog';
|
|
||||||
import { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';
|
|
||||||
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';
|
||||||
import { SigningCard3D } from '@documenso/ui/components/signing-card';
|
import { SigningCard3D } from '@documenso/ui/components/signing-card';
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Badge } from '@documenso/ui/primitives/badge';
|
import { Badge } from '@documenso/ui/primitives/badge';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
|
|
||||||
|
import { EnvelopeDownloadDialog } from '~/components/dialogs/envelope-download-dialog';
|
||||||
import { ClaimAccount } from '~/components/general/claim-account';
|
import { ClaimAccount } from '~/components/general/claim-account';
|
||||||
import { DocumentSigningAuthPageView } from '~/components/general/document-signing/document-signing-auth-page';
|
import { DocumentSigningAuthPageView } from '~/components/general/document-signing/document-signing-auth-page';
|
||||||
|
|
||||||
@ -207,24 +205,16 @@ export default function CompletedSigningPage({ loaderData }: Route.ComponentProp
|
|||||||
<div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">
|
<div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">
|
||||||
<DocumentShareButton documentId={document.id} token={recipient.token} />
|
<DocumentShareButton documentId={document.id} token={recipient.token} />
|
||||||
|
|
||||||
{isDocumentCompleted(document.status) ? (
|
{isDocumentCompleted(document.status) && (
|
||||||
<DocumentDownloadButton
|
<EnvelopeDownloadDialog
|
||||||
className="flex-1"
|
envelopeId={document.envelopeId}
|
||||||
fileName={document.title}
|
envelopeStatus={document.status}
|
||||||
documentData={document.documentData}
|
envelopeItems={document.envelopeItems}
|
||||||
disabled={!isDocumentCompleted(document.status)}
|
token={recipient?.token}
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<DocumentDialog
|
|
||||||
documentData={document.documentData}
|
|
||||||
trigger={
|
trigger={
|
||||||
<Button
|
<Button type="button" variant="outline" className="flex-1">
|
||||||
className="text-[11px]"
|
<DownloadIcon className="mr-2 h-5 w-5" />
|
||||||
title={_(msg`Signatures will appear once the document has been completed`)}
|
<Trans>Download</Trans>
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<FileSearch className="mr-2 h-5 w-5" strokeWidth={1.7} />
|
|
||||||
<Trans>View Original Document</Trans>
|
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -60,6 +60,7 @@ export const loader = async ({ request, params: { slug } }: Route.LoaderArgs) =>
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
document,
|
document,
|
||||||
|
token: slug,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ export const loader = async ({ request, params: { slug } }: Route.LoaderArgs) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function SharePage() {
|
export default function SharePage() {
|
||||||
const { document } = useLoaderData<typeof loader>();
|
const { document, token } = useLoaderData<typeof loader>();
|
||||||
|
|
||||||
if (document) {
|
if (document) {
|
||||||
return (
|
return (
|
||||||
@ -86,6 +87,7 @@ export default function SharePage() {
|
|||||||
envelopeItems={document.envelopeItems}
|
envelopeItems={document.envelopeItems}
|
||||||
recipientCount={document.recipientCount}
|
recipientCount={document.recipientCount}
|
||||||
completedDate={document.completedAt ?? undefined}
|
completedDate={document.completedAt ?? undefined}
|
||||||
|
token={token}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import {
|
|||||||
} from '@documenso/lib/constants/auth';
|
} from '@documenso/lib/constants/auth';
|
||||||
|
|
||||||
import { EmbedAuthenticationRequired } from '~/components/embed/embed-authentication-required';
|
import { EmbedAuthenticationRequired } from '~/components/embed/embed-authentication-required';
|
||||||
|
import { EmbedDocumentCompleted } from '~/components/embed/embed-document-completed';
|
||||||
|
import { EmbedDocumentRejected } from '~/components/embed/embed-document-rejected';
|
||||||
import { EmbedDocumentWaitingForTurn } from '~/components/embed/embed-document-waiting-for-turn';
|
import { EmbedDocumentWaitingForTurn } from '~/components/embed/embed-document-waiting-for-turn';
|
||||||
import { EmbedPaywall } from '~/components/embed/embed-paywall';
|
import { EmbedPaywall } from '~/components/embed/embed-paywall';
|
||||||
|
|
||||||
@ -48,6 +50,8 @@ export function ErrorBoundary({ loaderData }: Route.ErrorBoundaryProps) {
|
|||||||
|
|
||||||
const error = useRouteError();
|
const error = useRouteError();
|
||||||
|
|
||||||
|
console.log({ routeError: error });
|
||||||
|
|
||||||
if (isRouteErrorResponse(error)) {
|
if (isRouteErrorResponse(error)) {
|
||||||
if (error.status === 401 && error.data.type === 'embed-authentication-required') {
|
if (error.status === 401 && error.data.type === 'embed-authentication-required') {
|
||||||
return (
|
return (
|
||||||
@ -68,6 +72,16 @@ export function ErrorBoundary({ loaderData }: Route.ErrorBoundaryProps) {
|
|||||||
if (error.status === 403 && error.data.type === 'embed-waiting-for-turn') {
|
if (error.status === 403 && error.data.type === 'embed-waiting-for-turn') {
|
||||||
return <EmbedDocumentWaitingForTurn />;
|
return <EmbedDocumentWaitingForTurn />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !: Not used at the moment, may be removed in the future.
|
||||||
|
if (error.status === 403 && error.data.type === 'embed-document-rejected') {
|
||||||
|
return <EmbedDocumentRejected />;
|
||||||
|
}
|
||||||
|
|
||||||
|
// !: Not used at the moment, may be removed in the future.
|
||||||
|
if (error.status === 403 && error.data.type === 'embed-document-completed') {
|
||||||
|
return <EmbedDocumentCompleted name={error.data.name} signature={error.data.signature} />;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div>Not Found</div>;
|
return <div>Not Found</div>;
|
||||||
|
|||||||
332
apps/remix/app/routes/embed+/_v0+/direct.$token.tsx
Normal file
332
apps/remix/app/routes/embed+/_v0+/direct.$token.tsx
Normal file
@ -0,0 +1,332 @@
|
|||||||
|
import { data } from 'react-router';
|
||||||
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
|
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
|
import { EnvelopeRenderProvider } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
||||||
|
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
|
import { getEnvelopeForDirectTemplateSigning } from '@documenso/lib/server-only/envelope/get-envelope-for-direct-template-signing';
|
||||||
|
import { getEnvelopeRequiredAccessData } from '@documenso/lib/server-only/envelope/get-envelope-required-access-data';
|
||||||
|
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
||||||
|
import { getTemplateByDirectLinkToken } from '@documenso/lib/server-only/template/get-template-by-direct-link-token';
|
||||||
|
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
||||||
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { EmbedDirectTemplateClientPage } from '~/components/embed/embed-direct-template-client-page';
|
||||||
|
import { EmbedSignDocumentV2ClientPage } from '~/components/embed/embed-document-signing-page-v2';
|
||||||
|
import { DocumentSigningAuthProvider } from '~/components/general/document-signing/document-signing-auth-provider';
|
||||||
|
import { DocumentSigningProvider } from '~/components/general/document-signing/document-signing-provider';
|
||||||
|
import { DocumentSigningRecipientProvider } from '~/components/general/document-signing/document-signing-recipient-provider';
|
||||||
|
import { EnvelopeSigningProvider } from '~/components/general/document-signing/envelope-signing-provider';
|
||||||
|
import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader';
|
||||||
|
|
||||||
|
import type { Route } from './+types/direct.$token';
|
||||||
|
|
||||||
|
async function handleV1Loader({ params, request }: Route.LoaderArgs) {
|
||||||
|
if (!params.token) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = params.token;
|
||||||
|
|
||||||
|
const template = await getTemplateByDirectLinkToken({
|
||||||
|
token,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
|
// `template.directLink` is always available but we're doing this to
|
||||||
|
// satisfy the type checker.
|
||||||
|
if (!template || !template.directLink) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: template.teamId });
|
||||||
|
|
||||||
|
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
||||||
|
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
||||||
|
|
||||||
|
// TODO: Make this more robust, we need to ensure the owner is either
|
||||||
|
// TODO: the member of a team that has an active subscription, is an early
|
||||||
|
// TODO: adopter or is an enterprise user.
|
||||||
|
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-paywall',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { user } = await getOptionalSession(request);
|
||||||
|
|
||||||
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
|
documentAuth: template.authOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isAccessAuthValid = derivedRecipientAccessAuth.every((auth) =>
|
||||||
|
match(auth)
|
||||||
|
.with(DocumentAccessAuth.ACCOUNT, () => !!user)
|
||||||
|
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => false) // Not supported for direct links
|
||||||
|
.exhaustive(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAccessAuthValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: user?.email,
|
||||||
|
returnTo: `/embed/direct/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { directTemplateRecipientId } = template.directLink;
|
||||||
|
|
||||||
|
const recipient = template.recipients.find(
|
||||||
|
(recipient) => recipient.id === directTemplateRecipientId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!recipient) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const fields = template.fields.filter((field) => field.recipientId === directTemplateRecipientId);
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
template,
|
||||||
|
recipient,
|
||||||
|
fields,
|
||||||
|
hidePoweredBy,
|
||||||
|
allowEmbedSigningWhitelabel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleV2Loader({ params, request }: Route.LoaderArgs) {
|
||||||
|
if (!params.token) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = params.token;
|
||||||
|
|
||||||
|
const { user } = await getOptionalSession(request);
|
||||||
|
|
||||||
|
const envelopeForSigning = await getEnvelopeForDirectTemplateSigning({
|
||||||
|
token,
|
||||||
|
userId: user?.id,
|
||||||
|
})
|
||||||
|
.then((envelopeForSigning) => {
|
||||||
|
return {
|
||||||
|
isDocumentAccessValid: true,
|
||||||
|
...envelopeForSigning,
|
||||||
|
} as const;
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
const error = AppError.parseError(e);
|
||||||
|
|
||||||
|
if (error.code === AppErrorCode.UNAUTHORIZED) {
|
||||||
|
const requiredAccessData = await getEnvelopeRequiredAccessData({ token });
|
||||||
|
|
||||||
|
return {
|
||||||
|
isDocumentAccessValid: false,
|
||||||
|
...requiredAccessData,
|
||||||
|
} as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelopeForSigning.isDocumentAccessValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: envelopeForSigning.recipientEmail,
|
||||||
|
returnTo: `/embed/direct/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { envelope, recipient } = envelopeForSigning;
|
||||||
|
|
||||||
|
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: envelope.teamId });
|
||||||
|
|
||||||
|
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
||||||
|
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
||||||
|
|
||||||
|
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-paywall',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
|
documentAuth: envelope.authOptions,
|
||||||
|
recipientAuth: recipient.authOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isAccessAuthValid = derivedRecipientAccessAuth.every((accesssAuth) =>
|
||||||
|
match(accesssAuth)
|
||||||
|
.with(DocumentAccessAuth.ACCOUNT, () => user && user.email === recipient.email)
|
||||||
|
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => false) // Not supported for direct links
|
||||||
|
.exhaustive(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAccessAuthValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: user?.email || recipient.email,
|
||||||
|
returnTo: `/embed/direct/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
envelopeForSigning,
|
||||||
|
hidePoweredBy,
|
||||||
|
allowEmbedSigningWhitelabel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loader(loaderArgs: Route.LoaderArgs) {
|
||||||
|
const { token } = loaderArgs.params;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not efficient but works for now until we remove v1.
|
||||||
|
const foundDirectLink = await prisma.templateDirectLink.findFirst({
|
||||||
|
where: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
envelope: {
|
||||||
|
select: {
|
||||||
|
internalVersion: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!foundDirectLink) {
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundDirectLink.envelope.internalVersion === 2) {
|
||||||
|
const payloadV2 = await handleV2Loader(loaderArgs);
|
||||||
|
|
||||||
|
return superLoaderJson({
|
||||||
|
version: 2,
|
||||||
|
payload: payloadV2,
|
||||||
|
} as const);
|
||||||
|
}
|
||||||
|
|
||||||
|
const payloadV1 = await handleV1Loader(loaderArgs);
|
||||||
|
|
||||||
|
return superLoaderJson({
|
||||||
|
version: 1,
|
||||||
|
payload: payloadV1,
|
||||||
|
} as const);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EmbedDirectTemplatePage() {
|
||||||
|
const { version, payload } = useSuperLoaderData<typeof loader>();
|
||||||
|
|
||||||
|
if (version === 1) {
|
||||||
|
return <EmbedDirectTemplatePageV1 data={payload} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <EmbedDirectTemplatePageV2 data={payload} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EmbedDirectTemplatePageV1 = ({
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
data: Awaited<ReturnType<typeof handleV1Loader>>;
|
||||||
|
}) => {
|
||||||
|
const { token, user, template, recipient, fields, hidePoweredBy, allowEmbedSigningWhitelabel } =
|
||||||
|
data;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DocumentSigningProvider
|
||||||
|
email={user?.email}
|
||||||
|
fullName={user?.name}
|
||||||
|
signature={user?.signature}
|
||||||
|
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
||||||
|
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
||||||
|
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
||||||
|
>
|
||||||
|
<DocumentSigningAuthProvider
|
||||||
|
documentAuthOptions={template.authOptions}
|
||||||
|
recipient={recipient}
|
||||||
|
user={user}
|
||||||
|
>
|
||||||
|
<DocumentSigningRecipientProvider recipient={recipient}>
|
||||||
|
<EmbedDirectTemplateClientPage
|
||||||
|
token={token}
|
||||||
|
envelopeId={template.envelopeId}
|
||||||
|
updatedAt={template.updatedAt}
|
||||||
|
envelopeItems={template.envelopeItems}
|
||||||
|
recipient={recipient}
|
||||||
|
fields={fields}
|
||||||
|
metadata={template.templateMeta}
|
||||||
|
hidePoweredBy={hidePoweredBy}
|
||||||
|
allowWhiteLabelling={allowEmbedSigningWhitelabel}
|
||||||
|
/>
|
||||||
|
</DocumentSigningRecipientProvider>
|
||||||
|
</DocumentSigningAuthProvider>
|
||||||
|
</DocumentSigningProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmbedDirectTemplatePageV2 = ({
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
data: Awaited<ReturnType<typeof handleV2Loader>>;
|
||||||
|
}) => {
|
||||||
|
const { token, user, envelopeForSigning, hidePoweredBy, allowEmbedSigningWhitelabel } = data;
|
||||||
|
|
||||||
|
const { envelope, recipient } = envelopeForSigning;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EnvelopeSigningProvider
|
||||||
|
envelopeData={envelopeForSigning}
|
||||||
|
email={user?.email}
|
||||||
|
fullName={user?.name}
|
||||||
|
signature={user?.signature}
|
||||||
|
>
|
||||||
|
<DocumentSigningAuthProvider
|
||||||
|
documentAuthOptions={envelope.authOptions}
|
||||||
|
recipient={recipient}
|
||||||
|
user={user}
|
||||||
|
>
|
||||||
|
<EnvelopeRenderProvider envelope={envelope} token={recipient.token}>
|
||||||
|
<EmbedSignDocumentV2ClientPage
|
||||||
|
hidePoweredBy={hidePoweredBy}
|
||||||
|
allowWhitelabelling={allowEmbedSigningWhitelabel}
|
||||||
|
/>
|
||||||
|
</EnvelopeRenderProvider>
|
||||||
|
</DocumentSigningAuthProvider>
|
||||||
|
</EnvelopeSigningProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -1,138 +0,0 @@
|
|||||||
import { data } from 'react-router';
|
|
||||||
import { match } from 'ts-pattern';
|
|
||||||
|
|
||||||
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
|
||||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
|
||||||
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
|
||||||
import { getTemplateByDirectLinkToken } from '@documenso/lib/server-only/template/get-template-by-direct-link-token';
|
|
||||||
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
|
||||||
|
|
||||||
import { EmbedDirectTemplateClientPage } from '~/components/embed/embed-direct-template-client-page';
|
|
||||||
import { DocumentSigningAuthProvider } from '~/components/general/document-signing/document-signing-auth-provider';
|
|
||||||
import { DocumentSigningProvider } from '~/components/general/document-signing/document-signing-provider';
|
|
||||||
import { DocumentSigningRecipientProvider } from '~/components/general/document-signing/document-signing-recipient-provider';
|
|
||||||
import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader';
|
|
||||||
|
|
||||||
import type { Route } from './+types/direct.$url';
|
|
||||||
|
|
||||||
export async function loader({ params, request }: Route.LoaderArgs) {
|
|
||||||
if (!params.url) {
|
|
||||||
throw new Response('Not found', { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = params.url;
|
|
||||||
|
|
||||||
const template = await getTemplateByDirectLinkToken({
|
|
||||||
token,
|
|
||||||
}).catch(() => null);
|
|
||||||
|
|
||||||
// `template.directLink` is always available but we're doing this to
|
|
||||||
// satisfy the type checker.
|
|
||||||
if (!template || !template.directLink) {
|
|
||||||
throw new Response('Not found', { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: template.teamId });
|
|
||||||
|
|
||||||
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
|
||||||
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
|
||||||
|
|
||||||
// TODO: Make this more robust, we need to ensure the owner is either
|
|
||||||
// TODO: the member of a team that has an active subscription, is an early
|
|
||||||
// TODO: adopter or is an enterprise user.
|
|
||||||
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
|
||||||
throw data(
|
|
||||||
{
|
|
||||||
type: 'embed-paywall',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 403,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { user } = await getOptionalSession(request);
|
|
||||||
|
|
||||||
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
|
||||||
documentAuth: template.authOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isAccessAuthValid = derivedRecipientAccessAuth.every((auth) =>
|
|
||||||
match(auth)
|
|
||||||
.with(DocumentAccessAuth.ACCOUNT, () => !!user)
|
|
||||||
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => false) // Not supported for direct links
|
|
||||||
.exhaustive(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isAccessAuthValid) {
|
|
||||||
throw data(
|
|
||||||
{
|
|
||||||
type: 'embed-authentication-required',
|
|
||||||
email: user?.email,
|
|
||||||
returnTo: `/embed/direct/${token}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { directTemplateRecipientId } = template.directLink;
|
|
||||||
|
|
||||||
const recipient = template.recipients.find(
|
|
||||||
(recipient) => recipient.id === directTemplateRecipientId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!recipient) {
|
|
||||||
throw new Response('Not found', { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const fields = template.fields.filter((field) => field.recipientId === directTemplateRecipientId);
|
|
||||||
|
|
||||||
return superLoaderJson({
|
|
||||||
token,
|
|
||||||
user,
|
|
||||||
template,
|
|
||||||
recipient,
|
|
||||||
fields,
|
|
||||||
hidePoweredBy,
|
|
||||||
allowEmbedSigningWhitelabel,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function EmbedDirectTemplatePage() {
|
|
||||||
const { token, user, template, recipient, fields, hidePoweredBy, allowEmbedSigningWhitelabel } =
|
|
||||||
useSuperLoaderData<typeof loader>();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DocumentSigningProvider
|
|
||||||
email={user?.email}
|
|
||||||
fullName={user?.name}
|
|
||||||
signature={user?.signature}
|
|
||||||
typedSignatureEnabled={template.templateMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={template.templateMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={template.templateMeta?.drawSignatureEnabled}
|
|
||||||
>
|
|
||||||
<DocumentSigningAuthProvider
|
|
||||||
documentAuthOptions={template.authOptions}
|
|
||||||
recipient={recipient}
|
|
||||||
user={user}
|
|
||||||
>
|
|
||||||
<DocumentSigningRecipientProvider recipient={recipient}>
|
|
||||||
<EmbedDirectTemplateClientPage
|
|
||||||
token={token}
|
|
||||||
envelopeId={template.envelopeId}
|
|
||||||
updatedAt={template.updatedAt}
|
|
||||||
documentData={template.templateDocumentData}
|
|
||||||
recipient={recipient}
|
|
||||||
fields={fields}
|
|
||||||
metadata={template.templateMeta}
|
|
||||||
hidePoweredBy={hidePoweredBy}
|
|
||||||
allowWhiteLabelling={allowEmbedSigningWhitelabel}
|
|
||||||
/>
|
|
||||||
</DocumentSigningRecipientProvider>
|
|
||||||
</DocumentSigningAuthProvider>
|
|
||||||
</DocumentSigningProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
394
apps/remix/app/routes/embed+/_v0+/sign.$token.tsx
Normal file
394
apps/remix/app/routes/embed+/_v0+/sign.$token.tsx
Normal file
@ -0,0 +1,394 @@
|
|||||||
|
import { RecipientRole } from '@prisma/client';
|
||||||
|
import { data } from 'react-router';
|
||||||
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
|
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
|
import { EnvelopeRenderProvider } from '@documenso/lib/client-only/providers/envelope-render-provider';
|
||||||
|
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
|
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
||||||
|
import { viewedDocument } from '@documenso/lib/server-only/document/viewed-document';
|
||||||
|
import { getEnvelopeForRecipientSigning } from '@documenso/lib/server-only/envelope/get-envelope-for-recipient-signing';
|
||||||
|
import { getEnvelopeRequiredAccessData } from '@documenso/lib/server-only/envelope/get-envelope-required-access-data';
|
||||||
|
import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get-completed-fields-for-token';
|
||||||
|
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
||||||
|
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
||||||
|
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
||||||
|
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
||||||
|
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
||||||
|
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
||||||
|
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
||||||
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { EmbedSignDocumentV1ClientPage } from '~/components/embed/embed-document-signing-page-v1';
|
||||||
|
import { EmbedSignDocumentV2ClientPage } from '~/components/embed/embed-document-signing-page-v2';
|
||||||
|
import { DocumentSigningAuthProvider } from '~/components/general/document-signing/document-signing-auth-provider';
|
||||||
|
import { DocumentSigningProvider } from '~/components/general/document-signing/document-signing-provider';
|
||||||
|
import { EnvelopeSigningProvider } from '~/components/general/document-signing/envelope-signing-provider';
|
||||||
|
import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader';
|
||||||
|
|
||||||
|
import { getOptionalLoaderContext } from '../../../../server/utils/get-loader-session';
|
||||||
|
import type { Route } from './+types/sign.$token';
|
||||||
|
|
||||||
|
async function handleV1Loader({ params, request }: Route.LoaderArgs) {
|
||||||
|
const { requestMetadata } = getOptionalLoaderContext();
|
||||||
|
|
||||||
|
if (!params.token) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = params.token;
|
||||||
|
|
||||||
|
const { user } = await getOptionalSession(request);
|
||||||
|
|
||||||
|
const [document, fields, recipient, completedFields] = await Promise.all([
|
||||||
|
getDocumentAndSenderByToken({
|
||||||
|
token,
|
||||||
|
userId: user?.id,
|
||||||
|
requireAccessAuth: false,
|
||||||
|
}).catch(() => null),
|
||||||
|
getFieldsForToken({ token }),
|
||||||
|
getRecipientByToken({ token }).catch(() => null),
|
||||||
|
getCompletedFieldsForToken({ token }).catch(() => []),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// `document.directLink` is always available but we're doing this to
|
||||||
|
// satisfy the type checker.
|
||||||
|
if (!document || !recipient) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: document.teamId });
|
||||||
|
|
||||||
|
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
||||||
|
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
||||||
|
|
||||||
|
// TODO: Make this more robust, we need to ensure the owner is either
|
||||||
|
// TODO: the member of a team that has an active subscription, is an early
|
||||||
|
// TODO: adopter or is an enterprise user.
|
||||||
|
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-paywall',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
|
documentAuth: document.authOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isAccessAuthValid = derivedRecipientAccessAuth.every((accesssAuth) =>
|
||||||
|
match(accesssAuth)
|
||||||
|
.with(DocumentAccessAuth.ACCOUNT, () => user && user.email === recipient.email)
|
||||||
|
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => true) // Allow without account requirement
|
||||||
|
.exhaustive(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAccessAuthValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: user?.email || recipient.email,
|
||||||
|
returnTo: `/embed/sign/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isRecipientsTurnToSign = await getIsRecipientsTurnToSign({ token });
|
||||||
|
|
||||||
|
if (!isRecipientsTurnToSign) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-waiting-for-turn',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await viewedDocument({
|
||||||
|
token,
|
||||||
|
requestMetadata,
|
||||||
|
recipientAccessAuth: derivedRecipientAccessAuth,
|
||||||
|
});
|
||||||
|
|
||||||
|
const allRecipients =
|
||||||
|
recipient.role === RecipientRole.ASSISTANT
|
||||||
|
? await getRecipientsForAssistant({
|
||||||
|
token,
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
document,
|
||||||
|
allRecipients,
|
||||||
|
recipient,
|
||||||
|
fields,
|
||||||
|
completedFields,
|
||||||
|
hidePoweredBy,
|
||||||
|
allowEmbedSigningWhitelabel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleV2Loader({ params, request }: Route.LoaderArgs) {
|
||||||
|
const { requestMetadata } = getOptionalLoaderContext();
|
||||||
|
|
||||||
|
if (!params.token) {
|
||||||
|
throw new Response('Not found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = params.token;
|
||||||
|
|
||||||
|
const { user } = await getOptionalSession(request);
|
||||||
|
|
||||||
|
const envelopeForSigning = await getEnvelopeForRecipientSigning({
|
||||||
|
token,
|
||||||
|
userId: user?.id,
|
||||||
|
})
|
||||||
|
.then((envelopeForSigning) => {
|
||||||
|
return {
|
||||||
|
isDocumentAccessValid: true,
|
||||||
|
...envelopeForSigning,
|
||||||
|
} as const;
|
||||||
|
})
|
||||||
|
.catch(async (e) => {
|
||||||
|
const error = AppError.parseError(e);
|
||||||
|
|
||||||
|
if (error.code === AppErrorCode.UNAUTHORIZED) {
|
||||||
|
const requiredAccessData = await getEnvelopeRequiredAccessData({ token });
|
||||||
|
|
||||||
|
return {
|
||||||
|
isDocumentAccessValid: false,
|
||||||
|
...requiredAccessData,
|
||||||
|
} as const;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelopeForSigning.isDocumentAccessValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: envelopeForSigning.recipientEmail,
|
||||||
|
returnTo: `/embed/sign/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { envelope, recipient, isRecipientsTurn } = envelopeForSigning;
|
||||||
|
|
||||||
|
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: envelope.teamId });
|
||||||
|
|
||||||
|
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
||||||
|
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
||||||
|
|
||||||
|
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-paywall',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isRecipientsTurn) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-waiting-for-turn',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 403,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
||||||
|
documentAuth: envelope.authOptions,
|
||||||
|
recipientAuth: recipient.authOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isAccessAuthValid = derivedRecipientAccessAuth.every((accesssAuth) =>
|
||||||
|
match(accesssAuth)
|
||||||
|
.with(DocumentAccessAuth.ACCOUNT, () => user && user.email === recipient.email)
|
||||||
|
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => true)
|
||||||
|
.exhaustive(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!isAccessAuthValid) {
|
||||||
|
throw data(
|
||||||
|
{
|
||||||
|
type: 'embed-authentication-required',
|
||||||
|
email: user?.email || recipient.email,
|
||||||
|
returnTo: `/embed/sign/${token}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 401,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await viewedDocument({
|
||||||
|
token,
|
||||||
|
requestMetadata,
|
||||||
|
recipientAccessAuth: derivedRecipientAccessAuth,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
|
return {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
envelopeForSigning,
|
||||||
|
hidePoweredBy,
|
||||||
|
allowEmbedSigningWhitelabel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loader(loaderArgs: Route.LoaderArgs) {
|
||||||
|
const { token } = loaderArgs.params;
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not efficient but works for now until we remove v1.
|
||||||
|
const foundRecipient = await prisma.recipient.findFirst({
|
||||||
|
where: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
envelope: {
|
||||||
|
select: {
|
||||||
|
internalVersion: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!foundRecipient) {
|
||||||
|
throw new Response('Not Found', { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundRecipient.envelope.internalVersion === 2) {
|
||||||
|
const payloadV2 = await handleV2Loader(loaderArgs);
|
||||||
|
|
||||||
|
return superLoaderJson({
|
||||||
|
version: 2,
|
||||||
|
payload: payloadV2,
|
||||||
|
} as const);
|
||||||
|
}
|
||||||
|
|
||||||
|
const payloadV1 = await handleV1Loader(loaderArgs);
|
||||||
|
|
||||||
|
return superLoaderJson({
|
||||||
|
version: 1,
|
||||||
|
payload: payloadV1,
|
||||||
|
} as const);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EmbedSignDocumentPage() {
|
||||||
|
const { version, payload } = useSuperLoaderData<typeof loader>();
|
||||||
|
|
||||||
|
if (version === 1) {
|
||||||
|
return <EmbedSignDocumentPageV1 data={payload} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <EmbedSignDocumentPageV2 data={payload} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EmbedSignDocumentPageV1 = ({
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
data: Awaited<ReturnType<typeof handleV1Loader>>;
|
||||||
|
}) => {
|
||||||
|
const {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
document,
|
||||||
|
allRecipients,
|
||||||
|
recipient,
|
||||||
|
fields,
|
||||||
|
completedFields,
|
||||||
|
hidePoweredBy,
|
||||||
|
allowEmbedSigningWhitelabel,
|
||||||
|
} = data;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DocumentSigningProvider
|
||||||
|
email={recipient.email}
|
||||||
|
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
||||||
|
signature={user?.email === recipient.email ? user?.signature : undefined}
|
||||||
|
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
||||||
|
uploadSignatureEnabled={document.documentMeta?.uploadSignatureEnabled}
|
||||||
|
drawSignatureEnabled={document.documentMeta?.drawSignatureEnabled}
|
||||||
|
>
|
||||||
|
<DocumentSigningAuthProvider
|
||||||
|
documentAuthOptions={document.authOptions}
|
||||||
|
recipient={recipient}
|
||||||
|
user={user}
|
||||||
|
>
|
||||||
|
<EmbedSignDocumentV1ClientPage
|
||||||
|
token={token}
|
||||||
|
documentId={document.id}
|
||||||
|
envelopeId={document.envelopeId}
|
||||||
|
envelopeItems={document.envelopeItems}
|
||||||
|
recipient={recipient}
|
||||||
|
fields={fields}
|
||||||
|
completedFields={completedFields}
|
||||||
|
metadata={document.documentMeta}
|
||||||
|
isCompleted={isDocumentCompleted(document.status)}
|
||||||
|
hidePoweredBy={hidePoweredBy}
|
||||||
|
allowWhitelabelling={allowEmbedSigningWhitelabel}
|
||||||
|
allRecipients={allRecipients}
|
||||||
|
/>
|
||||||
|
</DocumentSigningAuthProvider>
|
||||||
|
</DocumentSigningProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const EmbedSignDocumentPageV2 = ({
|
||||||
|
data,
|
||||||
|
}: {
|
||||||
|
data: Awaited<ReturnType<typeof handleV2Loader>>;
|
||||||
|
}) => {
|
||||||
|
const { token, user, envelopeForSigning, hidePoweredBy, allowEmbedSigningWhitelabel } = data;
|
||||||
|
|
||||||
|
const { envelope, recipient } = envelopeForSigning;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<EnvelopeSigningProvider
|
||||||
|
envelopeData={envelopeForSigning}
|
||||||
|
email={recipient.email}
|
||||||
|
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
||||||
|
signature={user?.email === recipient.email ? user?.signature : undefined}
|
||||||
|
>
|
||||||
|
<DocumentSigningAuthProvider
|
||||||
|
documentAuthOptions={envelope.authOptions}
|
||||||
|
recipient={recipient}
|
||||||
|
user={user}
|
||||||
|
>
|
||||||
|
<EnvelopeRenderProvider envelope={envelope} token={token}>
|
||||||
|
<EmbedSignDocumentV2ClientPage
|
||||||
|
hidePoweredBy={hidePoweredBy}
|
||||||
|
allowWhitelabelling={allowEmbedSigningWhitelabel}
|
||||||
|
/>
|
||||||
|
</EnvelopeRenderProvider>
|
||||||
|
</DocumentSigningAuthProvider>
|
||||||
|
</EnvelopeSigningProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -1,181 +0,0 @@
|
|||||||
import { RecipientRole } from '@prisma/client';
|
|
||||||
import { data } from 'react-router';
|
|
||||||
import { getOptionalLoaderContext } from 'server/utils/get-loader-session';
|
|
||||||
import { match } from 'ts-pattern';
|
|
||||||
|
|
||||||
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
|
||||||
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
|
||||||
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
|
||||||
import { viewedDocument } from '@documenso/lib/server-only/document/viewed-document';
|
|
||||||
import { getCompletedFieldsForToken } from '@documenso/lib/server-only/field/get-completed-fields-for-token';
|
|
||||||
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
|
|
||||||
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
|
|
||||||
import { getIsRecipientsTurnToSign } from '@documenso/lib/server-only/recipient/get-is-recipient-turn';
|
|
||||||
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
|
|
||||||
import { getRecipientsForAssistant } from '@documenso/lib/server-only/recipient/get-recipients-for-assistant';
|
|
||||||
import { DocumentAccessAuth } from '@documenso/lib/types/document-auth';
|
|
||||||
import { isDocumentCompleted } from '@documenso/lib/utils/document';
|
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
|
||||||
|
|
||||||
import { EmbedSignDocumentClientPage } from '~/components/embed/embed-document-signing-page';
|
|
||||||
import { DocumentSigningAuthProvider } from '~/components/general/document-signing/document-signing-auth-provider';
|
|
||||||
import { DocumentSigningProvider } from '~/components/general/document-signing/document-signing-provider';
|
|
||||||
import { superLoaderJson, useSuperLoaderData } from '~/utils/super-json-loader';
|
|
||||||
|
|
||||||
import type { Route } from './+types/sign.$url';
|
|
||||||
|
|
||||||
export async function loader({ params, request }: Route.LoaderArgs) {
|
|
||||||
const { requestMetadata } = getOptionalLoaderContext();
|
|
||||||
|
|
||||||
if (!params.url) {
|
|
||||||
throw new Response('Not found', { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = params.url;
|
|
||||||
|
|
||||||
const { user } = await getOptionalSession(request);
|
|
||||||
|
|
||||||
const [document, fields, recipient, completedFields] = await Promise.all([
|
|
||||||
getDocumentAndSenderByToken({
|
|
||||||
token,
|
|
||||||
userId: user?.id,
|
|
||||||
requireAccessAuth: false,
|
|
||||||
}).catch(() => null),
|
|
||||||
getFieldsForToken({ token }),
|
|
||||||
getRecipientByToken({ token }).catch(() => null),
|
|
||||||
getCompletedFieldsForToken({ token }).catch(() => []),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// `document.directLink` is always available but we're doing this to
|
|
||||||
// satisfy the type checker.
|
|
||||||
if (!document || !recipient) {
|
|
||||||
throw new Response('Not found', { status: 404 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: document.teamId });
|
|
||||||
|
|
||||||
const allowEmbedSigningWhitelabel = organisationClaim.flags.embedSigningWhiteLabel;
|
|
||||||
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
|
|
||||||
|
|
||||||
// TODO: Make this more robust, we need to ensure the owner is either
|
|
||||||
// TODO: the member of a team that has an active subscription, is an early
|
|
||||||
// TODO: adopter or is an enterprise user.
|
|
||||||
if (IS_BILLING_ENABLED() && !organisationClaim.flags.embedSigning) {
|
|
||||||
throw data(
|
|
||||||
{
|
|
||||||
type: 'embed-paywall',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 403,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { derivedRecipientAccessAuth } = extractDocumentAuthMethods({
|
|
||||||
documentAuth: document.authOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isAccessAuthValid = derivedRecipientAccessAuth.every((accesssAuth) =>
|
|
||||||
match(accesssAuth)
|
|
||||||
.with(DocumentAccessAuth.ACCOUNT, () => user && user.email === recipient.email)
|
|
||||||
.with(DocumentAccessAuth.TWO_FACTOR_AUTH, () => true) // Allow without account requirement
|
|
||||||
.exhaustive(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isAccessAuthValid) {
|
|
||||||
throw data(
|
|
||||||
{
|
|
||||||
type: 'embed-authentication-required',
|
|
||||||
email: user?.email || recipient.email,
|
|
||||||
returnTo: `/embed/sign/${token}`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const isRecipientsTurnToSign = await getIsRecipientsTurnToSign({ token });
|
|
||||||
|
|
||||||
if (!isRecipientsTurnToSign) {
|
|
||||||
throw data(
|
|
||||||
{
|
|
||||||
type: 'embed-waiting-for-turn',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: 403,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await viewedDocument({
|
|
||||||
token,
|
|
||||||
requestMetadata,
|
|
||||||
recipientAccessAuth: derivedRecipientAccessAuth,
|
|
||||||
});
|
|
||||||
|
|
||||||
const allRecipients =
|
|
||||||
recipient.role === RecipientRole.ASSISTANT
|
|
||||||
? await getRecipientsForAssistant({
|
|
||||||
token,
|
|
||||||
})
|
|
||||||
: [];
|
|
||||||
|
|
||||||
return superLoaderJson({
|
|
||||||
token,
|
|
||||||
user,
|
|
||||||
document,
|
|
||||||
allRecipients,
|
|
||||||
recipient,
|
|
||||||
fields,
|
|
||||||
completedFields,
|
|
||||||
hidePoweredBy,
|
|
||||||
allowEmbedSigningWhitelabel,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function EmbedSignDocumentPage() {
|
|
||||||
const {
|
|
||||||
token,
|
|
||||||
user,
|
|
||||||
document,
|
|
||||||
allRecipients,
|
|
||||||
recipient,
|
|
||||||
fields,
|
|
||||||
completedFields,
|
|
||||||
hidePoweredBy,
|
|
||||||
allowEmbedSigningWhitelabel,
|
|
||||||
} = useSuperLoaderData<typeof loader>();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DocumentSigningProvider
|
|
||||||
email={recipient.email}
|
|
||||||
fullName={user?.email === recipient.email ? user?.name : recipient.name}
|
|
||||||
signature={user?.email === recipient.email ? user?.signature : undefined}
|
|
||||||
typedSignatureEnabled={document.documentMeta?.typedSignatureEnabled}
|
|
||||||
uploadSignatureEnabled={document.documentMeta?.uploadSignatureEnabled}
|
|
||||||
drawSignatureEnabled={document.documentMeta?.drawSignatureEnabled}
|
|
||||||
>
|
|
||||||
<DocumentSigningAuthProvider
|
|
||||||
documentAuthOptions={document.authOptions}
|
|
||||||
recipient={recipient}
|
|
||||||
user={user}
|
|
||||||
>
|
|
||||||
<EmbedSignDocumentClientPage
|
|
||||||
token={token}
|
|
||||||
documentId={document.id}
|
|
||||||
envelopeId={document.envelopeId}
|
|
||||||
documentData={document.documentData}
|
|
||||||
recipient={recipient}
|
|
||||||
fields={fields}
|
|
||||||
completedFields={completedFields}
|
|
||||||
metadata={document.documentMeta}
|
|
||||||
isCompleted={isDocumentCompleted(document.status)}
|
|
||||||
hidePoweredBy={hidePoweredBy}
|
|
||||||
allowWhitelabelling={allowEmbedSigningWhitelabel}
|
|
||||||
allRecipients={allRecipients}
|
|
||||||
/>
|
|
||||||
</DocumentSigningAuthProvider>
|
|
||||||
</DocumentSigningProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@ -67,6 +67,7 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|||||||
export default function MultisignPage() {
|
export default function MultisignPage() {
|
||||||
const { envelopes, user, hidePoweredBy, allowWhitelabelling } =
|
const { envelopes, user, hidePoweredBy, allowWhitelabelling } =
|
||||||
useSuperLoaderData<typeof loader>();
|
useSuperLoaderData<typeof loader>();
|
||||||
|
|
||||||
const revalidator = useRevalidator();
|
const revalidator = useRevalidator();
|
||||||
|
|
||||||
const [selectedDocument, setSelectedDocument] = useState<
|
const [selectedDocument, setSelectedDocument] = useState<
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { FieldType } from '@prisma/client';
|
import { FieldType } from '@prisma/client';
|
||||||
|
|
||||||
|
import { validateCheckboxLength } from '@documenso/lib/advanced-fields-validation/validate-checkbox';
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import type { TFieldCheckbox } from '@documenso/lib/types/field';
|
import type { TFieldCheckbox } from '@documenso/lib/types/field';
|
||||||
import { parseCheckboxCustomText } from '@documenso/lib/utils/fields';
|
import { parseCheckboxCustomText } from '@documenso/lib/utils/fields';
|
||||||
@ -44,6 +45,13 @@ export const handleCheckboxFieldClick = async (
|
|||||||
|
|
||||||
let checkedValues: number[] | null = newValues.filter((v) => v.isChecked).map((v) => v.index);
|
let checkedValues: number[] | null = newValues.filter((v) => v.isChecked).map((v) => v.index);
|
||||||
|
|
||||||
|
if (checkedValues.length === 0) {
|
||||||
|
return {
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
value: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (validationRule && validationLength) {
|
if (validationRule && validationLength) {
|
||||||
const checkboxValidationRule = checkboxValidationSigns.find(
|
const checkboxValidationRule = checkboxValidationSigns.find(
|
||||||
(sign) => sign.label === validationRule,
|
(sign) => sign.label === validationRule,
|
||||||
@ -55,13 +63,34 @@ export const handleCheckboxFieldClick = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Custom logic to make it flow better.
|
||||||
|
// If "at most" OR "exactly" 1 value then just return the new selected value if exists.
|
||||||
|
if (
|
||||||
|
(checkboxValidationRule.value === '=' || checkboxValidationRule.value === '<=') &&
|
||||||
|
validationLength === 1
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
value: [clickedCheckboxIndex],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const isValid = validateCheckboxLength(
|
||||||
|
checkedValues.length,
|
||||||
|
checkboxValidationRule.value,
|
||||||
|
validationLength,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only render validation dialog if validation is invalid.
|
||||||
|
if (!isValid) {
|
||||||
checkedValues = await SignFieldCheckboxDialog.call({
|
checkedValues = await SignFieldCheckboxDialog.call({
|
||||||
fieldMeta: field.fieldMeta,
|
fieldMeta: field.fieldMeta,
|
||||||
validationRule: checkboxValidationRule.value,
|
validationRule: checkboxValidationRule.value,
|
||||||
validationLength,
|
validationLength,
|
||||||
preselectedIndices: currentCheckedIndices,
|
preselectedIndices: checkedValues,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!checkedValues) {
|
if (!checkedValues) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
"@documenso/trpc": "*",
|
"@documenso/trpc": "*",
|
||||||
"@documenso/ui": "*",
|
"@documenso/ui": "*",
|
||||||
"@epic-web/remember": "^1.1.0",
|
"@epic-web/remember": "^1.1.0",
|
||||||
|
"@faker-js/faker": "^10.1.0",
|
||||||
"@hono/node-server": "^1.13.7",
|
"@hono/node-server": "^1.13.7",
|
||||||
"@hono/trpc-server": "^0.3.4",
|
"@hono/trpc-server": "^0.3.4",
|
||||||
"@hookform/resolvers": "^3.1.0",
|
"@hookform/resolvers": "^3.1.0",
|
||||||
|
|||||||
192
apps/remix/server/api/download/download.ts
Normal file
192
apps/remix/server/api/download/download.ts
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
import { sValidator } from '@hono/standard-validator';
|
||||||
|
import { EnvelopeType } from '@prisma/client';
|
||||||
|
import { Hono } from 'hono';
|
||||||
|
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
|
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
|
import { getApiTokenByToken } from '@documenso/lib/server-only/public-api/get-api-token-by-token';
|
||||||
|
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import type { HonoEnv } from '../../router';
|
||||||
|
import { handleEnvelopeItemFileRequest } from '../files/files.helpers';
|
||||||
|
import {
|
||||||
|
ZDownloadDocumentRequestParamsSchema,
|
||||||
|
ZDownloadEnvelopeItemRequestParamsSchema,
|
||||||
|
} from './download.types';
|
||||||
|
|
||||||
|
export const downloadRoute = new Hono<HonoEnv>()
|
||||||
|
/**
|
||||||
|
* Download an envelope item by its ID.
|
||||||
|
* Requires API key authentication via Authorization header.
|
||||||
|
*/
|
||||||
|
.get(
|
||||||
|
'/envelopeItem/:envelopeItemId/download',
|
||||||
|
sValidator('param', ZDownloadEnvelopeItemRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const logger = c.get('logger');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { envelopeItemId, version } = c.req.valid('param');
|
||||||
|
const authorizationHeader = c.req.header('authorization');
|
||||||
|
|
||||||
|
// Support for both "Authorization: Bearer api_xxx" and "Authorization: api_xxx"
|
||||||
|
const [token] = (authorizationHeader || '').split('Bearer ').filter((s) => s.length > 0);
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'API token was not provided',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiToken = await getApiTokenByToken({ token });
|
||||||
|
|
||||||
|
if (apiToken.user.disabled) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'User is disabled',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info({
|
||||||
|
auth: 'api',
|
||||||
|
source: 'apiV2',
|
||||||
|
path: c.req.path,
|
||||||
|
userId: apiToken.user.id,
|
||||||
|
apiTokenId: apiToken.id,
|
||||||
|
envelopeItemId,
|
||||||
|
version,
|
||||||
|
});
|
||||||
|
|
||||||
|
const envelopeItem = await prisma.envelopeItem.findFirst({
|
||||||
|
where: {
|
||||||
|
id: envelopeItemId,
|
||||||
|
envelope: {
|
||||||
|
team: buildTeamWhereQuery({ teamId: apiToken.teamId, userId: apiToken.user.id }),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelope: true,
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Envelope item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelopeItem.envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version: version || 'signed',
|
||||||
|
isDownload: true,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
|
||||||
|
if (error instanceof AppError) {
|
||||||
|
if (error.code === AppErrorCode.UNAUTHORIZED) {
|
||||||
|
return c.json({ error: error.message }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: error.message }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: 'Internal server error' }, 500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
/**
|
||||||
|
* Download a document by its ID.
|
||||||
|
* Requires API key authentication via Authorization header.
|
||||||
|
*/
|
||||||
|
.get(
|
||||||
|
'/document/:documentId/download',
|
||||||
|
sValidator('param', ZDownloadDocumentRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const logger = c.get('logger');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { documentId, version } = c.req.valid('param');
|
||||||
|
const authorizationHeader = c.req.header('authorization');
|
||||||
|
|
||||||
|
// Support for both "Authorization: Bearer api_xxx" and "Authorization: api_xxx"
|
||||||
|
const [token] = (authorizationHeader || '').split('Bearer ').filter((s) => s.length > 0);
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'API token was not provided',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiToken = await getApiTokenByToken({ token });
|
||||||
|
|
||||||
|
if (apiToken.user.disabled) {
|
||||||
|
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||||
|
message: 'User is disabled',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info({
|
||||||
|
auth: 'api',
|
||||||
|
source: 'apiV2',
|
||||||
|
path: c.req.path,
|
||||||
|
userId: apiToken.user.id,
|
||||||
|
apiTokenId: apiToken.id,
|
||||||
|
documentId,
|
||||||
|
version,
|
||||||
|
});
|
||||||
|
|
||||||
|
const envelope = await getEnvelopeById({
|
||||||
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: documentId,
|
||||||
|
},
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
userId: apiToken.user.id,
|
||||||
|
teamId: apiToken.teamId,
|
||||||
|
}).catch(() => null);
|
||||||
|
|
||||||
|
if (!envelope) {
|
||||||
|
return c.json({ error: 'Document not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the first envelope item (documents have exactly one)
|
||||||
|
const [envelopeItem] = envelope.envelopeItems;
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Document item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version: version || 'signed',
|
||||||
|
isDownload: true,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
|
||||||
|
if (error instanceof AppError) {
|
||||||
|
if (error.code === AppErrorCode.UNAUTHORIZED) {
|
||||||
|
return c.json({ error: error.message }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: error.message }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: 'Internal server error' }, 500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
29
apps/remix/server/api/download/download.types.ts
Normal file
29
apps/remix/server/api/download/download.types.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const ZDownloadEnvelopeItemRequestParamsSchema = z.object({
|
||||||
|
envelopeItemId: z.string().describe('The ID of the envelope item to download.'),
|
||||||
|
version: z
|
||||||
|
.enum(['original', 'signed'])
|
||||||
|
.optional()
|
||||||
|
.default('signed')
|
||||||
|
.describe(
|
||||||
|
'The version of the envelope item to download. "signed" returns the completed document with signatures, "original" returns the original uploaded document.',
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TDownloadEnvelopeItemRequestParams = z.infer<
|
||||||
|
typeof ZDownloadEnvelopeItemRequestParamsSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const ZDownloadDocumentRequestParamsSchema = z.object({
|
||||||
|
documentId: z.coerce.number().describe('The ID of the document to download.'),
|
||||||
|
version: z
|
||||||
|
.enum(['original', 'signed'])
|
||||||
|
.optional()
|
||||||
|
.default('signed')
|
||||||
|
.describe(
|
||||||
|
'The version of the document to download. "signed" returns the completed document with signatures, "original" returns the original uploaded document.',
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TDownloadDocumentRequestParams = z.infer<typeof ZDownloadDocumentRequestParamsSchema>;
|
||||||
@ -1,100 +0,0 @@
|
|||||||
import { PDFDocument } from '@cantoo/pdf-lib';
|
|
||||||
import { sValidator } from '@hono/standard-validator';
|
|
||||||
import { Hono } from 'hono';
|
|
||||||
|
|
||||||
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
||||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
|
||||||
import { putFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
|
||||||
import {
|
|
||||||
getPresignGetUrl,
|
|
||||||
getPresignPostUrl,
|
|
||||||
} from '@documenso/lib/universal/upload/server-actions';
|
|
||||||
|
|
||||||
import type { HonoEnv } from '../router';
|
|
||||||
import {
|
|
||||||
type TGetPresignedGetUrlResponse,
|
|
||||||
type TGetPresignedPostUrlResponse,
|
|
||||||
ZGetPresignedGetUrlRequestSchema,
|
|
||||||
ZGetPresignedPostUrlRequestSchema,
|
|
||||||
ZUploadPdfRequestSchema,
|
|
||||||
} from './files.types';
|
|
||||||
|
|
||||||
export const filesRoute = new Hono<HonoEnv>()
|
|
||||||
/**
|
|
||||||
* Uploads a document file to the appropriate storage location and creates
|
|
||||||
* a document data record.
|
|
||||||
*/
|
|
||||||
.post('/upload-pdf', sValidator('form', ZUploadPdfRequestSchema), async (c) => {
|
|
||||||
try {
|
|
||||||
const { file } = c.req.valid('form');
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
return c.json({ error: 'No file provided' }, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Todo: (RR7) This is new.
|
|
||||||
// Add file size validation.
|
|
||||||
// Convert MB to bytes (1 MB = 1024 * 1024 bytes)
|
|
||||||
const MAX_FILE_SIZE = APP_DOCUMENT_UPLOAD_SIZE_LIMIT * 1024 * 1024;
|
|
||||||
|
|
||||||
if (file.size > MAX_FILE_SIZE) {
|
|
||||||
return c.json({ error: 'File too large' }, 400);
|
|
||||||
}
|
|
||||||
|
|
||||||
const arrayBuffer = await file.arrayBuffer();
|
|
||||||
|
|
||||||
const pdf = await PDFDocument.load(arrayBuffer).catch((e) => {
|
|
||||||
console.error(`PDF upload parse error: ${e.message}`);
|
|
||||||
|
|
||||||
throw new AppError('INVALID_DOCUMENT_FILE');
|
|
||||||
});
|
|
||||||
|
|
||||||
if (pdf.isEncrypted) {
|
|
||||||
throw new AppError('INVALID_DOCUMENT_FILE');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Todo: (RR7) Test this.
|
|
||||||
if (!file.name.endsWith('.pdf')) {
|
|
||||||
Object.defineProperty(file, 'name', {
|
|
||||||
writable: true,
|
|
||||||
value: `${file.name}.pdf`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { type, data } = await putFileServerSide(file);
|
|
||||||
|
|
||||||
const result = await createDocumentData({ type, data });
|
|
||||||
|
|
||||||
return c.json(result);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Upload failed:', error);
|
|
||||||
return c.json({ error: 'Upload failed' }, 500);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.post('/presigned-get-url', sValidator('json', ZGetPresignedGetUrlRequestSchema), async (c) => {
|
|
||||||
const { key } = await c.req.json();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { url } = await getPresignGetUrl(key || '');
|
|
||||||
|
|
||||||
return c.json({ url } satisfies TGetPresignedGetUrlResponse);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
|
|
||||||
throw new AppError(AppErrorCode.UNKNOWN_ERROR);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.post('/presigned-post-url', sValidator('json', ZGetPresignedPostUrlRequestSchema), async (c) => {
|
|
||||||
const { fileName, contentType } = c.req.valid('json');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { key, url } = await getPresignPostUrl(fileName, contentType);
|
|
||||||
|
|
||||||
return c.json({ key, url } satisfies TGetPresignedPostUrlResponse);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
|
|
||||||
throw new AppError(AppErrorCode.UNKNOWN_ERROR);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import DocumentDataSchema from '@documenso/prisma/generated/zod/modelSchema/DocumentDataSchema';
|
|
||||||
|
|
||||||
export const ZUploadPdfRequestSchema = z.object({
|
|
||||||
file: z.instanceof(File),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZUploadPdfResponseSchema = DocumentDataSchema.pick({
|
|
||||||
type: true,
|
|
||||||
id: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TUploadPdfRequest = z.infer<typeof ZUploadPdfRequestSchema>;
|
|
||||||
export type TUploadPdfResponse = z.infer<typeof ZUploadPdfResponseSchema>;
|
|
||||||
|
|
||||||
export const ZGetPresignedPostUrlRequestSchema = z.object({
|
|
||||||
fileName: z.string().min(1),
|
|
||||||
contentType: z.string().min(1),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZGetPresignedPostUrlResponseSchema = z.object({
|
|
||||||
key: z.string().min(1),
|
|
||||||
url: z.string().min(1),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZGetPresignedGetUrlRequestSchema = z.object({
|
|
||||||
key: z.string().min(1),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZGetPresignedGetUrlResponseSchema = z.object({
|
|
||||||
url: z.string().min(1),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TGetPresignedPostUrlRequest = z.infer<typeof ZGetPresignedPostUrlRequestSchema>;
|
|
||||||
export type TGetPresignedPostUrlResponse = z.infer<typeof ZGetPresignedPostUrlResponseSchema>;
|
|
||||||
export type TGetPresignedGetUrlRequest = z.infer<typeof ZGetPresignedGetUrlRequestSchema>;
|
|
||||||
export type TGetPresignedGetUrlResponse = z.infer<typeof ZGetPresignedGetUrlResponseSchema>;
|
|
||||||
81
apps/remix/server/api/files/files.helpers.ts
Normal file
81
apps/remix/server/api/files/files.helpers.ts
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import { type DocumentDataType, DocumentStatus } from '@prisma/client';
|
||||||
|
import { type Context } from 'hono';
|
||||||
|
|
||||||
|
import { sha256 } from '@documenso/lib/universal/crypto';
|
||||||
|
import { getFileServerSide } from '@documenso/lib/universal/upload/get-file.server';
|
||||||
|
|
||||||
|
import type { HonoEnv } from '../../router';
|
||||||
|
|
||||||
|
type HandleEnvelopeItemFileRequestOptions = {
|
||||||
|
title: string;
|
||||||
|
status: DocumentStatus;
|
||||||
|
documentData: {
|
||||||
|
type: DocumentDataType;
|
||||||
|
data: string;
|
||||||
|
initialData: string;
|
||||||
|
};
|
||||||
|
version: 'signed' | 'original';
|
||||||
|
isDownload: boolean;
|
||||||
|
context: Context<HonoEnv>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to handle envelope item file requests (both view and download)
|
||||||
|
*/
|
||||||
|
export const handleEnvelopeItemFileRequest = async ({
|
||||||
|
title,
|
||||||
|
status,
|
||||||
|
documentData,
|
||||||
|
version,
|
||||||
|
isDownload,
|
||||||
|
context: c,
|
||||||
|
}: HandleEnvelopeItemFileRequestOptions) => {
|
||||||
|
const documentDataToUse = version === 'signed' ? documentData.data : documentData.initialData;
|
||||||
|
|
||||||
|
const etag = Buffer.from(sha256(documentDataToUse)).toString('hex');
|
||||||
|
|
||||||
|
if (c.req.header('If-None-Match') === etag) {
|
||||||
|
return c.body(null, 304);
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await getFileServerSide({
|
||||||
|
type: documentData.type,
|
||||||
|
data: documentDataToUse,
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
return c.json({ error: 'File not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.header('Content-Type', 'application/pdf');
|
||||||
|
c.header('ETag', etag);
|
||||||
|
|
||||||
|
if (!isDownload) {
|
||||||
|
if (status === DocumentStatus.COMPLETED) {
|
||||||
|
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
||||||
|
} else {
|
||||||
|
// Set a tiny 1 minute cache, with must-revalidate to ensure the client always checks for updates.
|
||||||
|
c.header('Cache-Control', 'public, max-age=60, must-revalidate');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDownload) {
|
||||||
|
// Generate filename following the pattern from envelope-download-dialog.tsx
|
||||||
|
const baseTitle = title.replace(/\.pdf$/, '');
|
||||||
|
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
||||||
|
const filename = `${baseTitle}${suffix}`;
|
||||||
|
|
||||||
|
c.header('Content-Disposition', `attachment; filename="${filename}"`);
|
||||||
|
|
||||||
|
// For downloads, prevent caching to ensure fresh data
|
||||||
|
c.header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||||
|
c.header('Pragma', 'no-cache');
|
||||||
|
c.header('Expires', '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.body(file);
|
||||||
|
};
|
||||||
307
apps/remix/server/api/files/files.ts
Normal file
307
apps/remix/server/api/files/files.ts
Normal file
@ -0,0 +1,307 @@
|
|||||||
|
import { sValidator } from '@hono/standard-validator';
|
||||||
|
import type { Prisma } from '@prisma/client';
|
||||||
|
import { Hono } from 'hono';
|
||||||
|
|
||||||
|
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
|
||||||
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
|
||||||
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
|
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
|
||||||
|
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||||
|
import { getPresignPostUrl } from '@documenso/lib/universal/upload/server-actions';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import type { HonoEnv } from '../../router';
|
||||||
|
import { handleEnvelopeItemFileRequest } from './files.helpers';
|
||||||
|
import {
|
||||||
|
type TGetPresignedPostUrlResponse,
|
||||||
|
ZGetEnvelopeItemFileDownloadRequestParamsSchema,
|
||||||
|
ZGetEnvelopeItemFileRequestParamsSchema,
|
||||||
|
ZGetEnvelopeItemFileTokenDownloadRequestParamsSchema,
|
||||||
|
ZGetEnvelopeItemFileTokenRequestParamsSchema,
|
||||||
|
ZGetPresignedPostUrlRequestSchema,
|
||||||
|
ZUploadPdfRequestSchema,
|
||||||
|
} from './files.types';
|
||||||
|
|
||||||
|
export const filesRoute = new Hono<HonoEnv>()
|
||||||
|
/**
|
||||||
|
* Uploads a document file to the appropriate storage location and creates
|
||||||
|
* a document data record.
|
||||||
|
*/
|
||||||
|
.post('/upload-pdf', sValidator('form', ZUploadPdfRequestSchema), async (c) => {
|
||||||
|
try {
|
||||||
|
const { file } = c.req.valid('form');
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
return c.json({ error: 'No file provided' }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: (RR7) This is new.
|
||||||
|
// Add file size validation.
|
||||||
|
// Convert MB to bytes (1 MB = 1024 * 1024 bytes)
|
||||||
|
const MAX_FILE_SIZE = APP_DOCUMENT_UPLOAD_SIZE_LIMIT * 1024 * 1024;
|
||||||
|
|
||||||
|
if (file.size > MAX_FILE_SIZE) {
|
||||||
|
return c.json({ error: 'File too large' }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await putNormalizedPdfFileServerSide(file);
|
||||||
|
|
||||||
|
return c.json(result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Upload failed:', error);
|
||||||
|
return c.json({ error: 'Upload failed' }, 500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.post('/presigned-post-url', sValidator('json', ZGetPresignedPostUrlRequestSchema), async (c) => {
|
||||||
|
const { fileName, contentType } = c.req.valid('json');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { key, url } = await getPresignPostUrl(fileName, contentType);
|
||||||
|
|
||||||
|
return c.json({ key, url } satisfies TGetPresignedPostUrlResponse);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
|
throw new AppError(AppErrorCode.UNKNOWN_ERROR);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.get(
|
||||||
|
'/envelope/:envelopeId/envelopeItem/:envelopeItemId',
|
||||||
|
sValidator('param', ZGetEnvelopeItemFileRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const { envelopeId, envelopeItemId } = c.req.valid('param');
|
||||||
|
|
||||||
|
const session = await getOptionalSession(c);
|
||||||
|
|
||||||
|
if (!session.user) {
|
||||||
|
return c.json({ error: 'Unauthorized' }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findFirst({
|
||||||
|
where: {
|
||||||
|
id: envelopeId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
where: {
|
||||||
|
id: envelopeItemId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelope) {
|
||||||
|
return c.json({ error: 'Envelope not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [envelopeItem] = envelope.envelopeItems;
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Envelope item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const team = await getTeamById({
|
||||||
|
userId: session.user.id,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!team) {
|
||||||
|
return c.json(
|
||||||
|
{ error: 'User does not have access to the team that this envelope is associated with' },
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version: 'signed',
|
||||||
|
isDownload: false,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
'/envelope/:envelopeId/envelopeItem/:envelopeItemId/download/:version?',
|
||||||
|
sValidator('param', ZGetEnvelopeItemFileDownloadRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const { envelopeId, envelopeItemId, version } = c.req.valid('param');
|
||||||
|
|
||||||
|
const session = await getOptionalSession(c);
|
||||||
|
|
||||||
|
if (!session.user) {
|
||||||
|
return c.json({ error: 'Unauthorized' }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findFirst({
|
||||||
|
where: {
|
||||||
|
id: envelopeId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
where: {
|
||||||
|
id: envelopeItemId,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelope) {
|
||||||
|
return c.json({ error: 'Envelope not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [envelopeItem] = envelope.envelopeItems;
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Envelope item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const team = await getTeamById({
|
||||||
|
userId: session.user.id,
|
||||||
|
teamId: envelope.teamId,
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!team) {
|
||||||
|
return c.json(
|
||||||
|
{ error: 'User does not have access to the team that this envelope is associated with' },
|
||||||
|
403,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version,
|
||||||
|
isDownload: true,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
'/token/:token/envelopeItem/:envelopeItemId',
|
||||||
|
sValidator('param', ZGetEnvelopeItemFileTokenRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const { token, envelopeItemId } = c.req.valid('param');
|
||||||
|
|
||||||
|
let envelopeWhereQuery: Prisma.EnvelopeItemWhereUniqueInput = {
|
||||||
|
id: envelopeItemId,
|
||||||
|
envelope: {
|
||||||
|
recipients: {
|
||||||
|
some: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (token.startsWith('qr_')) {
|
||||||
|
envelopeWhereQuery = {
|
||||||
|
id: envelopeItemId,
|
||||||
|
envelope: {
|
||||||
|
qrToken: token,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const envelopeItem = await prisma.envelopeItem.findUnique({
|
||||||
|
where: envelopeWhereQuery,
|
||||||
|
include: {
|
||||||
|
envelope: true,
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Envelope item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelopeItem.envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version: 'signed',
|
||||||
|
isDownload: false,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
'/token/:token/envelopeItem/:envelopeItemId/download/:version?',
|
||||||
|
sValidator('param', ZGetEnvelopeItemFileTokenDownloadRequestParamsSchema),
|
||||||
|
async (c) => {
|
||||||
|
const { token, envelopeItemId, version } = c.req.valid('param');
|
||||||
|
|
||||||
|
let envelopeWhereQuery: Prisma.EnvelopeItemWhereUniqueInput = {
|
||||||
|
id: envelopeItemId,
|
||||||
|
envelope: {
|
||||||
|
recipients: {
|
||||||
|
some: {
|
||||||
|
token,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (token.startsWith('qr_')) {
|
||||||
|
envelopeWhereQuery = {
|
||||||
|
id: envelopeItemId,
|
||||||
|
envelope: {
|
||||||
|
qrToken: token,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const envelopeItem = await prisma.envelopeItem.findUnique({
|
||||||
|
where: envelopeWhereQuery,
|
||||||
|
include: {
|
||||||
|
envelope: true,
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!envelopeItem) {
|
||||||
|
return c.json({ error: 'Envelope item not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!envelopeItem.documentData) {
|
||||||
|
return c.json({ error: 'Document data not found' }, 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await handleEnvelopeItemFileRequest({
|
||||||
|
title: envelopeItem.title,
|
||||||
|
status: envelopeItem.envelope.status,
|
||||||
|
documentData: envelopeItem.documentData,
|
||||||
|
version,
|
||||||
|
isDownload: true,
|
||||||
|
context: c,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
66
apps/remix/server/api/files/files.types.ts
Normal file
66
apps/remix/server/api/files/files.types.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import DocumentDataSchema from '@documenso/prisma/generated/zod/modelSchema/DocumentDataSchema';
|
||||||
|
|
||||||
|
export const ZUploadPdfRequestSchema = z.object({
|
||||||
|
file: z.instanceof(File),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const ZUploadPdfResponseSchema = DocumentDataSchema.pick({
|
||||||
|
type: true,
|
||||||
|
id: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TUploadPdfRequest = z.infer<typeof ZUploadPdfRequestSchema>;
|
||||||
|
export type TUploadPdfResponse = z.infer<typeof ZUploadPdfResponseSchema>;
|
||||||
|
|
||||||
|
export const ZGetPresignedPostUrlRequestSchema = z.object({
|
||||||
|
fileName: z.string().min(1),
|
||||||
|
contentType: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const ZGetPresignedPostUrlResponseSchema = z.object({
|
||||||
|
key: z.string().min(1),
|
||||||
|
url: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetPresignedPostUrlRequest = z.infer<typeof ZGetPresignedPostUrlRequestSchema>;
|
||||||
|
export type TGetPresignedPostUrlResponse = z.infer<typeof ZGetPresignedPostUrlResponseSchema>;
|
||||||
|
|
||||||
|
export const ZGetEnvelopeItemFileRequestParamsSchema = z.object({
|
||||||
|
envelopeId: z.string().min(1),
|
||||||
|
envelopeItemId: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetEnvelopeItemFileRequestParams = z.infer<
|
||||||
|
typeof ZGetEnvelopeItemFileRequestParamsSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const ZGetEnvelopeItemFileTokenRequestParamsSchema = z.object({
|
||||||
|
token: z.string().min(1),
|
||||||
|
envelopeItemId: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetEnvelopeItemFileTokenRequestParams = z.infer<
|
||||||
|
typeof ZGetEnvelopeItemFileTokenRequestParamsSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const ZGetEnvelopeItemFileDownloadRequestParamsSchema = z.object({
|
||||||
|
envelopeId: z.string().min(1),
|
||||||
|
envelopeItemId: z.string().min(1),
|
||||||
|
version: z.enum(['signed', 'original']).default('signed'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetEnvelopeItemFileDownloadRequestParams = z.infer<
|
||||||
|
typeof ZGetEnvelopeItemFileDownloadRequestParamsSchema
|
||||||
|
>;
|
||||||
|
|
||||||
|
export const ZGetEnvelopeItemFileTokenDownloadRequestParamsSchema = z.object({
|
||||||
|
token: z.string().min(1),
|
||||||
|
envelopeItemId: z.string().min(1),
|
||||||
|
version: z.enum(['signed', 'original']).default('signed'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TGetEnvelopeItemFileTokenDownloadRequestParams = z.infer<
|
||||||
|
typeof ZGetEnvelopeItemFileTokenDownloadRequestParamsSchema
|
||||||
|
>;
|
||||||
@ -8,13 +8,14 @@ import type { Logger } from 'pino';
|
|||||||
|
|
||||||
import { tsRestHonoApp } from '@documenso/api/hono';
|
import { tsRestHonoApp } from '@documenso/api/hono';
|
||||||
import { auth } from '@documenso/auth/server';
|
import { auth } from '@documenso/auth/server';
|
||||||
import { API_V2_BETA_URL } from '@documenso/lib/constants/app';
|
import { API_V2_BETA_URL, API_V2_URL } from '@documenso/lib/constants/app';
|
||||||
import { jobsClient } from '@documenso/lib/jobs/client';
|
import { jobsClient } from '@documenso/lib/jobs/client';
|
||||||
import { getIpAddress } from '@documenso/lib/universal/get-ip-address';
|
import { getIpAddress } from '@documenso/lib/universal/get-ip-address';
|
||||||
import { logger } from '@documenso/lib/utils/logger';
|
import { logger } from '@documenso/lib/utils/logger';
|
||||||
import { openApiDocument } from '@documenso/trpc/server/open-api';
|
import { openApiDocument } from '@documenso/trpc/server/open-api';
|
||||||
|
|
||||||
import { filesRoute } from './api/files';
|
import { downloadRoute } from './api/download/download';
|
||||||
|
import { filesRoute } from './api/files/files';
|
||||||
import { type AppContext, appContext } from './context';
|
import { type AppContext, appContext } from './context';
|
||||||
import { appMiddleware } from './middleware';
|
import { appMiddleware } from './middleware';
|
||||||
import { openApiTrpcServerHandler } from './trpc/hono-trpc-open-api';
|
import { openApiTrpcServerHandler } from './trpc/hono-trpc-open-api';
|
||||||
@ -89,9 +90,26 @@ app.route('/api/v1', tsRestHonoApp);
|
|||||||
app.use('/api/jobs/*', jobsClient.getApiHandler());
|
app.use('/api/jobs/*', jobsClient.getApiHandler());
|
||||||
app.use('/api/trpc/*', reactRouterTrpcServer);
|
app.use('/api/trpc/*', reactRouterTrpcServer);
|
||||||
|
|
||||||
|
// Unstable API server routes. Order matters for these two.
|
||||||
|
app.get(`${API_V2_URL}/openapi.json`, (c) => c.json(openApiDocument));
|
||||||
|
app.use(`${API_V2_URL}/*`, cors());
|
||||||
|
// Shadows the download routes that tRPC defines since tRPC-to-openapi doesn't support their return types.
|
||||||
|
app.route(`${API_V2_URL}`, downloadRoute);
|
||||||
|
app.use(`${API_V2_URL}/*`, async (c) =>
|
||||||
|
openApiTrpcServerHandler(c, {
|
||||||
|
isBeta: false,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// Unstable API server routes. Order matters for these two.
|
// Unstable API server routes. Order matters for these two.
|
||||||
app.get(`${API_V2_BETA_URL}/openapi.json`, (c) => c.json(openApiDocument));
|
app.get(`${API_V2_BETA_URL}/openapi.json`, (c) => c.json(openApiDocument));
|
||||||
app.use(`${API_V2_BETA_URL}/*`, cors());
|
app.use(`${API_V2_BETA_URL}/*`, cors());
|
||||||
app.use(`${API_V2_BETA_URL}/*`, async (c) => openApiTrpcServerHandler(c));
|
// Shadows the download routes that tRPC defines since tRPC-to-openapi doesn't support their return types.
|
||||||
|
app.route(`${API_V2_BETA_URL}`, downloadRoute);
|
||||||
|
app.use(`${API_V2_BETA_URL}/*`, async (c) =>
|
||||||
|
openApiTrpcServerHandler(c, {
|
||||||
|
isBeta: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@ -1,15 +1,22 @@
|
|||||||
import type { Context } from 'hono';
|
import type { Context } from 'hono';
|
||||||
import { createOpenApiFetchHandler } from 'trpc-to-openapi';
|
|
||||||
|
|
||||||
import { API_V2_BETA_URL } from '@documenso/lib/constants/app';
|
import { API_V2_BETA_URL, API_V2_URL } from '@documenso/lib/constants/app';
|
||||||
import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error';
|
import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error';
|
||||||
import { createTrpcContext } from '@documenso/trpc/server/context';
|
import { createTrpcContext } from '@documenso/trpc/server/context';
|
||||||
import { appRouter } from '@documenso/trpc/server/router';
|
import { appRouter } from '@documenso/trpc/server/router';
|
||||||
|
import { createOpenApiFetchHandler } from '@documenso/trpc/utils/openapi-fetch-handler';
|
||||||
import { handleTrpcRouterError } from '@documenso/trpc/utils/trpc-error-handler';
|
import { handleTrpcRouterError } from '@documenso/trpc/utils/trpc-error-handler';
|
||||||
|
|
||||||
export const openApiTrpcServerHandler = async (c: Context) => {
|
type OpenApiTrpcServerHandlerOptions = {
|
||||||
|
isBeta: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const openApiTrpcServerHandler = async (
|
||||||
|
c: Context,
|
||||||
|
{ isBeta }: OpenApiTrpcServerHandlerOptions,
|
||||||
|
) => {
|
||||||
return createOpenApiFetchHandler<typeof appRouter>({
|
return createOpenApiFetchHandler<typeof appRouter>({
|
||||||
endpoint: API_V2_BETA_URL,
|
endpoint: isBeta ? API_V2_BETA_URL : API_V2_URL,
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
createContext: async () => createTrpcContext({ c, requestSource: 'apiV2' }),
|
createContext: async () => createTrpcContext({ c, requestSource: 'apiV2' }),
|
||||||
req: c.req.raw,
|
req: c.req.raw,
|
||||||
|
|||||||
BIN
assets/field-font-alignment.pdf
Normal file
BIN
assets/field-font-alignment.pdf
Normal file
Binary file not shown.
BIN
assets/field-meta.pdf
Normal file
BIN
assets/field-meta.pdf
Normal file
Binary file not shown.
782
package-lock.json
generated
782
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -44,7 +44,7 @@
|
|||||||
"@commitlint/cli": "^17.7.1",
|
"@commitlint/cli": "^17.7.1",
|
||||||
"@commitlint/config-conventional": "^17.7.0",
|
"@commitlint/config-conventional": "^17.7.0",
|
||||||
"@lingui/cli": "^5.2.0",
|
"@lingui/cli": "^5.2.0",
|
||||||
"@prisma/client": "^6.8.2",
|
"@prisma/client": "^6.18.0",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"dotenv-cli": "^8.0.0",
|
"dotenv-cli": "^8.0.0",
|
||||||
"eslint": "^8.40.0",
|
"eslint": "^8.40.0",
|
||||||
@ -54,11 +54,22 @@
|
|||||||
"nodemailer": "^6.10.1",
|
"nodemailer": "^6.10.1",
|
||||||
"playwright": "1.52.0",
|
"playwright": "1.52.0",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"prisma": "^6.8.2",
|
"prisma": "^6.18.0",
|
||||||
"prisma-extension-kysely": "^3.0.0",
|
"prisma-extension-kysely": "^3.0.0",
|
||||||
|
"prisma-json-types-generator": "^3.6.2",
|
||||||
"prisma-kysely": "^1.8.0",
|
"prisma-kysely": "^1.8.0",
|
||||||
"rimraf": "^5.0.1",
|
"rimraf": "^5.0.1",
|
||||||
"turbo": "^1.9.3",
|
"turbo": "^1.9.3",
|
||||||
|
"@trpc/client": "11.7.0",
|
||||||
|
"@trpc/react-query": "11.7.0",
|
||||||
|
"@trpc/server": "11.7.0",
|
||||||
|
"superjson": "^2.2.5",
|
||||||
|
"trpc-to-openapi": "2.4.0",
|
||||||
|
"zod-openapi": "^4.2.4",
|
||||||
|
"@ts-rest/core": "^3.52.1",
|
||||||
|
"@ts-rest/open-api": "^3.52.1",
|
||||||
|
"@ts-rest/serverless": "^3.52.1",
|
||||||
|
"zod-prisma-types": "3.3.5",
|
||||||
"vite": "^6.3.5"
|
"vite": "^6.3.5"
|
||||||
},
|
},
|
||||||
"name": "@documenso/root",
|
"name": "@documenso/root",
|
||||||
@ -76,10 +87,10 @@
|
|||||||
"mupdf": "^1.0.0",
|
"mupdf": "^1.0.0",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"typescript": "5.6.2",
|
"typescript": "5.6.2",
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
},
|
},
|
||||||
"trigger.dev": {
|
"trigger.dev": {
|
||||||
"endpointId": "documenso-app"
|
"endpointId": "documenso-app"
|
||||||
|
|||||||
@ -17,14 +17,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@documenso/lib": "*",
|
"@documenso/lib": "*",
|
||||||
"@documenso/prisma": "*",
|
"@documenso/prisma": "*",
|
||||||
"@ts-rest/core": "^3.30.5",
|
"@ts-rest/core": "^3.52.0",
|
||||||
"@ts-rest/open-api": "^3.33.0",
|
"@ts-rest/open-api": "^3.52.0",
|
||||||
"@ts-rest/serverless": "^3.30.5",
|
"@ts-rest/serverless": "^3.52.0",
|
||||||
"@types/swagger-ui-react": "^5.18.0",
|
"@types/swagger-ui-react": "^5.18.0",
|
||||||
"luxon": "^3.4.0",
|
"luxon": "^3.4.0",
|
||||||
"superjson": "^1.13.1",
|
"superjson": "^2.2.5",
|
||||||
"swagger-ui-react": "^5.21.0",
|
"swagger-ui-react": "^5.21.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,12 +20,12 @@ import {
|
|||||||
getEnvelopeWhereInput,
|
getEnvelopeWhereInput,
|
||||||
} from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
} from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||||
import { deleteDocumentField } from '@documenso/lib/server-only/field/delete-document-field';
|
import { deleteDocumentField } from '@documenso/lib/server-only/field/delete-document-field';
|
||||||
import { updateDocumentFields } from '@documenso/lib/server-only/field/update-document-fields';
|
import { updateEnvelopeFields } from '@documenso/lib/server-only/field/update-envelope-fields';
|
||||||
import { insertFormValuesInPdf } from '@documenso/lib/server-only/pdf/insert-form-values-in-pdf';
|
import { insertFormValuesInPdf } from '@documenso/lib/server-only/pdf/insert-form-values-in-pdf';
|
||||||
import { deleteDocumentRecipient } from '@documenso/lib/server-only/recipient/delete-document-recipient';
|
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
||||||
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
||||||
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
import { setDocumentRecipients } from '@documenso/lib/server-only/recipient/set-document-recipients';
|
||||||
import { updateDocumentRecipients } from '@documenso/lib/server-only/recipient/update-document-recipients';
|
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
||||||
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
||||||
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
||||||
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
||||||
@ -1285,7 +1285,7 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedRecipient = await updateDocumentRecipients({
|
const updatedRecipient = await updateEnvelopeRecipients({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
id: {
|
id: {
|
||||||
@ -1336,7 +1336,7 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const deletedRecipient = await deleteDocumentRecipient({
|
const deletedRecipient = await deleteEnvelopeRecipient({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
recipientId: Number(recipientId),
|
recipientId: Number(recipientId),
|
||||||
@ -1634,10 +1634,13 @@ export const ApiContractV1Implementation = tsr.router(ApiContractV1, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const { fields } = await updateDocumentFields({
|
const { fields } = await updateEnvelopeFields({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
documentId: legacyDocumentId,
|
id: {
|
||||||
|
type: 'documentId',
|
||||||
|
id: legacyDocumentId,
|
||||||
|
},
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
id: Number(fieldId),
|
id: Number(fieldId),
|
||||||
|
|||||||
498
packages/app-tests/constants/field-alignment-pdf.ts
Normal file
498
packages/app-tests/constants/field-alignment-pdf.ts
Normal file
@ -0,0 +1,498 @@
|
|||||||
|
import { FieldType } from '@prisma/client';
|
||||||
|
|
||||||
|
import type { TFieldAndMeta } from '@documenso/lib/types/field-meta';
|
||||||
|
import { toCheckboxCustomText } from '@documenso/lib/utils/fields';
|
||||||
|
|
||||||
|
export type FieldTestData = TFieldAndMeta & {
|
||||||
|
page: number;
|
||||||
|
positionX: number;
|
||||||
|
positionY: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
customText: string;
|
||||||
|
signature?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const columnWidth = 19.125;
|
||||||
|
const rowHeight = 6.7;
|
||||||
|
|
||||||
|
const alignmentGridStartX = 31;
|
||||||
|
const alignmentGridStartY = 19.02;
|
||||||
|
|
||||||
|
export const ALIGNMENT_TEST_FIELDS: FieldTestData[] = [
|
||||||
|
/**
|
||||||
|
* Row 1 EMAIL
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.EMAIL,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'email',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'admin@documenso.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.EMAIL,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'email',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'admin@documenso.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.EMAIL,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'email',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'admin@documenso.com',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 2 NAME
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.NAME,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'name',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'John Doe',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NAME,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'name',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'John Doe',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NAME,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'name',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'John Doe',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 3 DATE
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.DATE,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DATE,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DATE,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'date',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 4 TEXT
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 5 NUMBER
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 6 Initials
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.INITIALS,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
textAlign: 'left',
|
||||||
|
type: 'initials',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'JD',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.INITIALS,
|
||||||
|
fieldMeta: {
|
||||||
|
textAlign: 'center',
|
||||||
|
type: 'initials',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'JD',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.INITIALS,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
textAlign: 'right',
|
||||||
|
type: 'initials',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'JD',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 7 Radio
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: true, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: true, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
direction: 'horizontal',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 8 Checkbox
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: true, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: toCheckboxCustomText([0]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: true, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: toCheckboxCustomText([1]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
direction: 'horizontal',
|
||||||
|
type: 'checkbox',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 8 Dropdown
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Row 9 Signature
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 10,
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
fontSize: 20,
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 1,
|
||||||
|
height: rowHeight,
|
||||||
|
width: columnWidth,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const formatAlignmentTestFields = ALIGNMENT_TEST_FIELDS.map((field, index) => {
|
||||||
|
const row = Math.floor(index / 3);
|
||||||
|
const column = index % 3;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...field,
|
||||||
|
positionX: alignmentGridStartX + column * columnWidth,
|
||||||
|
positionY: alignmentGridStartY + row * rowHeight,
|
||||||
|
};
|
||||||
|
});
|
||||||
482
packages/app-tests/constants/field-meta-pdf.ts
Normal file
482
packages/app-tests/constants/field-meta-pdf.ts
Normal file
@ -0,0 +1,482 @@
|
|||||||
|
import { FieldType } from '@prisma/client';
|
||||||
|
|
||||||
|
import { toCheckboxCustomText } from '@documenso/lib/utils/fields';
|
||||||
|
import {
|
||||||
|
CheckboxValidationRules,
|
||||||
|
numberFormatValues,
|
||||||
|
} from '@documenso/ui/primitives/document-flow/field-items-advanced-settings/constants';
|
||||||
|
|
||||||
|
import type { FieldTestData } from './field-alignment-pdf';
|
||||||
|
|
||||||
|
const columnWidth = 20.1;
|
||||||
|
const fullColumnWidth = 75.8;
|
||||||
|
const rowHeight = 9.8;
|
||||||
|
const rowPadding = 1.8;
|
||||||
|
|
||||||
|
const alignmentGridStartX = 11.85;
|
||||||
|
const alignmentGridStartY = 15.07;
|
||||||
|
|
||||||
|
const calculatePosition = (row: number, column: number, width: 'full' | 'column' = 'column') => {
|
||||||
|
return {
|
||||||
|
height: rowHeight,
|
||||||
|
width: width === 'full' ? fullColumnWidth : columnWidth,
|
||||||
|
positionX: alignmentGridStartX + (column ?? 0) * columnWidth,
|
||||||
|
positionY: alignmentGridStartY + row * (rowHeight + rowPadding),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FIELD_META_TEST_FIELDS: FieldTestData[] = [
|
||||||
|
/**
|
||||||
|
* PAGE 2 Signature
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 2,
|
||||||
|
...calculatePosition(0, 0),
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 2,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 2,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
|
page: 2,
|
||||||
|
...calculatePosition(3, 0),
|
||||||
|
customText: '',
|
||||||
|
signature: 'My Signature',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PAGE 3 TEXT
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(0, 0, 'full'),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: '123456789123456789123456789123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
characterLimit: 5,
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: '12345',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
placeholder: 'Demo Placeholder',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(3, 0),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
label: 'Demo Label',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(3, 1),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
text: 'Prefilled text',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(3, 2),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(4, 0),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.TEXT,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'text',
|
||||||
|
readOnly: true,
|
||||||
|
text: 'Readonly Value',
|
||||||
|
},
|
||||||
|
page: 3,
|
||||||
|
...calculatePosition(4, 1),
|
||||||
|
customText: 'Readonly Value',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PAGE 4 NUMBER
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(0, 0, 'full'),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: '123456789123456789123456789123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
minValue: 0,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: '50',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
numberFormat: numberFormatValues[0].value, // Todo: Envelopes - Check this.
|
||||||
|
value: '123,456,789.00',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(2, 1),
|
||||||
|
customText: '123,456,789.00',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
placeholder: 'Demo Placeholder',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(3, 0),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
label: 'Demo Label',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(3, 1),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
value: '123',
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(3, 2),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(4, 0),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.NUMBER,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'number',
|
||||||
|
readOnly: true,
|
||||||
|
},
|
||||||
|
page: 4,
|
||||||
|
...calculatePosition(4, 1),
|
||||||
|
customText: '123456789',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PAGE 5 RADIO
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'horizontal',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: true, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 5,
|
||||||
|
...calculatePosition(0, 0, 'full'),
|
||||||
|
customText: '0',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: true, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 5,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: '2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 5,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.RADIO,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'radio',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 5,
|
||||||
|
...calculatePosition(2, 1),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PAGE 6 CHECKBOX
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'horizontal',
|
||||||
|
type: 'checkbox',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: true, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 3' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 4' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(0, 0, 'full'),
|
||||||
|
customText: toCheckboxCustomText([0]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: true, value: 'Option 2' },
|
||||||
|
{ id: 2, checked: true, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: toCheckboxCustomText([1]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
required: true,
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
readOnly: true,
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(2, 1),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
validationRule: CheckboxValidationRules.SELECT_AT_LEAST,
|
||||||
|
validationLength: 2,
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(3, 0),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
validationRule: CheckboxValidationRules.SELECT_EXACTLY,
|
||||||
|
validationLength: 2,
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(3, 1),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.CHECKBOX,
|
||||||
|
fieldMeta: {
|
||||||
|
direction: 'vertical',
|
||||||
|
type: 'checkbox',
|
||||||
|
validationRule: CheckboxValidationRules.SELECT_AT_MOST,
|
||||||
|
validationLength: 2,
|
||||||
|
values: [
|
||||||
|
{ id: 1, checked: false, value: 'Option 1' },
|
||||||
|
{ id: 2, checked: false, value: 'Option 2' },
|
||||||
|
{ id: 3, checked: false, value: 'Option 3' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
page: 6,
|
||||||
|
...calculatePosition(3, 2),
|
||||||
|
customText: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PAGE 7 DROPDOWN
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
},
|
||||||
|
page: 7,
|
||||||
|
...calculatePosition(0, 0, 'full'),
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
defaultValue: 'Option 1',
|
||||||
|
},
|
||||||
|
page: 7,
|
||||||
|
...calculatePosition(1, 0),
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
page: 7,
|
||||||
|
...calculatePosition(2, 0),
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.DROPDOWN,
|
||||||
|
fieldMeta: {
|
||||||
|
values: [{ value: 'Option 1' }, { value: 'Option 2' }, { value: 'Option 3' }],
|
||||||
|
type: 'dropdown',
|
||||||
|
readOnly: true,
|
||||||
|
},
|
||||||
|
page: 7,
|
||||||
|
...calculatePosition(2, 1),
|
||||||
|
customText: 'Option 1',
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export const formatFieldMetaTestFields = FIELD_META_TEST_FIELDS.map((field, index) => {
|
||||||
|
return {
|
||||||
|
...field,
|
||||||
|
};
|
||||||
|
});
|
||||||
560
packages/app-tests/e2e/api/v2/envelopes-api.spec.ts
Normal file
560
packages/app-tests/e2e/api/v2/envelopes-api.spec.ts
Normal file
@ -0,0 +1,560 @@
|
|||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
import type { Team, User } from '@prisma/client';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { pick } from 'remeda';
|
||||||
|
|
||||||
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||||
|
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import {
|
||||||
|
DocumentDistributionMethod,
|
||||||
|
DocumentSigningOrder,
|
||||||
|
DocumentStatus,
|
||||||
|
DocumentVisibility,
|
||||||
|
EnvelopeType,
|
||||||
|
FieldType,
|
||||||
|
FolderType,
|
||||||
|
RecipientRole,
|
||||||
|
} from '@documenso/prisma/client';
|
||||||
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
|
import type { TCreateEnvelopeItemsPayload } from '@documenso/trpc/server/envelope-router/create-envelope-items.types';
|
||||||
|
import type {
|
||||||
|
TCreateEnvelopePayload,
|
||||||
|
TCreateEnvelopeResponse,
|
||||||
|
} from '@documenso/trpc/server/envelope-router/create-envelope.types';
|
||||||
|
import type { TCreateEnvelopeRecipientsRequest } from '@documenso/trpc/server/envelope-router/envelope-recipients/create-envelope-recipients.types';
|
||||||
|
import type { TGetEnvelopeResponse } from '@documenso/trpc/server/envelope-router/get-envelope.types';
|
||||||
|
import type { TUpdateEnvelopeRequest } from '@documenso/trpc/server/envelope-router/update-envelope.types';
|
||||||
|
|
||||||
|
import { formatAlignmentTestFields } from '../../../constants/field-alignment-pdf';
|
||||||
|
import { FIELD_META_TEST_FIELDS } from '../../../constants/field-meta-pdf';
|
||||||
|
|
||||||
|
const WEBAPP_BASE_URL = NEXT_PUBLIC_WEBAPP_URL();
|
||||||
|
const baseUrl = `${WEBAPP_BASE_URL}/api/v2-beta`;
|
||||||
|
|
||||||
|
test.describe.configure({
|
||||||
|
mode: 'parallel',
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('API V2 Envelopes', () => {
|
||||||
|
let userA: User, teamA: Team, userB: User, teamB: Team, tokenA: string, tokenB: string;
|
||||||
|
|
||||||
|
test.beforeEach(async () => {
|
||||||
|
({ user: userA, team: teamA } = await seedUser());
|
||||||
|
({ token: tokenA } = await createApiToken({
|
||||||
|
userId: userA.id,
|
||||||
|
teamId: teamA.id,
|
||||||
|
tokenName: 'userA',
|
||||||
|
expiresIn: null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
({ user: userB, team: teamB } = await seedUser());
|
||||||
|
({ token: tokenB } = await createApiToken({
|
||||||
|
userId: userB.id,
|
||||||
|
teamId: teamB.id,
|
||||||
|
tokenName: 'userB',
|
||||||
|
expiresIn: null,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Envelope create endpoint', () => {
|
||||||
|
test('should fail on invalid form', async ({ request }) => {
|
||||||
|
const payload = {
|
||||||
|
type: 'Invalid Type',
|
||||||
|
title: 'Test Envelope',
|
||||||
|
};
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
|
||||||
|
const res = await request.post(`${baseUrl}/envelope/create`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenB}` },
|
||||||
|
multipart: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.ok()).toBeFalsy();
|
||||||
|
expect(res.status()).toBe(400);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should create envelope with single file', async ({ request }) => {
|
||||||
|
const payload = {
|
||||||
|
type: EnvelopeType.TEMPLATE,
|
||||||
|
title: 'Test Envelope',
|
||||||
|
} satisfies TCreateEnvelopePayload;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
|
||||||
|
const files = [
|
||||||
|
{
|
||||||
|
name: 'field-font-alignment.pdf',
|
||||||
|
data: fs.readFileSync(
|
||||||
|
path.join(__dirname, '../../../../../assets/field-font-alignment.pdf'),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
formData.append('files', new File([file.data], file.name, { type: 'application/pdf' }));
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await request.post(`${baseUrl}/envelope/create`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenB}` },
|
||||||
|
multipart: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
expect(res.status()).toBe(200);
|
||||||
|
|
||||||
|
const response = (await res.json()) as TCreateEnvelopeResponse;
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findUnique({
|
||||||
|
where: {
|
||||||
|
id: response.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(envelope).toBeDefined();
|
||||||
|
expect(envelope?.title).toBe('Test Envelope');
|
||||||
|
expect(envelope?.type).toBe(EnvelopeType.TEMPLATE);
|
||||||
|
expect(envelope?.status).toBe(DocumentStatus.DRAFT);
|
||||||
|
expect(envelope?.envelopeItems.length).toBe(1);
|
||||||
|
expect(envelope?.envelopeItems[0].title).toBe('field-font-alignment.pdf');
|
||||||
|
expect(envelope?.envelopeItems[0].documentDataId).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should create envelope with multiple file', async ({ request }) => {
|
||||||
|
const folder = await prisma.folder.create({
|
||||||
|
data: {
|
||||||
|
name: 'Test Folder',
|
||||||
|
teamId: teamA.id,
|
||||||
|
userId: userA.id,
|
||||||
|
type: FolderType.DOCUMENT,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title: 'Envelope Title',
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
externalId: 'externalId',
|
||||||
|
visibility: DocumentVisibility.MANAGER_AND_ABOVE,
|
||||||
|
globalAccessAuth: ['ACCOUNT'],
|
||||||
|
formValues: {
|
||||||
|
hello: 'world',
|
||||||
|
},
|
||||||
|
folderId: folder.id,
|
||||||
|
recipients: [
|
||||||
|
{
|
||||||
|
email: userA.email,
|
||||||
|
name: 'Name',
|
||||||
|
role: RecipientRole.SIGNER,
|
||||||
|
accessAuth: ['TWO_FACTOR_AUTH'],
|
||||||
|
signingOrder: 1,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
identifier: 'field-font-alignment.pdf',
|
||||||
|
page: 1,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: FieldType.SIGNATURE,
|
||||||
|
identifier: 0,
|
||||||
|
page: 1,
|
||||||
|
positionX: 0,
|
||||||
|
positionY: 0,
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
subject: 'Subject',
|
||||||
|
message: 'Message',
|
||||||
|
timezone: 'Europe/Berlin',
|
||||||
|
dateFormat: 'dd.MM.yyyy',
|
||||||
|
distributionMethod: DocumentDistributionMethod.NONE,
|
||||||
|
signingOrder: DocumentSigningOrder.SEQUENTIAL,
|
||||||
|
allowDictateNextSigner: true,
|
||||||
|
redirectUrl: 'https://documenso.com',
|
||||||
|
language: 'de',
|
||||||
|
typedSignatureEnabled: true,
|
||||||
|
uploadSignatureEnabled: false,
|
||||||
|
drawSignatureEnabled: false,
|
||||||
|
emailReplyTo: userA.email,
|
||||||
|
emailSettings: {
|
||||||
|
recipientSigningRequest: false,
|
||||||
|
recipientRemoved: false,
|
||||||
|
recipientSigned: false,
|
||||||
|
documentPending: false,
|
||||||
|
documentCompleted: false,
|
||||||
|
documentDeleted: false,
|
||||||
|
ownerDocumentCompleted: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
label: 'Test Attachment',
|
||||||
|
data: 'https://documenso.com',
|
||||||
|
type: 'link',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} satisfies TCreateEnvelopePayload;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append('payload', JSON.stringify(payload));
|
||||||
|
|
||||||
|
const files = [
|
||||||
|
{
|
||||||
|
name: 'field-meta.pdf',
|
||||||
|
data: fs.readFileSync(path.join(__dirname, '../../../../../assets/field-meta.pdf')),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'field-font-alignment.pdf',
|
||||||
|
data: fs.readFileSync(
|
||||||
|
path.join(__dirname, '../../../../../assets/field-font-alignment.pdf'),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
formData.append('files', new File([file.data], file.name, { type: 'application/pdf' }));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should error since folder is not owned by the user.
|
||||||
|
const invalidRes = await request.post(`${baseUrl}/envelope/create`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenB}` },
|
||||||
|
multipart: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(invalidRes.ok()).toBeFalsy();
|
||||||
|
|
||||||
|
const res = await request.post(`${baseUrl}/envelope/create`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
multipart: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
expect(res.status()).toBe(200);
|
||||||
|
|
||||||
|
const response = (await res.json()) as TCreateEnvelopeResponse;
|
||||||
|
|
||||||
|
const envelope = await prisma.envelope.findUniqueOrThrow({
|
||||||
|
where: {
|
||||||
|
id: response.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentMeta: true,
|
||||||
|
envelopeItems: true,
|
||||||
|
recipients: true,
|
||||||
|
fields: true,
|
||||||
|
envelopeAttachments: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(userB.email);
|
||||||
|
|
||||||
|
expect(envelope.envelopeItems.length).toBe(2);
|
||||||
|
expect(envelope.envelopeItems[0].title).toBe('field-meta.pdf');
|
||||||
|
expect(envelope.envelopeItems[1].title).toBe('field-font-alignment.pdf');
|
||||||
|
|
||||||
|
expect(envelope.title).toBe(payload.title);
|
||||||
|
expect(envelope.type).toBe(payload.type);
|
||||||
|
expect(envelope.externalId).toBe(payload.externalId);
|
||||||
|
expect(envelope.visibility).toBe(payload.visibility);
|
||||||
|
expect(envelope.authOptions).toEqual({
|
||||||
|
globalAccessAuth: payload.globalAccessAuth,
|
||||||
|
globalActionAuth: [],
|
||||||
|
});
|
||||||
|
expect(envelope.formValues).toEqual(payload.formValues);
|
||||||
|
expect(envelope.folderId).toBe(payload.folderId);
|
||||||
|
|
||||||
|
expect(envelope.documentMeta.subject).toBe(payload.meta.subject);
|
||||||
|
expect(envelope.documentMeta.message).toBe(payload.meta.message);
|
||||||
|
expect(envelope.documentMeta.timezone).toBe(payload.meta.timezone);
|
||||||
|
expect(envelope.documentMeta.dateFormat).toBe(payload.meta.dateFormat);
|
||||||
|
expect(envelope.documentMeta.distributionMethod).toBe(payload.meta.distributionMethod);
|
||||||
|
expect(envelope.documentMeta.signingOrder).toBe(payload.meta.signingOrder);
|
||||||
|
expect(envelope.documentMeta.allowDictateNextSigner).toBe(
|
||||||
|
payload.meta.allowDictateNextSigner,
|
||||||
|
);
|
||||||
|
expect(envelope.documentMeta.redirectUrl).toBe(payload.meta.redirectUrl);
|
||||||
|
expect(envelope.documentMeta.language).toBe(payload.meta.language);
|
||||||
|
expect(envelope.documentMeta.typedSignatureEnabled).toBe(payload.meta.typedSignatureEnabled);
|
||||||
|
expect(envelope.documentMeta.uploadSignatureEnabled).toBe(
|
||||||
|
payload.meta.uploadSignatureEnabled,
|
||||||
|
);
|
||||||
|
expect(envelope.documentMeta.drawSignatureEnabled).toBe(payload.meta.drawSignatureEnabled);
|
||||||
|
expect(envelope.documentMeta.emailReplyTo).toBe(payload.meta.emailReplyTo);
|
||||||
|
expect(envelope.documentMeta.emailSettings).toEqual(payload.meta.emailSettings);
|
||||||
|
|
||||||
|
expect([
|
||||||
|
{
|
||||||
|
label: envelope.envelopeAttachments[0].label,
|
||||||
|
data: envelope.envelopeAttachments[0].data,
|
||||||
|
type: envelope.envelopeAttachments[0].type,
|
||||||
|
},
|
||||||
|
]).toEqual(payload.attachments);
|
||||||
|
|
||||||
|
const field = envelope.fields[0];
|
||||||
|
const recipient = envelope.recipients[0];
|
||||||
|
|
||||||
|
expect({
|
||||||
|
email: recipient.email,
|
||||||
|
name: recipient.name,
|
||||||
|
role: recipient.role,
|
||||||
|
signingOrder: recipient.signingOrder,
|
||||||
|
accessAuth: recipient.authOptions?.accessAuth,
|
||||||
|
}).toEqual(
|
||||||
|
pick(payload.recipients[0], ['email', 'name', 'role', 'signingOrder', 'accessAuth']),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect({
|
||||||
|
type: field.type,
|
||||||
|
page: field.page,
|
||||||
|
positionX: field.positionX.toNumber(),
|
||||||
|
positionY: field.positionY.toNumber(),
|
||||||
|
width: field.width.toNumber(),
|
||||||
|
height: field.height.toNumber(),
|
||||||
|
}).toEqual(
|
||||||
|
pick(payload.recipients[0].fields[0], [
|
||||||
|
'type',
|
||||||
|
'page',
|
||||||
|
'positionX',
|
||||||
|
'positionY',
|
||||||
|
'width',
|
||||||
|
'height',
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Expect string based ID to work.
|
||||||
|
expect(field.envelopeItemId).toBe(
|
||||||
|
envelope.envelopeItems.find((item) => item.title === 'field-font-alignment.pdf')?.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Expect index based ID to work.
|
||||||
|
expect(envelope.fields[1].envelopeItemId).toBe(
|
||||||
|
envelope.envelopeItems.find((item) => item.title === 'field-meta.pdf')?.id,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates envelopes with the two field test PDFs.
|
||||||
|
*/
|
||||||
|
test('Envelope full test', async ({ request }) => {
|
||||||
|
// Step 1: Create initial envelope with Prisma (with first envelope item)
|
||||||
|
const alignmentPdf = fs.readFileSync(
|
||||||
|
path.join(__dirname, '../../../../../assets/field-font-alignment.pdf'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fieldMetaPdf = fs.readFileSync(
|
||||||
|
path.join(__dirname, '../../../../../assets/field-meta.pdf'),
|
||||||
|
);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
formData.append(
|
||||||
|
'payload',
|
||||||
|
JSON.stringify({
|
||||||
|
type: EnvelopeType.DOCUMENT,
|
||||||
|
title: 'Envelope Full Field Test',
|
||||||
|
} satisfies TCreateEnvelopePayload),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only add one file for now.
|
||||||
|
formData.append(
|
||||||
|
'files',
|
||||||
|
new File([alignmentPdf], 'field-font-alignment.pdf', { type: 'application/pdf' }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const createEnvelopeRequest = await request.post(`${baseUrl}/envelope/create`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
multipart: formData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createEnvelopeRequest.ok()).toBeTruthy();
|
||||||
|
expect(createEnvelopeRequest.status()).toBe(200);
|
||||||
|
|
||||||
|
const { id: createdEnvelopeId }: TCreateEnvelopeResponse = await createEnvelopeRequest.json();
|
||||||
|
|
||||||
|
const getEnvelopeRequest = await request.get(`${baseUrl}/envelope/${createdEnvelopeId}`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
const createdEnvelope: TGetEnvelopeResponse = await getEnvelopeRequest.json();
|
||||||
|
|
||||||
|
// Might as well testing access control here as well.
|
||||||
|
const unauthRequest = await request.get(`${baseUrl}/envelope/${createdEnvelopeId}`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenB}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(unauthRequest.ok()).toBeFalsy();
|
||||||
|
expect(unauthRequest.status()).toBe(404);
|
||||||
|
|
||||||
|
// Step 2: Create second envelope item via API
|
||||||
|
const createEnvelopeItemsPayload: TCreateEnvelopeItemsPayload = {
|
||||||
|
envelopeId: createdEnvelope.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const createEnvelopeItemFormData = new FormData();
|
||||||
|
createEnvelopeItemFormData.append('payload', JSON.stringify(createEnvelopeItemsPayload));
|
||||||
|
createEnvelopeItemFormData.append(
|
||||||
|
'files',
|
||||||
|
new File([fieldMetaPdf], 'field-meta.pdf', { type: 'application/pdf' }),
|
||||||
|
);
|
||||||
|
|
||||||
|
const createItemsRes = await request.post(`${baseUrl}/envelope/item/create-many`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
multipart: createEnvelopeItemFormData,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createItemsRes.ok()).toBeTruthy();
|
||||||
|
expect(createItemsRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Step 3: Update envelope via API
|
||||||
|
const updateEnvelopeRequest: TUpdateEnvelopeRequest = {
|
||||||
|
envelopeId: createdEnvelope.id,
|
||||||
|
data: {
|
||||||
|
title: 'Envelope Full Field Test',
|
||||||
|
visibility: DocumentVisibility.MANAGER_AND_ABOVE,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateRes = await request.post(`${baseUrl}/envelope/update`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
data: updateEnvelopeRequest,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updateRes.ok()).toBeTruthy();
|
||||||
|
expect(updateRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Step 4: Create recipient via API
|
||||||
|
const createRecipientsRequest: TCreateEnvelopeRecipientsRequest = {
|
||||||
|
envelopeId: createdEnvelope.id,
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
email: userA.email,
|
||||||
|
name: userA.name || '',
|
||||||
|
role: RecipientRole.SIGNER,
|
||||||
|
accessAuth: [],
|
||||||
|
actionAuth: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const createRecipientsRes = await request.post(`${baseUrl}/envelope/recipient/create-many`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
data: createRecipientsRequest,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createRecipientsRes.ok()).toBeTruthy();
|
||||||
|
expect(createRecipientsRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Step 5: Get envelope to retrieve recipients and envelope items
|
||||||
|
const getRes = await request.get(`${baseUrl}/envelope/${createdEnvelope.id}`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(getRes.ok()).toBeTruthy();
|
||||||
|
expect(getRes.status()).toBe(200);
|
||||||
|
|
||||||
|
const envelopeResponse = (await getRes.json()) as TGetEnvelopeResponse;
|
||||||
|
|
||||||
|
const recipientId = envelopeResponse.recipients[0].id;
|
||||||
|
const alignmentItem = envelopeResponse.envelopeItems.find(
|
||||||
|
(item: { order: number }) => item.order === 1,
|
||||||
|
);
|
||||||
|
const fieldMetaItem = envelopeResponse.envelopeItems.find(
|
||||||
|
(item: { order: number }) => item.order === 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(recipientId).toBeDefined();
|
||||||
|
expect(alignmentItem).toBeDefined();
|
||||||
|
expect(fieldMetaItem).toBeDefined();
|
||||||
|
|
||||||
|
if (!alignmentItem || !fieldMetaItem) {
|
||||||
|
throw new Error('Envelope items not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 6: Create fields for first PDF (alignment fields)
|
||||||
|
const alignmentFieldsRequest = {
|
||||||
|
envelopeId: createdEnvelope.id,
|
||||||
|
data: formatAlignmentTestFields.map((field) => ({
|
||||||
|
recipientId,
|
||||||
|
envelopeItemId: alignmentItem.id,
|
||||||
|
type: field.type,
|
||||||
|
page: field.page,
|
||||||
|
positionX: field.positionX,
|
||||||
|
positionY: field.positionY,
|
||||||
|
width: field.width,
|
||||||
|
height: field.height,
|
||||||
|
fieldMeta: field.fieldMeta,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const createAlignmentFieldsRes = await request.post(`${baseUrl}/envelope/field/create-many`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
data: alignmentFieldsRequest,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createAlignmentFieldsRes.ok()).toBeTruthy();
|
||||||
|
expect(createAlignmentFieldsRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Step 7: Create fields for second PDF (field-meta fields)
|
||||||
|
const fieldMetaFieldsRequest = {
|
||||||
|
envelopeId: createdEnvelope.id,
|
||||||
|
data: FIELD_META_TEST_FIELDS.map((field) => ({
|
||||||
|
recipientId,
|
||||||
|
envelopeItemId: fieldMetaItem.id,
|
||||||
|
type: field.type,
|
||||||
|
page: field.page,
|
||||||
|
positionX: field.positionX,
|
||||||
|
positionY: field.positionY,
|
||||||
|
width: field.width,
|
||||||
|
height: field.height,
|
||||||
|
fieldMeta: field.fieldMeta,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const createFieldMetaFieldsRes = await request.post(`${baseUrl}/envelope/field/create-many`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
data: fieldMetaFieldsRequest,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createFieldMetaFieldsRes.ok()).toBeTruthy();
|
||||||
|
expect(createFieldMetaFieldsRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Step 8: Verify final envelope structure
|
||||||
|
const finalGetRes = await request.get(`${baseUrl}/envelope/${createdEnvelope.id}`, {
|
||||||
|
headers: { Authorization: `Bearer ${tokenA}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(finalGetRes.ok()).toBeTruthy();
|
||||||
|
const finalEnvelope = (await finalGetRes.json()) as TGetEnvelopeResponse;
|
||||||
|
|
||||||
|
// Verify structure
|
||||||
|
expect(finalEnvelope.envelopeItems.length).toBe(2);
|
||||||
|
expect(finalEnvelope.recipients.length).toBe(1);
|
||||||
|
expect(finalEnvelope.fields.length).toBe(
|
||||||
|
formatAlignmentTestFields.length + FIELD_META_TEST_FIELDS.length,
|
||||||
|
);
|
||||||
|
expect(finalEnvelope.title).toBe('Envelope Full Field Test');
|
||||||
|
expect(finalEnvelope.type).toBe(EnvelopeType.DOCUMENT);
|
||||||
|
|
||||||
|
console.log({
|
||||||
|
createdEnvelopeId: finalEnvelope.id,
|
||||||
|
userEmail: userA.email,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load Diff
293
packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts
Normal file
293
packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
// sort-imports-ignore
|
||||||
|
|
||||||
|
// ---- PATCH pdfjs-dist's canvas require BEFORE importing it ----
|
||||||
|
import Module from 'module';
|
||||||
|
import { Canvas, Image } from 'skia-canvas';
|
||||||
|
|
||||||
|
// Intercept require('canvas') and return skia-canvas equivalents
|
||||||
|
const originalRequire = Module.prototype.require;
|
||||||
|
Module.prototype.require = function (path: string) {
|
||||||
|
if (path === 'canvas') {
|
||||||
|
return {
|
||||||
|
createCanvas: (width: number, height: number) => new Canvas(width, height),
|
||||||
|
Image, // needed by pdfjs-dist
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line prefer-rest-params, @typescript-eslint/consistent-type-assertions
|
||||||
|
return originalRequire.apply(this, arguments as unknown as [string]);
|
||||||
|
};
|
||||||
|
|
||||||
|
import pixelMatch from 'pixelmatch';
|
||||||
|
import { PNG } from 'pngjs';
|
||||||
|
import type { TestInfo } from '@playwright/test';
|
||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
import { DocumentStatus } from '@prisma/client';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.js';
|
||||||
|
import { getEnvelopeDownloadUrl } from '@documenso/lib/utils/envelope-download';
|
||||||
|
import { prisma } from '@documenso/prisma';
|
||||||
|
import { seedAlignmentTestDocument } from '@documenso/prisma/seed/initial-seed';
|
||||||
|
import { seedUser } from '@documenso/prisma/seed/users';
|
||||||
|
|
||||||
|
import { apiSignin } from '../fixtures/authentication';
|
||||||
|
|
||||||
|
test.describe.configure({ mode: 'parallel', timeout: 60000 });
|
||||||
|
|
||||||
|
test.skip('field placement visual regression', async ({ page }, testInfo) => {
|
||||||
|
const { user, team } = await seedUser();
|
||||||
|
|
||||||
|
const envelope = await seedAlignmentTestDocument({
|
||||||
|
userId: user.id,
|
||||||
|
teamId: team.id,
|
||||||
|
recipientName: user.name || '',
|
||||||
|
recipientEmail: user.email,
|
||||||
|
insertFields: true,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = envelope.recipients[0].token;
|
||||||
|
|
||||||
|
const signUrl = `/sign/${token}`;
|
||||||
|
|
||||||
|
await apiSignin({
|
||||||
|
page,
|
||||||
|
email: user.email,
|
||||||
|
redirectPath: signUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: 'Complete' }).click();
|
||||||
|
await page.getByRole('button', { name: 'Sign' }).click();
|
||||||
|
await page.waitForURL(`${signUrl}/complete`);
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
const { status } = await prisma.envelope.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: envelope.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toBe(DocumentStatus.COMPLETED);
|
||||||
|
}).toPass({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: envelope.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
orderBy: {
|
||||||
|
order: 'asc',
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const storedImages = fs.readdirSync(path.join(__dirname, '../../visual-regression'));
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
completedDocument.envelopeItems.map(async (item) => {
|
||||||
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: item,
|
||||||
|
token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const pdfData = await fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
|
||||||
|
const loadedImages = storedImages
|
||||||
|
.filter((image) => image.includes(item.title))
|
||||||
|
.map((image) => fs.readFileSync(path.join(__dirname, '../../visual-regression', image)));
|
||||||
|
|
||||||
|
await compareSignedPdfWithImages({
|
||||||
|
id: item.title.replaceAll(' ', '-').toLowerCase(),
|
||||||
|
pdfData: new Uint8Array(pdfData),
|
||||||
|
images: loadedImages,
|
||||||
|
testInfo,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to download the envelope images when updating the visual regression test.
|
||||||
|
*
|
||||||
|
* DON'T COMMIT THIS WITHOUT THE "SKIP" COMMAND.
|
||||||
|
*/
|
||||||
|
test.skip('download envelope images', async ({ page }) => {
|
||||||
|
const { user, team } = await seedUser();
|
||||||
|
|
||||||
|
const envelope = await seedAlignmentTestDocument({
|
||||||
|
userId: user.id,
|
||||||
|
teamId: team.id,
|
||||||
|
recipientName: user.name || '',
|
||||||
|
recipientEmail: user.email,
|
||||||
|
insertFields: true,
|
||||||
|
status: DocumentStatus.PENDING,
|
||||||
|
});
|
||||||
|
|
||||||
|
const token = envelope.recipients[0].token;
|
||||||
|
|
||||||
|
const signUrl = `/sign/${token}`;
|
||||||
|
|
||||||
|
await apiSignin({
|
||||||
|
page,
|
||||||
|
email: user.email,
|
||||||
|
redirectPath: signUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.getByRole('heading', { name: 'Sign Document' })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: 'Complete' }).click();
|
||||||
|
await page.getByRole('button', { name: 'Sign' }).click();
|
||||||
|
await page.waitForURL(`${signUrl}/complete`);
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
const { status } = await prisma.envelope.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: envelope.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(status).toBe(DocumentStatus.COMPLETED);
|
||||||
|
}).toPass({
|
||||||
|
timeout: 10000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const completedDocument = await prisma.envelope.findFirstOrThrow({
|
||||||
|
where: {
|
||||||
|
id: envelope.id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
envelopeItems: {
|
||||||
|
orderBy: {
|
||||||
|
order: 'asc',
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
documentData: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
completedDocument.envelopeItems.map(async (item) => {
|
||||||
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: item,
|
||||||
|
token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const pdfData = await fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
|
||||||
|
const pdfImages = await renderPdfToImage(new Uint8Array(pdfData));
|
||||||
|
|
||||||
|
for (const [index, { image }] of pdfImages.entries()) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(__dirname, '../../visual-regression', `${item.title}-${index}.png`),
|
||||||
|
new Uint8Array(image),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function renderPdfToImage(pdfBytes: Uint8Array) {
|
||||||
|
const loadingTask = pdfjsLib.getDocument({ data: pdfBytes });
|
||||||
|
const pdf = await loadingTask.promise;
|
||||||
|
|
||||||
|
// Increase for higher resolution
|
||||||
|
const scale = 4;
|
||||||
|
|
||||||
|
return await Promise.all(
|
||||||
|
Array.from({ length: pdf.numPages }, async (_, index) => {
|
||||||
|
const page = await pdf.getPage(index + 1);
|
||||||
|
|
||||||
|
const viewport = page.getViewport({ scale });
|
||||||
|
|
||||||
|
const virtualCanvas = new Canvas(viewport.width, viewport.height);
|
||||||
|
const context = virtualCanvas.getContext('2d');
|
||||||
|
context.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
// @ts-expect-error skia-canvas context satisfies runtime requirements for pdfjs
|
||||||
|
await page.render({ canvasContext: context, viewport }).promise;
|
||||||
|
|
||||||
|
return {
|
||||||
|
image: await virtualCanvas.toBuffer('png'),
|
||||||
|
|
||||||
|
// Rounded down because the certificate page somehow gives dimensions with decimals
|
||||||
|
width: Math.floor(viewport.width),
|
||||||
|
height: Math.floor(viewport.height),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type CompareSignedPdfWithImagesOptions = {
|
||||||
|
id: string;
|
||||||
|
pdfData: Uint8Array;
|
||||||
|
images: Buffer[];
|
||||||
|
testInfo: TestInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
const compareSignedPdfWithImages = async ({
|
||||||
|
id,
|
||||||
|
pdfData,
|
||||||
|
images,
|
||||||
|
testInfo,
|
||||||
|
}: CompareSignedPdfWithImagesOptions) => {
|
||||||
|
const renderedImages = await renderPdfToImage(pdfData);
|
||||||
|
|
||||||
|
const blankCertificateFile = fs.readFileSync(
|
||||||
|
path.join(__dirname, '../../visual-regression/blank-certificate.png'),
|
||||||
|
);
|
||||||
|
const blankCertificateImage = PNG.sync.read(blankCertificateFile).data;
|
||||||
|
|
||||||
|
for (const [index, { image, width, height }] of renderedImages.entries()) {
|
||||||
|
const isCertificate = index === renderedImages.length - 1;
|
||||||
|
|
||||||
|
const diff = new PNG({ width, height });
|
||||||
|
|
||||||
|
const storedImage = PNG.sync.read(images[index]).data;
|
||||||
|
|
||||||
|
const newImage = PNG.sync.read(image).data;
|
||||||
|
|
||||||
|
const oldImage = isCertificate ? blankCertificateImage : storedImage;
|
||||||
|
|
||||||
|
const comparison = pixelMatch(
|
||||||
|
new Uint8Array(oldImage),
|
||||||
|
new Uint8Array(newImage),
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||||
|
diff.data as unknown as Uint8Array,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
{
|
||||||
|
threshold: 0.25,
|
||||||
|
// includeAA: true, // This allows stricter testing.
|
||||||
|
},
|
||||||
|
);
|
||||||
|
console.log(`${id}-${index}: ${comparison}`);
|
||||||
|
|
||||||
|
const diffFilePath = path.join(testInfo.outputPath(), `${id}-${index}-diff.png`);
|
||||||
|
const oldFilePath = path.join(testInfo.outputPath(), `${id}-${index}-old.png`);
|
||||||
|
const newFilePath = path.join(testInfo.outputPath(), `${id}-${index}-new.png`);
|
||||||
|
|
||||||
|
fs.writeFileSync(diffFilePath, new Uint8Array(PNG.sync.write(diff)));
|
||||||
|
fs.writeFileSync(oldFilePath, new Uint8Array(images[index]));
|
||||||
|
fs.writeFileSync(newFilePath, new Uint8Array(image));
|
||||||
|
|
||||||
|
if (isCertificate) {
|
||||||
|
// Expect the certificate to NOT be blank. Since the storedImage is blank.
|
||||||
|
expect.soft(comparison).toBeGreaterThan(20000);
|
||||||
|
} else {
|
||||||
|
expect.soft(comparison).toEqual(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
|
|||||||
import { DocumentStatus, FieldType } from '@prisma/client';
|
import { DocumentStatus, FieldType } from '@prisma/client';
|
||||||
|
|
||||||
import { getDocumentByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
import { getDocumentByToken } from '@documenso/lib/server-only/document/get-document-by-token';
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
import { getEnvelopeDownloadUrl } from '@documenso/lib/utils/envelope-download';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import { seedPendingDocumentWithFullFields } from '@documenso/prisma/seed/documents';
|
import { seedPendingDocumentWithFullFields } from '@documenso/prisma/seed/documents';
|
||||||
import { seedTeam } from '@documenso/prisma/seed/teams';
|
import { seedTeam } from '@documenso/prisma/seed/teams';
|
||||||
@ -25,20 +25,25 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentData = await prisma.documentData
|
const recipient = recipients[0];
|
||||||
|
|
||||||
|
const documentData = await prisma.envelopeItem
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
envelopeItem: {
|
|
||||||
envelopeId: document.id,
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => {
|
||||||
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: data,
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
return fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
});
|
||||||
|
|
||||||
const originalPdf = await PDFDocument.load(documentData);
|
const originalPdf = await PDFDocument.load(documentData);
|
||||||
|
|
||||||
const recipient = recipients[0];
|
|
||||||
|
|
||||||
// Sign the document
|
// Sign the document
|
||||||
await page.goto(`/sign/${recipient.token}`);
|
await page.goto(`/sign/${recipient.token}`);
|
||||||
|
|
||||||
@ -78,10 +83,17 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Todo: Envelopes
|
const firstDocumentData = completedDocument.envelopeItems[0];
|
||||||
const firstDocumentData = completedDocument.envelopeItems[0].documentData;
|
|
||||||
|
|
||||||
const completedDocumentData = await getFile(firstDocumentData);
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: firstDocumentData,
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const pdfData = await fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
|
||||||
|
const completedDocumentData = new Uint8Array(pdfData);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const pdfDoc = await PDFDocument.load(completedDocumentData);
|
const pdfDoc = await PDFDocument.load(completedDocumentData);
|
||||||
@ -118,20 +130,25 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentData = await prisma.documentData
|
const recipient = recipients[0];
|
||||||
|
|
||||||
|
const documentData = await prisma.envelopeItem
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
envelopeItem: {
|
|
||||||
envelopeId: document.id,
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => {
|
||||||
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: data,
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
return fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
});
|
||||||
|
|
||||||
const originalPdf = await PDFDocument.load(documentData);
|
const originalPdf = await PDFDocument.load(documentData);
|
||||||
|
|
||||||
const recipient = recipients[0];
|
|
||||||
|
|
||||||
// Sign the document
|
// Sign the document
|
||||||
await page.goto(`/sign/${recipient.token}`);
|
await page.goto(`/sign/${recipient.token}`);
|
||||||
|
|
||||||
@ -169,10 +186,17 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Todo: Envelopes
|
const firstDocumentData = completedDocument.envelopeItems[0];
|
||||||
const firstDocumentData = completedDocument.envelopeItems[0].documentData;
|
|
||||||
|
|
||||||
const completedDocumentData = await getFile(firstDocumentData);
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: firstDocumentData,
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const pdfData = await fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
|
||||||
|
const completedDocumentData = new Uint8Array(pdfData);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const completedPdf = await PDFDocument.load(completedDocumentData);
|
const completedPdf = await PDFDocument.load(completedDocumentData);
|
||||||
@ -209,19 +233,24 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentData = await prisma.documentData
|
const recipient = recipients[0];
|
||||||
|
|
||||||
|
const documentData = await prisma.envelopeItem
|
||||||
.findFirstOrThrow({
|
.findFirstOrThrow({
|
||||||
where: {
|
where: {
|
||||||
envelopeItem: {
|
|
||||||
envelopeId: document.id,
|
envelopeId: document.id,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.then(async (data) => getFile(data));
|
.then(async (data) => {
|
||||||
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: data,
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
return fetch(documentUrl).then(async (res) => await res.arrayBuffer());
|
||||||
|
});
|
||||||
|
|
||||||
const originalPdf = await PDFDocument.load(documentData);
|
const originalPdf = await PDFDocument.load(new Uint8Array(documentData));
|
||||||
|
|
||||||
const recipient = recipients[0];
|
|
||||||
|
|
||||||
// Sign the document
|
// Sign the document
|
||||||
await page.goto(`/sign/${recipient.token}`);
|
await page.goto(`/sign/${recipient.token}`);
|
||||||
@ -260,7 +289,15 @@ test.describe('Signing Certificate Tests', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const completedDocumentData = await getFile(completedDocument.envelopeItems[0].documentData);
|
const documentUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: completedDocument.envelopeItems[0],
|
||||||
|
token: recipient.token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const completedDocumentData = await fetch(documentUrl).then(
|
||||||
|
async (res) => await res.arrayBuffer(),
|
||||||
|
);
|
||||||
|
|
||||||
// Load the PDF and check number of pages
|
// Load the PDF and check number of pages
|
||||||
const completedPdf = await PDFDocument.load(completedDocumentData);
|
const completedPdf = await PDFDocument.load(completedDocumentData);
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { expect, test } from '@playwright/test';
|
||||||
import { DocumentDataType, TeamMemberRole } from '@prisma/client';
|
import { DocumentDataType, TeamMemberRole } from '@prisma/client';
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
|
||||||
@ -12,6 +11,10 @@ import { seedUser } from '@documenso/prisma/seed/users';
|
|||||||
import { apiSignin } from '../fixtures/authentication';
|
import { apiSignin } from '../fixtures/authentication';
|
||||||
|
|
||||||
const EXAMPLE_PDF_PATH = path.join(__dirname, '../../../../assets/example.pdf');
|
const EXAMPLE_PDF_PATH = path.join(__dirname, '../../../../assets/example.pdf');
|
||||||
|
const FIELD_ALIGNMENT_TEST_PDF_PATH = path.join(
|
||||||
|
__dirname,
|
||||||
|
'../../../../assets/field-font-alignment.pdf',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1. Create a template with all settings filled out
|
* 1. Create a template with all settings filled out
|
||||||
@ -233,10 +236,6 @@ test('[TEMPLATE]: should create a document from a template with custom document'
|
|||||||
const { user, team } = await seedUser();
|
const { user, team } = await seedUser();
|
||||||
const template = await seedBlankTemplate(user, team.id);
|
const template = await seedBlankTemplate(user, team.id);
|
||||||
|
|
||||||
// Create a temporary PDF file for upload
|
|
||||||
|
|
||||||
const pdfContent = fs.readFileSync(EXAMPLE_PDF_PATH).toString('base64');
|
|
||||||
|
|
||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
@ -277,7 +276,7 @@ test('[TEMPLATE]: should create a document from a template with custom document'
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await fileChooser.setFiles(EXAMPLE_PDF_PATH);
|
await fileChooser.setFiles(FIELD_ALIGNMENT_TEST_PDF_PATH);
|
||||||
|
|
||||||
// Wait for upload to complete
|
// Wait for upload to complete
|
||||||
await expect(page.getByText('Remove')).toBeVisible();
|
await expect(page.getByText('Remove')).toBeVisible();
|
||||||
@ -314,8 +313,12 @@ test('[TEMPLATE]: should create a document from a template with custom document'
|
|||||||
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
||||||
|
|
||||||
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
||||||
expect(firstDocumentData.data).toEqual(pdfContent);
|
// Todo: Doesn't really work due to normalization of the PDF which won't let us directly compare the data.
|
||||||
expect(firstDocumentData.initialData).toEqual(pdfContent);
|
// Probably need to do a pixel match
|
||||||
|
expect(firstDocumentData.data).not.toEqual(template.envelopeItems[0].documentData.data);
|
||||||
|
expect(firstDocumentData.initialData).not.toEqual(
|
||||||
|
template.envelopeItems[0].documentData.initialData,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
||||||
expect(firstDocumentData.data).toBeTruthy();
|
expect(firstDocumentData.data).toBeTruthy();
|
||||||
@ -336,8 +339,6 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
|
|
||||||
const template = await seedBlankTemplate(owner, team.id);
|
const template = await seedBlankTemplate(owner, team.id);
|
||||||
|
|
||||||
const pdfContent = fs.readFileSync(EXAMPLE_PDF_PATH).toString('base64');
|
|
||||||
|
|
||||||
await apiSignin({
|
await apiSignin({
|
||||||
page,
|
page,
|
||||||
email: owner.email,
|
email: owner.email,
|
||||||
@ -378,7 +379,7 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await fileChooser.setFiles(EXAMPLE_PDF_PATH);
|
await fileChooser.setFiles(FIELD_ALIGNMENT_TEST_PDF_PATH);
|
||||||
|
|
||||||
// Wait for upload to complete
|
// Wait for upload to complete
|
||||||
await expect(page.getByText('Remove')).toBeVisible();
|
await expect(page.getByText('Remove')).toBeVisible();
|
||||||
@ -416,8 +417,12 @@ test('[TEMPLATE]: should create a team document from a template with custom docu
|
|||||||
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
expect(firstDocumentData.type).toEqual(expectedDocumentDataType);
|
||||||
|
|
||||||
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
if (expectedDocumentDataType === DocumentDataType.BYTES_64) {
|
||||||
expect(firstDocumentData.data).toEqual(pdfContent);
|
// Todo: Doesn't really work due to normalization of the PDF which won't let us directly compare the data.
|
||||||
expect(firstDocumentData.initialData).toEqual(pdfContent);
|
// Probably need to do a pixel match
|
||||||
|
expect(firstDocumentData.data).not.toEqual(template.envelopeItems[0].documentData.data);
|
||||||
|
expect(firstDocumentData.initialData).not.toEqual(
|
||||||
|
template.envelopeItems[0].documentData.initialData,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
// For S3, we expect the data/initialData to be the S3 path (non-empty string)
|
||||||
expect(firstDocumentData.data).toBeTruthy();
|
expect(firstDocumentData.data).toBeTruthy();
|
||||||
|
|||||||
@ -15,7 +15,10 @@
|
|||||||
"@documenso/lib": "*",
|
"@documenso/lib": "*",
|
||||||
"@documenso/prisma": "*",
|
"@documenso/prisma": "*",
|
||||||
"@playwright/test": "1.52.0",
|
"@playwright/test": "1.52.0",
|
||||||
"@types/node": "^20"
|
"@types/node": "^20",
|
||||||
|
"@types/pngjs": "^6.0.5",
|
||||||
|
"pixelmatch": "^7.1.0",
|
||||||
|
"pngjs": "^7.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"start-server-and-test": "^2.0.12"
|
"start-server-and-test": "^2.0.12"
|
||||||
|
|||||||
@ -20,6 +20,6 @@
|
|||||||
"luxon": "^3.5.0",
|
"luxon": "^3.5.0",
|
||||||
"nanoid": "^5.1.5",
|
"nanoid": "^5.1.5",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,6 +19,6 @@
|
|||||||
"micro": "^10.0.1",
|
"micro": "^10.0.1",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,12 +1,14 @@
|
|||||||
import type { DocumentData } from '@prisma/client';
|
import type { EnvelopeItem } from '@prisma/client';
|
||||||
|
|
||||||
import { getFile } from '../universal/upload/get-file';
|
import { getEnvelopeDownloadUrl } from '../utils/envelope-download';
|
||||||
import { downloadFile } from './download-file';
|
import { downloadFile } from './download-file';
|
||||||
|
|
||||||
type DocumentVersion = 'original' | 'signed';
|
type DocumentVersion = 'original' | 'signed';
|
||||||
|
|
||||||
type DownloadPDFProps = {
|
type DownloadPDFProps = {
|
||||||
documentData: DocumentData;
|
envelopeItem: Pick<EnvelopeItem, 'id' | 'envelopeId'>;
|
||||||
|
token: string | undefined;
|
||||||
|
|
||||||
fileName?: string;
|
fileName?: string;
|
||||||
/**
|
/**
|
||||||
* Specifies which version of the document to download.
|
* Specifies which version of the document to download.
|
||||||
@ -17,18 +19,18 @@ type DownloadPDFProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const downloadPDF = async ({
|
export const downloadPDF = async ({
|
||||||
documentData,
|
envelopeItem,
|
||||||
|
token,
|
||||||
fileName,
|
fileName,
|
||||||
version = 'signed',
|
version = 'signed',
|
||||||
}: DownloadPDFProps) => {
|
}: DownloadPDFProps) => {
|
||||||
const bytes = await getFile({
|
const downloadUrl = getEnvelopeDownloadUrl({
|
||||||
type: documentData.type,
|
envelopeItem: envelopeItem,
|
||||||
data: version === 'signed' ? documentData.data : documentData.initialData,
|
token,
|
||||||
|
version,
|
||||||
});
|
});
|
||||||
|
|
||||||
const blob = new Blob([bytes], {
|
const blob = await fetch(downloadUrl).then(async (res) => await res.blob());
|
||||||
type: 'application/pdf',
|
|
||||||
});
|
|
||||||
|
|
||||||
const baseTitle = (fileName ?? 'document').replace(/\.pdf$/, '');
|
const baseTitle = (fileName ?? 'document').replace(/\.pdf$/, '');
|
||||||
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
const suffix = version === 'signed' ? '_signed.pdf' : '.pdf';
|
||||||
|
|||||||
@ -165,10 +165,7 @@ export const useEditorFields = ({
|
|||||||
const index = localFields.findIndex((field) => field.formId === formId);
|
const index = localFields.findIndex((field) => field.formId === formId);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
update(index, {
|
form.setValue(`fields.${index}.id`, id);
|
||||||
...localFields[index],
|
|
||||||
id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useRef } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
import Konva from 'konva';
|
import Konva from 'konva';
|
||||||
import type { RenderParameters } from 'pdfjs-dist/types/src/display/api';
|
import type { RenderParameters } from 'pdfjs-dist/types/src/display/api';
|
||||||
@ -25,6 +25,8 @@ export function usePageRenderer(renderFunction: RenderFunction) {
|
|||||||
const stage = useRef<Konva.Stage | null>(null);
|
const stage = useRef<Konva.Stage | null>(null);
|
||||||
const pageLayer = useRef<Konva.Layer | null>(null);
|
const pageLayer = useRef<Konva.Layer | null>(null);
|
||||||
|
|
||||||
|
const [renderError, setRenderError] = useState<boolean>(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The raw viewport with no scaling. Basically the actual PDF size.
|
* The raw viewport with no scaling. Basically the actual PDF size.
|
||||||
*/
|
*/
|
||||||
@ -122,5 +124,7 @@ export function usePageRenderer(renderFunction: RenderFunction) {
|
|||||||
unscaledViewport,
|
unscaledViewport,
|
||||||
scaledViewport,
|
scaledViewport,
|
||||||
pageContext,
|
pageContext,
|
||||||
|
renderError,
|
||||||
|
setRenderError,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,6 +46,7 @@ type EnvelopeEditorProviderValue = {
|
|||||||
setLocalEnvelope: (localEnvelope: Partial<TEnvelope>) => void;
|
setLocalEnvelope: (localEnvelope: Partial<TEnvelope>) => void;
|
||||||
|
|
||||||
updateEnvelope: (envelopeUpdates: UpdateEnvelopePayload) => void;
|
updateEnvelope: (envelopeUpdates: UpdateEnvelopePayload) => void;
|
||||||
|
updateEnvelopeAsync: (envelopeUpdates: UpdateEnvelopePayload) => Promise<void>;
|
||||||
setRecipientsDebounced: (recipients: TSetEnvelopeRecipientsRequest['recipients']) => void;
|
setRecipientsDebounced: (recipients: TSetEnvelopeRecipientsRequest['recipients']) => void;
|
||||||
setRecipientsAsync: (recipients: TSetEnvelopeRecipientsRequest['recipients']) => Promise<void>;
|
setRecipientsAsync: (recipients: TSetEnvelopeRecipientsRequest['recipients']) => Promise<void>;
|
||||||
|
|
||||||
@ -66,8 +67,6 @@ type EnvelopeEditorProviderValue = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
syncEnvelope: () => Promise<void>;
|
syncEnvelope: () => Promise<void>;
|
||||||
// refetchEnvelope: () => Promise<void>;
|
|
||||||
// updateEnvelope: (envelope: TEnvelope) => Promise<void>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
interface EnvelopeEditorProviderProps {
|
interface EnvelopeEditorProviderProps {
|
||||||
@ -151,7 +150,7 @@ export const EnvelopeEditorProvider = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const envelopeRecipientSetMutationQuery = trpc.envelope.recipient.set.useMutation({
|
const envelopeRecipientSetMutationQuery = trpc.envelope.recipient.set.useMutation({
|
||||||
onSuccess: ({ recipients }) => {
|
onSuccess: ({ data: recipients }) => {
|
||||||
setEnvelope((prev) => ({
|
setEnvelope((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
recipients,
|
recipients,
|
||||||
@ -197,7 +196,7 @@ export const EnvelopeEditorProvider = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Insert the IDs into the local fields.
|
// Insert the IDs into the local fields.
|
||||||
envelopeFields.fields.forEach((field) => {
|
envelopeFields.data.forEach((field) => {
|
||||||
const localField = localFields.find((localField) => localField.formId === field.formId);
|
const localField = localFields.find((localField) => localField.formId === field.formId);
|
||||||
|
|
||||||
if (localField && !localField.id) {
|
if (localField && !localField.id) {
|
||||||
@ -215,7 +214,6 @@ export const EnvelopeEditorProvider = ({
|
|||||||
} = useEnvelopeAutosave(async (envelopeUpdates: UpdateEnvelopePayload) => {
|
} = useEnvelopeAutosave(async (envelopeUpdates: UpdateEnvelopePayload) => {
|
||||||
await envelopeUpdateMutationQuery.mutateAsync({
|
await envelopeUpdateMutationQuery.mutateAsync({
|
||||||
envelopeId: envelope.id,
|
envelopeId: envelope.id,
|
||||||
envelopeType: envelope.type,
|
|
||||||
data: envelopeUpdates.data,
|
data: envelopeUpdates.data,
|
||||||
meta: envelopeUpdates.meta,
|
meta: envelopeUpdates.meta,
|
||||||
});
|
});
|
||||||
@ -237,6 +235,13 @@ export const EnvelopeEditorProvider = ({
|
|||||||
setEnvelopeDebounced(envelopeUpdates);
|
setEnvelopeDebounced(envelopeUpdates);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateEnvelopeAsync = async (envelopeUpdates: UpdateEnvelopePayload) => {
|
||||||
|
await envelopeUpdateMutationQuery.mutateAsync({
|
||||||
|
envelopeId: envelope.id,
|
||||||
|
...envelopeUpdates,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const getRecipientColorKey = useCallback(
|
const getRecipientColorKey = useCallback(
|
||||||
(recipientId: number) => {
|
(recipientId: number) => {
|
||||||
const recipientIndex = envelope.recipients.findIndex(
|
const recipientIndex = envelope.recipients.findIndex(
|
||||||
@ -324,6 +329,7 @@ export const EnvelopeEditorProvider = ({
|
|||||||
setLocalEnvelope,
|
setLocalEnvelope,
|
||||||
getRecipientColorKey,
|
getRecipientColorKey,
|
||||||
updateEnvelope,
|
updateEnvelope,
|
||||||
|
updateEnvelopeAsync,
|
||||||
setRecipientsDebounced,
|
setRecipientsDebounced,
|
||||||
setRecipientsAsync,
|
setRecipientsAsync,
|
||||||
editorFields,
|
editorFields,
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import type { DocumentData } from '@prisma/client';
|
import type { Field, Recipient } from '@prisma/client';
|
||||||
|
|
||||||
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
import type { TRecipientColor } from '@documenso/ui/lib/recipient-colors';
|
||||||
import { AVAILABLE_RECIPIENT_COLORS } from '@documenso/ui/lib/recipient-colors';
|
import { AVAILABLE_RECIPIENT_COLORS } from '@documenso/ui/lib/recipient-colors';
|
||||||
|
|
||||||
import type { TEnvelope } from '../../types/envelope';
|
import type { TEnvelope } from '../../types/envelope';
|
||||||
import { getFile } from '../../universal/upload/get-file';
|
import type { FieldRenderMode } from '../../universal/field-renderer/render-field';
|
||||||
|
import { getEnvelopeDownloadUrl } from '../../utils/envelope-download';
|
||||||
|
|
||||||
type FileData =
|
type FileData =
|
||||||
| {
|
| {
|
||||||
@ -18,19 +19,31 @@ type FileData =
|
|||||||
status: 'loaded';
|
status: 'loaded';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type EnvelopeRenderOverrideSettings = {
|
||||||
|
mode?: FieldRenderMode;
|
||||||
|
showRecipientTooltip?: boolean;
|
||||||
|
showRecipientSigningStatus?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
type EnvelopeRenderItem = TEnvelope['envelopeItems'][number];
|
type EnvelopeRenderItem = TEnvelope['envelopeItems'][number];
|
||||||
|
|
||||||
type EnvelopeRenderProviderValue = {
|
type EnvelopeRenderProviderValue = {
|
||||||
getPdfBuffer: (documentDataId: string) => FileData | null;
|
getPdfBuffer: (envelopeItemId: string) => FileData | null;
|
||||||
envelopeItems: EnvelopeRenderItem[];
|
envelopeItems: EnvelopeRenderItem[];
|
||||||
currentEnvelopeItem: EnvelopeRenderItem | null;
|
currentEnvelopeItem: EnvelopeRenderItem | null;
|
||||||
setCurrentEnvelopeItem: (envelopeItemId: string) => void;
|
setCurrentEnvelopeItem: (envelopeItemId: string) => void;
|
||||||
fields: TEnvelope['fields'];
|
fields: Field[];
|
||||||
|
recipients: Pick<Recipient, 'id' | 'name' | 'email' | 'signingStatus'>[];
|
||||||
getRecipientColorKey: (recipientId: number) => TRecipientColor;
|
getRecipientColorKey: (recipientId: number) => TRecipientColor;
|
||||||
|
|
||||||
|
renderError: boolean;
|
||||||
|
setRenderError: (renderError: boolean) => void;
|
||||||
|
overrideSettings?: EnvelopeRenderOverrideSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface EnvelopeRenderProviderProps {
|
interface EnvelopeRenderProviderProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|
||||||
envelope: Pick<TEnvelope, 'envelopeItems'>;
|
envelope: Pick<TEnvelope, 'envelopeItems'>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,14 +51,27 @@ interface EnvelopeRenderProviderProps {
|
|||||||
*
|
*
|
||||||
* Only pass if the CustomRenderer you are passing in wants fields.
|
* Only pass if the CustomRenderer you are passing in wants fields.
|
||||||
*/
|
*/
|
||||||
fields?: TEnvelope['fields'];
|
fields?: Field[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional recipient IDs used to determine the color of the fields.
|
* Optional recipient used to determine the color of the fields and hover
|
||||||
|
* previews.
|
||||||
*
|
*
|
||||||
* Only required for generic page renderers.
|
* Only required for generic page renderers.
|
||||||
*/
|
*/
|
||||||
recipientIds?: number[];
|
recipients?: Pick<Recipient, 'id' | 'name' | 'email' | 'signingStatus'>[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The token to access the envelope.
|
||||||
|
*
|
||||||
|
* If not provided, it will be assumed that the current user can access the document.
|
||||||
|
*/
|
||||||
|
token: string | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom override settings for generic page renderers.
|
||||||
|
*/
|
||||||
|
overrideSettings?: EnvelopeRenderOverrideSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EnvelopeRenderContext = createContext<EnvelopeRenderProviderValue | null>(null);
|
const EnvelopeRenderContext = createContext<EnvelopeRenderProviderValue | null>(null);
|
||||||
@ -67,39 +93,51 @@ export const EnvelopeRenderProvider = ({
|
|||||||
children,
|
children,
|
||||||
envelope,
|
envelope,
|
||||||
fields,
|
fields,
|
||||||
recipientIds = [],
|
token,
|
||||||
|
recipients = [],
|
||||||
|
overrideSettings,
|
||||||
}: EnvelopeRenderProviderProps) => {
|
}: EnvelopeRenderProviderProps) => {
|
||||||
// Indexed by documentDataId.
|
// Indexed by documentDataId.
|
||||||
const [files, setFiles] = useState<Record<string, FileData>>({});
|
const [files, setFiles] = useState<Record<string, FileData>>({});
|
||||||
|
|
||||||
const [currentItem, setItem] = useState<EnvelopeRenderItem | null>(null);
|
const [currentItem, setItem] = useState<EnvelopeRenderItem | null>(null);
|
||||||
|
|
||||||
|
const [renderError, setRenderError] = useState<boolean>(false);
|
||||||
|
|
||||||
const envelopeItems = useMemo(
|
const envelopeItems = useMemo(
|
||||||
() => envelope.envelopeItems.sort((a, b) => a.order - b.order),
|
() => envelope.envelopeItems.sort((a, b) => a.order - b.order),
|
||||||
[envelope.envelopeItems],
|
[envelope.envelopeItems],
|
||||||
);
|
);
|
||||||
|
|
||||||
const loadEnvelopeItemPdfFile = async (documentData: DocumentData) => {
|
const loadEnvelopeItemPdfFile = async (envelopeItem: EnvelopeRenderItem) => {
|
||||||
if (files[documentData.id]?.status === 'loading') {
|
if (files[envelopeItem.id]?.status === 'loading') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!files[documentData.id]) {
|
if (!files[envelopeItem.id]) {
|
||||||
setFiles((prev) => ({
|
setFiles((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[documentData.id]: {
|
[envelopeItem.id]: {
|
||||||
status: 'loading',
|
status: 'loading',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const file = await getFile(documentData);
|
const downloadUrl = getEnvelopeDownloadUrl({
|
||||||
|
envelopeItem: envelopeItem,
|
||||||
|
token,
|
||||||
|
version: 'signed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const blob = await fetch(downloadUrl).then(async (res) => await res.blob());
|
||||||
|
|
||||||
|
const file = await blob.arrayBuffer();
|
||||||
|
|
||||||
setFiles((prev) => ({
|
setFiles((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[documentData.id]: {
|
[envelopeItem.id]: {
|
||||||
file,
|
file: new Uint8Array(file),
|
||||||
status: 'loaded',
|
status: 'loaded',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@ -108,7 +146,7 @@ export const EnvelopeRenderProvider = ({
|
|||||||
|
|
||||||
setFiles((prev) => ({
|
setFiles((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[documentData.id]: {
|
[envelopeItem.id]: {
|
||||||
status: 'error',
|
status: 'error',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@ -116,8 +154,8 @@ export const EnvelopeRenderProvider = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getPdfBuffer = useCallback(
|
const getPdfBuffer = useCallback(
|
||||||
(documentDataId: string) => {
|
(envelopeItemId: string) => {
|
||||||
return files[documentDataId] || null;
|
return files[envelopeItemId] || null;
|
||||||
},
|
},
|
||||||
[files],
|
[files],
|
||||||
);
|
);
|
||||||
@ -137,13 +175,18 @@ export const EnvelopeRenderProvider = ({
|
|||||||
|
|
||||||
// Look for any missing pdf files and load them.
|
// Look for any missing pdf files and load them.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const missingFiles = envelope.envelopeItems.filter((item) => !files[item.documentDataId]);
|
const missingFiles = envelope.envelopeItems.filter((item) => !files[item.id]);
|
||||||
|
|
||||||
for (const item of missingFiles) {
|
for (const item of missingFiles) {
|
||||||
void loadEnvelopeItemPdfFile(item.documentData);
|
void loadEnvelopeItemPdfFile(item);
|
||||||
}
|
}
|
||||||
}, [envelope.envelopeItems]);
|
}, [envelope.envelopeItems]);
|
||||||
|
|
||||||
|
const recipientIds = useMemo(
|
||||||
|
() => recipients.map((recipient) => recipient.id).sort(),
|
||||||
|
[recipients],
|
||||||
|
);
|
||||||
|
|
||||||
const getRecipientColorKey = useCallback(
|
const getRecipientColorKey = useCallback(
|
||||||
(recipientId: number) => {
|
(recipientId: number) => {
|
||||||
const recipientIndex = recipientIds.findIndex((id) => id === recipientId);
|
const recipientIndex = recipientIds.findIndex((id) => id === recipientId);
|
||||||
@ -163,7 +206,11 @@ export const EnvelopeRenderProvider = ({
|
|||||||
currentEnvelopeItem: currentItem,
|
currentEnvelopeItem: currentItem,
|
||||||
setCurrentEnvelopeItem,
|
setCurrentEnvelopeItem,
|
||||||
fields: fields ?? [],
|
fields: fields ?? [],
|
||||||
|
recipients,
|
||||||
getRecipientColorKey,
|
getRecipientColorKey,
|
||||||
|
renderError,
|
||||||
|
setRenderError,
|
||||||
|
overrideSettings,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export const NEXT_PRIVATE_INTERNAL_WEBAPP_URL =
|
|||||||
export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED') === 'true';
|
export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED') === 'true';
|
||||||
|
|
||||||
export const API_V2_BETA_URL = '/api/v2-beta';
|
export const API_V2_BETA_URL = '/api/v2-beta';
|
||||||
|
export const API_V2_URL = '/api/v2';
|
||||||
|
|
||||||
export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com';
|
export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com';
|
||||||
|
|
||||||
|
|||||||
@ -55,7 +55,7 @@
|
|||||||
"skia-canvas": "^3.0.8",
|
"skia-canvas": "^3.0.8",
|
||||||
"stripe": "^12.7.0",
|
"stripe": "^12.7.0",
|
||||||
"ts-pattern": "^5.0.5",
|
"ts-pattern": "^5.0.5",
|
||||||
"zod": "3.24.1"
|
"zod": "^3.25.76"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/browser-chromium": "1.52.0",
|
"@playwright/browser-chromium": "1.52.0",
|
||||||
|
|||||||
@ -78,6 +78,14 @@ export const adminFindDocuments = async ({
|
|||||||
url: true,
|
url: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
envelopeId: true,
|
||||||
|
title: true,
|
||||||
|
order: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.envelope.count({
|
prisma.envelope.count({
|
||||||
|
|||||||
@ -248,6 +248,14 @@ export const findDocuments = async ({
|
|||||||
url: true,
|
url: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
envelopeItems: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
envelopeId: true,
|
||||||
|
title: true,
|
||||||
|
order: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.envelope.count({
|
prisma.envelope.count({
|
||||||
|
|||||||
@ -92,6 +92,10 @@ export const getDocumentAndSenderByToken = async ({
|
|||||||
},
|
},
|
||||||
envelopeItems: {
|
envelopeItems: {
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
order: true,
|
||||||
|
envelopeId: true,
|
||||||
documentData: true,
|
documentData: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -63,5 +63,8 @@ export const getDocumentWithDetailsById = async ({
|
|||||||
documentId: legacyDocumentId,
|
documentId: legacyDocumentId,
|
||||||
password: null,
|
password: null,
|
||||||
},
|
},
|
||||||
|
envelopeItems: envelope.envelopeItems.map((envelopeItem) => ({
|
||||||
|
...envelopeItem,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,7 +20,12 @@ import { validateCheckboxLength } from '../../advanced-fields-validation/validat
|
|||||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||||
import { jobs } from '../../jobs/client';
|
import { jobs } from '../../jobs/client';
|
||||||
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
import { extractDerivedDocumentEmailSettings } from '../../types/document-email';
|
||||||
import { ZCheckboxFieldMeta, ZDropdownFieldMeta, ZRadioFieldMeta } from '../../types/field-meta';
|
import {
|
||||||
|
ZCheckboxFieldMeta,
|
||||||
|
ZDropdownFieldMeta,
|
||||||
|
ZFieldAndMetaSchema,
|
||||||
|
ZRadioFieldMeta,
|
||||||
|
} from '../../types/field-meta';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapEnvelopeToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
@ -174,9 +179,20 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
const fieldsToAutoInsert: { fieldId: number; customText: string }[] = [];
|
const fieldsToAutoInsert: { fieldId: number; customText: string }[] = [];
|
||||||
|
|
||||||
// Auto insert radio and checkboxes that have default values.
|
// Validate and autoinsert fields for V2 envelopes.
|
||||||
if (envelope.internalVersion === 2) {
|
if (envelope.internalVersion === 2) {
|
||||||
for (const field of envelope.fields) {
|
for (const unknownField of envelope.fields) {
|
||||||
|
const parsedField = ZFieldAndMetaSchema.safeParse(unknownField);
|
||||||
|
|
||||||
|
if (parsedField.error) {
|
||||||
|
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||||
|
message: 'One or more fields have invalid metadata. Error: ' + parsedField.error.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const field = parsedField.data;
|
||||||
|
const fieldId = unknownField.id;
|
||||||
|
|
||||||
if (field.type === FieldType.RADIO) {
|
if (field.type === FieldType.RADIO) {
|
||||||
const { values = [] } = ZRadioFieldMeta.parse(field.fieldMeta);
|
const { values = [] } = ZRadioFieldMeta.parse(field.fieldMeta);
|
||||||
|
|
||||||
@ -184,7 +200,7 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
if (checkedItemIndex !== -1) {
|
if (checkedItemIndex !== -1) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId: field.id,
|
fieldId,
|
||||||
customText: toRadioCustomText(checkedItemIndex),
|
customText: toRadioCustomText(checkedItemIndex),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -195,7 +211,7 @@ export const sendDocument = async ({
|
|||||||
|
|
||||||
if (defaultValue && values.some((value) => value.value === defaultValue)) {
|
if (defaultValue && values.some((value) => value.value === defaultValue)) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId: field.id,
|
fieldId,
|
||||||
customText: defaultValue,
|
customText: defaultValue,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -234,9 +250,9 @@ export const sendDocument = async ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValid) {
|
if (isValid && checkedIndices.length > 0) {
|
||||||
fieldsToAutoInsert.push({
|
fieldsToAutoInsert.push({
|
||||||
fieldId: field.id,
|
fieldId,
|
||||||
customText: toCheckboxCustomText(checkedIndices),
|
customText: toCheckboxCustomText(checkedIndices),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,11 +16,16 @@ import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-reques
|
|||||||
import { nanoid, prefixedId } from '@documenso/lib/universal/id';
|
import { nanoid, prefixedId } from '@documenso/lib/universal/id';
|
||||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import type { TCreateEnvelopeRequest } from '@documenso/trpc/server/envelope-router/create-envelope.types';
|
|
||||||
|
|
||||||
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
import type {
|
||||||
|
TDocumentAccessAuthTypes,
|
||||||
|
TDocumentActionAuthTypes,
|
||||||
|
TRecipientAccessAuthTypes,
|
||||||
|
TRecipientActionAuthTypes,
|
||||||
|
} from '../../types/document-auth';
|
||||||
import type { TDocumentFormValues } from '../../types/document-form-values';
|
import type { TDocumentFormValues } from '../../types/document-form-values';
|
||||||
import type { TEnvelopeAttachmentType } from '../../types/envelope-attachment';
|
import type { TEnvelopeAttachmentType } from '../../types/envelope-attachment';
|
||||||
|
import type { TFieldAndMeta } from '../../types/field-meta';
|
||||||
import {
|
import {
|
||||||
ZWebhookDocumentSchema,
|
ZWebhookDocumentSchema,
|
||||||
mapEnvelopeToWebhookDocumentPayload,
|
mapEnvelopeToWebhookDocumentPayload,
|
||||||
@ -34,6 +39,25 @@ import { incrementDocumentId, incrementTemplateId } from '../envelope/increment-
|
|||||||
import { getTeamSettings } from '../team/get-team-settings';
|
import { getTeamSettings } from '../team/get-team-settings';
|
||||||
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
import { triggerWebhook } from '../webhooks/trigger/trigger-webhook';
|
||||||
|
|
||||||
|
type CreateEnvelopeRecipientFieldOptions = TFieldAndMeta & {
|
||||||
|
documentDataId: string;
|
||||||
|
page: number;
|
||||||
|
positionX: number;
|
||||||
|
positionY: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CreateEnvelopeRecipientOptions = {
|
||||||
|
email: string;
|
||||||
|
name: string;
|
||||||
|
role: RecipientRole;
|
||||||
|
signingOrder?: number;
|
||||||
|
accessAuth?: TRecipientAccessAuthTypes[];
|
||||||
|
actionAuth?: TRecipientActionAuthTypes[];
|
||||||
|
fields?: CreateEnvelopeRecipientFieldOptions[];
|
||||||
|
};
|
||||||
|
|
||||||
export type CreateEnvelopeOptions = {
|
export type CreateEnvelopeOptions = {
|
||||||
userId: number;
|
userId: number;
|
||||||
teamId: number;
|
teamId: number;
|
||||||
@ -46,7 +70,6 @@ export type CreateEnvelopeOptions = {
|
|||||||
envelopeItems: { title?: string; documentDataId: string; order?: number }[];
|
envelopeItems: { title?: string; documentDataId: string; order?: number }[];
|
||||||
formValues?: TDocumentFormValues;
|
formValues?: TDocumentFormValues;
|
||||||
|
|
||||||
timezone?: string;
|
|
||||||
userTimezone?: string;
|
userTimezone?: string;
|
||||||
|
|
||||||
templateType?: TemplateType;
|
templateType?: TemplateType;
|
||||||
@ -56,7 +79,7 @@ export type CreateEnvelopeOptions = {
|
|||||||
visibility?: DocumentVisibility;
|
visibility?: DocumentVisibility;
|
||||||
globalAccessAuth?: TDocumentAccessAuthTypes[];
|
globalAccessAuth?: TDocumentAccessAuthTypes[];
|
||||||
globalActionAuth?: TDocumentActionAuthTypes[];
|
globalActionAuth?: TDocumentActionAuthTypes[];
|
||||||
recipients?: TCreateEnvelopeRequest['recipients'];
|
recipients?: CreateEnvelopeRecipientOptions[];
|
||||||
folderId?: string;
|
folderId?: string;
|
||||||
};
|
};
|
||||||
attachments?: Array<{
|
attachments?: Array<{
|
||||||
@ -83,7 +106,6 @@ export const createEnvelope = async ({
|
|||||||
title,
|
title,
|
||||||
externalId,
|
externalId,
|
||||||
formValues,
|
formValues,
|
||||||
timezone,
|
|
||||||
userTimezone,
|
userTimezone,
|
||||||
folderId,
|
folderId,
|
||||||
templateType,
|
templateType,
|
||||||
@ -142,6 +164,7 @@ export const createEnvelope = async ({
|
|||||||
let envelopeItems: { title?: string; documentDataId: string; order?: number }[] =
|
let envelopeItems: { title?: string; documentDataId: string; order?: number }[] =
|
||||||
data.envelopeItems;
|
data.envelopeItems;
|
||||||
|
|
||||||
|
// Todo: Envelopes - Remove
|
||||||
if (normalizePdf) {
|
if (normalizePdf) {
|
||||||
envelopeItems = await Promise.all(
|
envelopeItems = await Promise.all(
|
||||||
data.envelopeItems.map(async (item) => {
|
data.envelopeItems.map(async (item) => {
|
||||||
@ -219,7 +242,7 @@ export const createEnvelope = async ({
|
|||||||
|
|
||||||
// userTimezone is last because it's always passed in regardless of the organisation/team settings
|
// userTimezone is last because it's always passed in regardless of the organisation/team settings
|
||||||
// for uploads from the frontend
|
// for uploads from the frontend
|
||||||
const timezoneToUse = timezone || settings.documentTimezone || userTimezone;
|
const timezoneToUse = meta?.timezone || settings.documentTimezone || userTimezone;
|
||||||
|
|
||||||
const documentMeta = await prisma.documentMeta.create({
|
const documentMeta = await prisma.documentMeta.create({
|
||||||
data: extractDerivedDocumentMeta(settings, {
|
data: extractDerivedDocumentMeta(settings, {
|
||||||
|
|||||||
@ -143,7 +143,7 @@ export const getEnvelopeForDirectTemplateSigning = async ({
|
|||||||
envelope,
|
envelope,
|
||||||
recipient: {
|
recipient: {
|
||||||
...recipient,
|
...recipient,
|
||||||
token: envelope.directLink?.token || '',
|
directToken: envelope.directLink?.token || '',
|
||||||
},
|
},
|
||||||
recipientSignature: null,
|
recipientSignature: null,
|
||||||
isRecipientsTurn: true,
|
isRecipientsTurn: true,
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { DocumentSigningOrder, DocumentStatus, EnvelopeType, SigningStatus } fro
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
import DocumentDataSchema from '@documenso/prisma/generated/zod/modelSchema/DocumentDataSchema';
|
|
||||||
import DocumentMetaSchema from '@documenso/prisma/generated/zod/modelSchema/DocumentMetaSchema';
|
import DocumentMetaSchema from '@documenso/prisma/generated/zod/modelSchema/DocumentMetaSchema';
|
||||||
import EnvelopeItemSchema from '@documenso/prisma/generated/zod/modelSchema/EnvelopeItemSchema';
|
import EnvelopeItemSchema from '@documenso/prisma/generated/zod/modelSchema/EnvelopeItemSchema';
|
||||||
import EnvelopeSchema from '@documenso/prisma/generated/zod/modelSchema/EnvelopeSchema';
|
import EnvelopeSchema from '@documenso/prisma/generated/zod/modelSchema/EnvelopeSchema';
|
||||||
@ -72,20 +71,11 @@ export const ZEnvelopeForSigningResponse = z.object({
|
|||||||
.array(),
|
.array(),
|
||||||
|
|
||||||
envelopeItems: EnvelopeItemSchema.pick({
|
envelopeItems: EnvelopeItemSchema.pick({
|
||||||
|
envelopeId: true,
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
documentDataId: true,
|
|
||||||
order: true,
|
order: true,
|
||||||
})
|
}).array(),
|
||||||
.extend({
|
|
||||||
documentData: DocumentDataSchema.pick({
|
|
||||||
type: true,
|
|
||||||
id: true,
|
|
||||||
data: true,
|
|
||||||
initialData: true,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
.array(),
|
|
||||||
|
|
||||||
team: TeamSchema.pick({
|
team: TeamSchema.pick({
|
||||||
id: true,
|
id: true,
|
||||||
@ -117,6 +107,7 @@ export const ZEnvelopeForSigningResponse = z.object({
|
|||||||
signingOrder: true,
|
signingOrder: true,
|
||||||
rejectionReason: true,
|
rejectionReason: true,
|
||||||
}).extend({
|
}).extend({
|
||||||
|
directToken: z.string().nullish(),
|
||||||
fields: ZFieldSchema.omit({
|
fields: ZFieldSchema.omit({
|
||||||
documentId: true,
|
documentId: true,
|
||||||
templateId: true,
|
templateId: true,
|
||||||
@ -199,11 +190,7 @@ export const getEnvelopeForRecipientSigning = async ({
|
|||||||
signingOrder: 'asc',
|
signingOrder: 'asc',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
envelopeItems: {
|
envelopeItems: true,
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@ -26,9 +26,9 @@ export interface CreateEnvelopeFieldsOptions {
|
|||||||
envelopeItemId?: string;
|
envelopeItemId?: string;
|
||||||
|
|
||||||
recipientId: number;
|
recipientId: number;
|
||||||
pageNumber: number;
|
page: number;
|
||||||
pageX: number;
|
positionX: number;
|
||||||
pageY: number;
|
positionY: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
})[];
|
})[];
|
||||||
@ -122,9 +122,9 @@ export const createEnvelopeFields = async ({
|
|||||||
const newlyCreatedFields = await tx.field.createManyAndReturn({
|
const newlyCreatedFields = await tx.field.createManyAndReturn({
|
||||||
data: validatedFields.map((field) => ({
|
data: validatedFields.map((field) => ({
|
||||||
type: field.type,
|
type: field.type,
|
||||||
page: field.pageNumber,
|
page: field.page,
|
||||||
positionX: field.pageX,
|
positionX: field.positionX,
|
||||||
positionY: field.pageY,
|
positionY: field.positionY,
|
||||||
width: field.width,
|
width: field.width,
|
||||||
height: field.height,
|
height: field.height,
|
||||||
customText: '',
|
customText: '',
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user