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

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-01-19 19:24:01 +01:00
import { ReactElement, useEffect } from "react";
2023-01-27 18:15:41 +01:00
import Layout from "../../../components/layout";
import { NextPageWithLayout } from "../../_app";
2023-01-19 19:24:01 +01:00
import { Document, Page, pdfjs } from "react-pdf";
import dynamic from "next/dynamic";
2023-01-23 18:25:14 +01:00
import { useRouter } from "next/router";
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib";
2023-01-31 15:42:04 +01:00
import prisma from "@documenso/prisma";
import { getUserFromToken } from "@documenso/lib/server";
import Logo from "../../../components/logo";
import Link from "next/link";
2023-01-19 19:24:01 +01:00
2023-01-27 18:15:41 +01:00
const PDFViewer = dynamic(() => import("../../../components/pdf-viewer"), {
2023-01-19 19:24:01 +01:00
ssr: false,
});
2023-01-19 17:42:20 +01:00
2023-01-31 15:42:04 +01:00
const DocumentsDetailPage: NextPageWithLayout = (props: any) => {
2023-01-23 18:25:14 +01:00
const router = useRouter();
2023-01-19 19:24:01 +01:00
return (
2023-01-31 15:42:04 +01:00
<div className="mx-auto w-fit p-4">
<div className="mx-auto w-auto text-left">
<div>
<h3 className="font-medium leading-tight text-3xl mt-0 mb-2 text-neon">
{props.document.title}
</h3>
<Link
type="a"
href={
NEXT_PUBLIC_WEBAPP_URL +
"/documents/" +
props.document.id +
"/recipients"
}
className="inline-flex items-center justify-center rounded-md border border-transparent bg-neon px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-neon-dark focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 sm:w-auto"
>
Add Signers
</Link>
</div>
</div>
<div className="">
<PDFViewer
pdfUrl={`${NEXT_PUBLIC_WEBAPP_URL}/api/documents/${router.query.id}`}
/>
</div>
2023-01-19 19:24:01 +01:00
</div>
);
2023-01-19 17:42:20 +01:00
};
2023-01-31 15:42:04 +01:00
export async function getServerSideProps(context: any) {
const user = await getUserFromToken(context.req, context.res);
if (!user) return;
const { id: documentId } = context.query;
const document = await prisma.document.findFirstOrThrow({
where: {
id: +documentId,
},
});
// todo optimize querys
// todo no intersection groups
return {
props: {
document: document,
},
};
}
2023-01-19 17:42:20 +01:00
DocumentsDetailPage.getLayout = function getLayout(page: ReactElement) {
return <Layout>{page}</Layout>;
};
export default DocumentsDetailPage;