import { notFound } from 'next/navigation'; import { match } from 'ts-pattern'; import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer'; import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-session'; import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token'; import { viewedDocument } from '@documenso/lib/server-only/document/viewed-document'; import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token'; import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token'; import { getFile } from '@documenso/lib/universal/upload/get-file'; import { FieldType } from '@documenso/prisma/client'; 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'; import { DateField } from './date-field'; import { EmailField } from './email-field'; import { SigningForm } from './form'; import { NameField } from './name-field'; import { SigningProvider } from './provider'; import { SignatureField } from './signature-field'; export type SigningPageProps = { params: { token?: string; }; }; export default async function SigningPage({ params: { token } }: SigningPageProps) { if (!token) { return notFound(); } const [document, fields, recipient] = await Promise.all([ getDocumentAndSenderByToken({ token, }).catch(() => null), getFieldsForToken({ token }), getRecipientByToken({ token }).catch(() => null), viewedDocument({ token }), ]); if (!document || !document.documentData || !recipient) { return notFound(); } const { documentData } = document; const documentDataUrl = await getFile(documentData) .then((buffer) => Buffer.from(buffer).toString('base64')) .then((data) => `data:application/pdf;base64,${data}`); const user = await getServerComponentSession(); return (

{document.title}

{document.User.name} ({document.User.email}) has invited you to sign this document.

{fields.map((field) => match(field.type) .with(FieldType.SIGNATURE, () => ( )) .with(FieldType.NAME, () => ( )) .with(FieldType.DATE, () => ( )) .with(FieldType.EMAIL, () => ( )) .otherwise(() => null), )}
); }