2024-08-27 20:34:39 +09:00
|
|
|
import { Trans } from '@lingui/macro';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { match } from 'ts-pattern';
|
|
|
|
|
|
|
|
|
|
import { DEFAULT_DOCUMENT_DATE_FORMAT } from '@documenso/lib/constants/date-formats';
|
|
|
|
|
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
|
|
|
|
|
import { DEFAULT_DOCUMENT_TIME_ZONE } from '@documenso/lib/constants/time-zones';
|
|
|
|
|
import type { DocumentAndSender } from '@documenso/lib/server-only/document/get-document-by-token';
|
2024-07-18 16:45:44 +03:00
|
|
|
import {
|
|
|
|
|
ZCheckboxFieldMeta,
|
|
|
|
|
ZDropdownFieldMeta,
|
|
|
|
|
ZNumberFieldMeta,
|
|
|
|
|
ZRadioFieldMeta,
|
|
|
|
|
ZTextFieldMeta,
|
|
|
|
|
} from '@documenso/lib/types/field-meta';
|
2024-04-18 21:56:31 +07:00
|
|
|
import type { CompletedField } from '@documenso/lib/types/fields';
|
2024-03-28 13:13:29 +08:00
|
|
|
import type { Field, Recipient } from '@documenso/prisma/client';
|
|
|
|
|
import { FieldType, RecipientRole } from '@documenso/prisma/client';
|
2024-07-18 16:45:44 +03:00
|
|
|
import type { FieldWithSignatureAndFieldMeta } from '@documenso/prisma/types/field-with-signature-and-fieldmeta';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { Card, CardContent } from '@documenso/ui/primitives/card';
|
|
|
|
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
|
|
|
|
import { LazyPDFViewer } from '@documenso/ui/primitives/lazy-pdf-viewer';
|
|
|
|
|
|
2024-04-18 21:56:31 +07:00
|
|
|
import { DocumentReadOnlyFields } from '~/components/document/document-read-only-fields';
|
2024-03-28 13:13:29 +08:00
|
|
|
|
2024-07-18 16:45:44 +03:00
|
|
|
import { CheckboxField } from './checkbox-field';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { DateField } from './date-field';
|
2024-07-18 16:45:44 +03:00
|
|
|
import { DropdownField } from './dropdown-field';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { EmailField } from './email-field';
|
|
|
|
|
import { SigningForm } from './form';
|
2024-08-12 15:29:32 +02:00
|
|
|
import { InitialsField } from './initials-field';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { NameField } from './name-field';
|
2024-07-18 16:45:44 +03:00
|
|
|
import { NumberField } from './number-field';
|
|
|
|
|
import { RadioField } from './radio-field';
|
2024-11-14 21:37:42 +11:00
|
|
|
import { RejectDocumentDialog } from './reject-document-dialog';
|
2024-03-28 13:13:29 +08:00
|
|
|
import { SignatureField } from './signature-field';
|
|
|
|
|
import { TextField } from './text-field';
|
|
|
|
|
|
|
|
|
|
export type SigningPageViewProps = {
|
|
|
|
|
document: DocumentAndSender;
|
|
|
|
|
recipient: Recipient;
|
|
|
|
|
fields: Field[];
|
2024-04-18 21:56:31 +07:00
|
|
|
completedFields: CompletedField[];
|
2024-09-16 12:36:45 +00:00
|
|
|
isRecipientsTurn: boolean;
|
2024-03-28 13:13:29 +08:00
|
|
|
};
|
|
|
|
|
|
2024-04-18 21:56:31 +07:00
|
|
|
export const SigningPageView = ({
|
|
|
|
|
document,
|
|
|
|
|
recipient,
|
|
|
|
|
fields,
|
|
|
|
|
completedFields,
|
2024-09-16 12:36:45 +00:00
|
|
|
isRecipientsTurn,
|
2024-04-18 21:56:31 +07:00
|
|
|
}: SigningPageViewProps) => {
|
2024-03-28 13:13:29 +08:00
|
|
|
const { documentData, documentMeta } = document;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx-auto w-full max-w-screen-xl">
|
|
|
|
|
<h1 className="mt-4 truncate text-2xl font-semibold md:text-3xl" title={document.title}>
|
2024-07-28 23:13:35 -04:00
|
|
|
{document.title}
|
2024-03-28 13:13:29 +08:00
|
|
|
</h1>
|
|
|
|
|
|
2024-11-14 21:37:42 +11:00
|
|
|
<div className="mt-2.5 flex flex-wrap items-center justify-between gap-x-6">
|
|
|
|
|
<div>
|
|
|
|
|
<p
|
|
|
|
|
className="text-muted-foreground truncate"
|
|
|
|
|
title={document.User.name ? document.User.name : ''}
|
|
|
|
|
>
|
|
|
|
|
{document.User.name}
|
|
|
|
|
</p>
|
2024-09-04 23:13:00 +10:00
|
|
|
|
2024-11-14 21:37:42 +11:00
|
|
|
<p className="text-muted-foreground">
|
|
|
|
|
{match(recipient.role)
|
|
|
|
|
.with(RecipientRole.VIEWER, () => (
|
|
|
|
|
<Trans>({document.User.email}) has invited you to view this document</Trans>
|
|
|
|
|
))
|
|
|
|
|
.with(RecipientRole.SIGNER, () => (
|
|
|
|
|
<Trans>({document.User.email}) has invited you to sign this document</Trans>
|
|
|
|
|
))
|
|
|
|
|
.with(RecipientRole.APPROVER, () => (
|
|
|
|
|
<Trans>({document.User.email}) has invited you to approve this document</Trans>
|
|
|
|
|
))
|
|
|
|
|
.otherwise(() => null)}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<RejectDocumentDialog document={document} token={recipient.token} />
|
|
|
|
|
</div>
|
2024-03-28 13:13:29 +08:00
|
|
|
|
|
|
|
|
<div className="mt-8 grid grid-cols-12 gap-y-8 lg:gap-x-8 lg:gap-y-0">
|
|
|
|
|
<Card
|
|
|
|
|
className="col-span-12 rounded-xl before:rounded-xl lg:col-span-7 xl:col-span-8"
|
|
|
|
|
gradient
|
|
|
|
|
>
|
|
|
|
|
<CardContent className="p-2">
|
|
|
|
|
<LazyPDFViewer
|
|
|
|
|
key={documentData.id}
|
|
|
|
|
documentData={documentData}
|
|
|
|
|
document={document}
|
|
|
|
|
password={documentMeta?.password}
|
|
|
|
|
/>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<div className="col-span-12 lg:col-span-5 xl:col-span-4">
|
|
|
|
|
<SigningForm
|
|
|
|
|
document={document}
|
|
|
|
|
recipient={recipient}
|
|
|
|
|
fields={fields}
|
|
|
|
|
redirectUrl={documentMeta?.redirectUrl}
|
2024-09-16 12:36:45 +00:00
|
|
|
isRecipientsTurn={isRecipientsTurn}
|
2024-03-28 13:13:29 +08:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-04-18 21:56:31 +07:00
|
|
|
<DocumentReadOnlyFields fields={completedFields} />
|
|
|
|
|
|
2024-03-28 13:13:29 +08:00
|
|
|
<ElementVisible target={PDF_VIEWER_PAGE_SELECTOR}>
|
|
|
|
|
{fields.map((field) =>
|
|
|
|
|
match(field.type)
|
|
|
|
|
.with(FieldType.SIGNATURE, () => (
|
2024-10-18 04:25:19 +01:00
|
|
|
<SignatureField
|
|
|
|
|
key={field.id}
|
|
|
|
|
field={field}
|
|
|
|
|
recipient={recipient}
|
|
|
|
|
typedSignatureEnabled={documentMeta?.typedSignatureEnabled}
|
|
|
|
|
/>
|
2024-03-28 13:13:29 +08:00
|
|
|
))
|
2024-08-12 15:29:32 +02:00
|
|
|
.with(FieldType.INITIALS, () => (
|
|
|
|
|
<InitialsField key={field.id} field={field} recipient={recipient} />
|
|
|
|
|
))
|
2024-03-28 13:13:29 +08:00
|
|
|
.with(FieldType.NAME, () => (
|
|
|
|
|
<NameField key={field.id} field={field} recipient={recipient} />
|
|
|
|
|
))
|
|
|
|
|
.with(FieldType.DATE, () => (
|
|
|
|
|
<DateField
|
|
|
|
|
key={field.id}
|
|
|
|
|
field={field}
|
|
|
|
|
recipient={recipient}
|
|
|
|
|
dateFormat={documentMeta?.dateFormat ?? DEFAULT_DOCUMENT_DATE_FORMAT}
|
|
|
|
|
timezone={documentMeta?.timezone ?? DEFAULT_DOCUMENT_TIME_ZONE}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
.with(FieldType.EMAIL, () => (
|
|
|
|
|
<EmailField key={field.id} field={field} recipient={recipient} />
|
|
|
|
|
))
|
2024-07-18 16:45:44 +03:00
|
|
|
.with(FieldType.TEXT, () => {
|
|
|
|
|
const fieldWithMeta: FieldWithSignatureAndFieldMeta = {
|
|
|
|
|
...field,
|
|
|
|
|
fieldMeta: field.fieldMeta ? ZTextFieldMeta.parse(field.fieldMeta) : null,
|
|
|
|
|
};
|
|
|
|
|
return <TextField key={field.id} field={fieldWithMeta} recipient={recipient} />;
|
|
|
|
|
})
|
|
|
|
|
.with(FieldType.NUMBER, () => {
|
|
|
|
|
const fieldWithMeta: FieldWithSignatureAndFieldMeta = {
|
|
|
|
|
...field,
|
|
|
|
|
fieldMeta: field.fieldMeta ? ZNumberFieldMeta.parse(field.fieldMeta) : null,
|
|
|
|
|
};
|
|
|
|
|
return <NumberField key={field.id} field={fieldWithMeta} recipient={recipient} />;
|
|
|
|
|
})
|
|
|
|
|
.with(FieldType.RADIO, () => {
|
|
|
|
|
const fieldWithMeta: FieldWithSignatureAndFieldMeta = {
|
|
|
|
|
...field,
|
|
|
|
|
fieldMeta: field.fieldMeta ? ZRadioFieldMeta.parse(field.fieldMeta) : null,
|
|
|
|
|
};
|
|
|
|
|
return <RadioField key={field.id} field={fieldWithMeta} recipient={recipient} />;
|
|
|
|
|
})
|
|
|
|
|
.with(FieldType.CHECKBOX, () => {
|
|
|
|
|
const fieldWithMeta: FieldWithSignatureAndFieldMeta = {
|
|
|
|
|
...field,
|
|
|
|
|
fieldMeta: field.fieldMeta ? ZCheckboxFieldMeta.parse(field.fieldMeta) : null,
|
|
|
|
|
};
|
|
|
|
|
return <CheckboxField key={field.id} field={fieldWithMeta} recipient={recipient} />;
|
|
|
|
|
})
|
|
|
|
|
.with(FieldType.DROPDOWN, () => {
|
|
|
|
|
const fieldWithMeta: FieldWithSignatureAndFieldMeta = {
|
|
|
|
|
...field,
|
|
|
|
|
fieldMeta: field.fieldMeta ? ZDropdownFieldMeta.parse(field.fieldMeta) : null,
|
|
|
|
|
};
|
|
|
|
|
return <DropdownField key={field.id} field={fieldWithMeta} recipient={recipient} />;
|
|
|
|
|
})
|
2024-03-28 13:13:29 +08:00
|
|
|
.otherwise(() => null),
|
|
|
|
|
)}
|
|
|
|
|
</ElementVisible>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|