Files
sign/apps/web/pages/documents/[id]/sign.tsx

66 lines
1.6 KiB
TypeScript
Raw Normal View History

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";
2023-02-09 19:35:29 +01:00
import { useEffect } from "react";
2023-01-27 18:15:41 +01:00
import { NextPageWithLayout } from "../../_app";
2023-01-27 18:31:40 +01:00
import { ReadStatus } from "@prisma/client";
2023-01-31 17:33:00 +01:00
import SignaturePad from "signature_pad";
2023-01-27 18:15:41 +01:00
2023-02-09 19:35:29 +01:00
const SignPage: NextPageWithLayout = (props: any) => {
2023-01-31 17:33:00 +01:00
useEffect(() => {
const canvas: any = document.querySelector("canvas");
const signaturePad = new SignaturePad(canvas);
2023-02-09 19:46:27 +01:00
const resizeCanvas = () => {
const ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
// signaturePad.clear(); // otherwise isEmpty() might return incorrect value
};
window.addEventListener("resize", resizeCanvas);
2023-01-31 17:33:00 +01:00
});
2023-01-27 18:15:41 +01:00
return (
<>
<Head>
<title>Sign | Documenso</title>
</Head>
Hello, please sign at the dotted line.
2023-01-31 17:33:00 +01:00
<canvas className="mx-auto bg-neon"></canvas>
<hr></hr>
2023-02-09 19:35:29 +01:00
{/* todo read/ sign version of editor => flag or own component */}
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"];
await prisma.recipient.updateMany({
where: {
token: recipientToken,
},
data: {
readStatus: ReadStatus.OPENED,
},
});
2023-02-09 19:35:29 +01:00
const document = await prisma.recipient
.findFirstOrThrow({
where: {
token: recipientToken,
},
})
.Document();
// todo get r
2023-01-27 20:14:32 +01:00
// todo sign ui
2023-01-27 18:31:40 +01:00
return {
2023-02-09 19:35:29 +01:00
props: {
document: document,
},
2023-01-27 18:31:40 +01:00
};
}
2023-01-27 18:15:41 +01:00
export default SignPage;