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

146 lines
4.2 KiB
TypeScript
Raw Normal View History

2023-02-14 10:58:10 +01:00
import { ReactElement } from "react";
2023-01-27 18:15:41 +01:00
import Layout from "../../../components/layout";
import { NextPageWithLayout } from "../../_app";
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 { getUserFromToken } from "@documenso/lib/server";
import Link from "next/link";
2023-01-31 16:32:57 +01:00
import { DocumentStatus } from "@prisma/client";
import {
InformationCircleIcon,
PaperAirplaneIcon,
UsersIcon,
} from "@heroicons/react/24/outline";
2023-02-01 18:32:59 +01:00
import { getDocument } from "@documenso/lib/query";
import { Document as PrismaDocument } from "@prisma/client";
2023-02-03 12:18:55 +01:00
import { Button, Breadcrumb } from "@documenso/ui";
2023-02-13 16:58:25 +01:00
import PDFEditor from "../../../components/editor/pdf-editor";
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 16:32:57 +01:00
<div className="mt-4">
<div>
2023-01-31 15:42:04 +01:00
<div>
2023-02-03 13:06:26 +01:00
<Breadcrumb
document={props.document}
items={[
{
title: "Documents",
href: "/documents",
},
{
title: props.document.title,
href:
NEXT_PUBLIC_WEBAPP_URL + "/documents/" + props.document.id,
},
]}
/>
2023-01-31 16:32:57 +01:00
</div>
<div className="mt-2 md:flex md:items-center md:justify-between">
<div className="min-w-0 flex-1">
<h2 className="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
{props.document.title}
</h2>
<div className="mt-1 flex flex-col sm:mt-0 sm:flex-row sm:flex-wrap sm:space-x-6">
<div className="mt-2 flex items-center text-sm text-gray-500">
<UsersIcon
className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true"
/>
2023-02-03 19:57:54 +01:00
<Link href={`/documents/${props.document.id}/recipients`}>
{props?.document?.Recipient?.length} Recipients
</Link>
2023-01-31 16:32:57 +01:00
</div>
<div className="mt-2 flex items-center text-sm text-gray-500">
<InformationCircleIcon
className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true"
/>
{formatDocumentStatus(props.document.status)}
</div>
</div>
</div>
<div className="mt-4 flex flex-shrink-0 md:mt-0 md:ml-4">
2023-02-02 18:24:23 +01:00
<Button
2023-02-07 11:16:14 +01:00
icon={PaperAirplaneIcon}
disabled={(props?.document?.Recipient?.length || 0) === 0}
className="ml-3"
2023-01-31 16:32:57 +01:00
href={
NEXT_PUBLIC_WEBAPP_URL +
"/documents/" +
props.document.id +
"/recipients"
}
2023-01-31 17:14:23 +01:00
onClick={() => {
if (
confirm(
`Send document out to ${props?.document?.Recipient?.length} recipients?`
)
) {
}
}}
2023-01-31 16:32:57 +01:00
>
2023-02-07 11:16:14 +01:00
Prepare to Send
2023-02-02 14:46:24 +01:00
</Button>
2023-01-31 16:32:57 +01:00
</div>
2023-01-31 15:42:04 +01:00
</div>
</div>
2023-02-09 12:40:18 +01:00
<div className="mx-auto w-fit">
2023-02-13 16:58:25 +01:00
<PDFEditor document={props.document} />
2023-01-31 15:42:04 +01:00
</div>
2023-01-19 19:24:01 +01:00
</div>
);
2023-01-19 17:42:20 +01:00
};
2023-01-31 16:32:57 +01:00
function formatDocumentStatus(status: DocumentStatus) {
switch (status) {
case DocumentStatus.DRAFT:
return "Draft";
case DocumentStatus.PENDING:
return "Pending";
case DocumentStatus.COMPLETED:
return "Completed";
}
}
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;
2023-02-01 18:32:59 +01:00
2023-02-14 11:12:07 +01:00
try {
const document: PrismaDocument = await getDocument(
+documentId,
context.req,
context.res
);
} catch (error) {
if (!document) {
return {
notFound: true,
};
}
}
2023-01-31 15:42:04 +01:00
// 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;