2023-01-27 18:31:40 +01:00
|
|
|
import prisma from "@documenso/prisma";
|
2023-01-27 18:15:41 +01:00
|
|
|
import Head from "next/head";
|
|
|
|
|
import { NextPageWithLayout } from "../../_app";
|
2023-01-27 18:31:40 +01:00
|
|
|
import { ReadStatus } from "@prisma/client";
|
2023-02-16 18:31:06 +01:00
|
|
|
import PDFSigner from "../../../components/editor/pdf-signer";
|
2023-02-21 15:06:47 +01:00
|
|
|
|
2023-02-09 19:35:29 +01:00
|
|
|
const SignPage: NextPageWithLayout = (props: any) => {
|
2023-01-27 18:15:41 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Head>
|
|
|
|
|
<title>Sign | Documenso</title>
|
|
|
|
|
</Head>
|
2023-02-16 18:31:06 +01:00
|
|
|
<PDFSigner document={props.document} fields={props.fields} />
|
2023-01-27 18:15:41 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-27 18:31:40 +01:00
|
|
|
export async function getServerSideProps(context: any) {
|
|
|
|
|
const recipientToken: string = context.query["token"];
|
|
|
|
|
|
2023-02-17 19:08:23 +01:00
|
|
|
// todo redirect to sigend of all already signed
|
|
|
|
|
|
2023-01-27 18:31:40 +01:00
|
|
|
await prisma.recipient.updateMany({
|
|
|
|
|
where: {
|
|
|
|
|
token: recipientToken,
|
|
|
|
|
},
|
|
|
|
|
data: {
|
|
|
|
|
readStatus: ReadStatus.OPENED,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-16 18:31:06 +01:00
|
|
|
const recipient = await prisma.recipient.findFirstOrThrow({
|
|
|
|
|
where: {
|
|
|
|
|
token: recipientToken,
|
|
|
|
|
},
|
|
|
|
|
include: {
|
|
|
|
|
Document: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-21 15:58:45 +01:00
|
|
|
const unsignedFields = await prisma.field.findMany({
|
2023-02-16 18:31:06 +01:00
|
|
|
where: {
|
|
|
|
|
documentId: recipient.Document.id,
|
2023-02-21 15:58:45 +01:00
|
|
|
recipientId: recipient.id,
|
|
|
|
|
Signature: { is: null },
|
2023-02-16 18:31:06 +01:00
|
|
|
},
|
|
|
|
|
include: {
|
|
|
|
|
Recipient: true,
|
2023-02-21 15:58:45 +01:00
|
|
|
Signature: true,
|
2023-02-16 18:31:06 +01:00
|
|
|
},
|
|
|
|
|
});
|
2023-02-09 19:35:29 +01:00
|
|
|
|
2023-02-21 15:58:45 +01:00
|
|
|
if (unsignedFields.length === 0) {
|
|
|
|
|
return {
|
|
|
|
|
redirect: {
|
|
|
|
|
permanent: false,
|
|
|
|
|
destination: `/documents/${recipient.Document.id}/signed`,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 18:31:40 +01:00
|
|
|
return {
|
2023-02-09 19:35:29 +01:00
|
|
|
props: {
|
2023-02-16 18:31:06 +01:00
|
|
|
document: recipient.Document,
|
2023-02-21 15:58:45 +01:00
|
|
|
fields: unsignedFields,
|
2023-02-09 19:35:29 +01:00
|
|
|
},
|
2023-01-27 18:31:40 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 18:15:41 +01:00
|
|
|
export default SignPage;
|