import prisma from "@documenso/prisma"; import Head from "next/head"; import { NextPageWithLayout } from "../../_app"; import { ReadStatus } from "@prisma/client"; import PDFSigner from "../../../components/editor/pdf-signer"; import Link from "next/link"; import { ClockIcon } from "@heroicons/react/24/outline"; import { FieldType, DocumentStatus } from "@prisma/client"; const SignPage: NextPageWithLayout = (props: any) => { return ( <>
This signing link is expired.
Please ask{" "} {props.document.User.name ? `${props.document.User.name}` : `the sender`}{" "} to resend it.
Want to send of your own?{" "} Create your own Account
> )} > ); }; export async function getServerSideProps(context: any) { const recipientToken: string = context.query["token"]; // todo redirect to sigend of all already signed await prisma.recipient.updateMany({ where: { token: recipientToken, }, data: { readStatus: ReadStatus.OPENED, }, }); const recipient = await prisma.recipient.findFirstOrThrow({ where: { token: recipientToken, }, include: { Document: { include: { User: true } }, }, }); // Document was already signed if (recipient.Document.status === DocumentStatus.COMPLETED) { return { redirect: { permanent: false, destination: `/documents/${recipient.Document.id}/signed`, }, }; } // Clean up unsigned free place fields from UI from previous page visits // todo refactor free sign fields to be client side only await prisma.field.deleteMany({ where: { type: { in: [FieldType.FREE_SIGNATURE] }, Signature: { is: null }, }, }); const unsignedFields = await prisma.field.findMany({ where: { documentId: recipient.Document.id, recipientId: recipient.id, type: { in: [FieldType.SIGNATURE] }, Signature: { is: null }, }, include: { Recipient: true, Signature: true, }, }); return { props: { recipient: JSON.parse(JSON.stringify(recipient)), document: JSON.parse(JSON.stringify(recipient.Document)), fields: JSON.parse(JSON.stringify(unsignedFields)), expired: recipient.expired ? new Date(recipient.expired) < new Date() : false, }, }; } export default SignPage;