2023-02-14 10:58:10 +01:00
|
|
|
import { ReactElement } from "react";
|
2023-04-04 22:02:32 +00:00
|
|
|
import Link from "next/link";
|
2023-01-23 18:25:14 +01:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib";
|
2023-04-04 22:02:32 +00:00
|
|
|
import { getDocument } from "@documenso/lib/query";
|
2023-01-31 15:42:04 +01:00
|
|
|
import { getUserFromToken } from "@documenso/lib/server";
|
2023-05-06 16:08:21 +10:00
|
|
|
import { useSubscription } from "@documenso/lib/stripe";
|
2023-04-04 22:02:32 +00:00
|
|
|
import { Breadcrumb, Button } from "@documenso/ui";
|
|
|
|
|
import PDFEditor from "../../../components/editor/pdf-editor";
|
|
|
|
|
import Layout from "../../../components/layout";
|
|
|
|
|
import { NextPageWithLayout } from "../../_app";
|
|
|
|
|
import { InformationCircleIcon, PaperAirplaneIcon, UsersIcon } from "@heroicons/react/24/outline";
|
2023-01-31 16:32:57 +01:00
|
|
|
import { DocumentStatus } from "@prisma/client";
|
2023-02-01 18:32:59 +01:00
|
|
|
import { Document as PrismaDocument } from "@prisma/client";
|
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-05-06 16:08:21 +10:00
|
|
|
const { hasSubscription } = useSubscription();
|
2023-01-23 18:25:14 +01:00
|
|
|
|
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,
|
2023-04-04 22:02:32 +00:00
|
|
|
href: NEXT_PUBLIC_WEBAPP_URL + "/documents/" + props.document.id,
|
2023-02-03 13:06:26 +01:00
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
/>
|
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">
|
2023-04-04 22:10:30 +00:00
|
|
|
<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}
|
|
|
|
|
className="ml-3"
|
2023-04-04 22:02:32 +00:00
|
|
|
href={NEXT_PUBLIC_WEBAPP_URL + "/documents/" + props.document.id + "/recipients"}
|
2023-01-31 17:14:23 +01:00
|
|
|
onClick={() => {
|
2023-04-04 22:10:30 +00:00
|
|
|
if (
|
|
|
|
|
confirm(`Send document out to ${props?.document?.Recipient?.length} recipients?`)
|
|
|
|
|
) {
|
2023-01-31 17:14:23 +01:00
|
|
|
}
|
2023-04-04 22:02:32 +00: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:
|
2023-02-23 19:17:59 +01:00
|
|
|
return "Waiting for others";
|
2023-01-31 16:32:57 +01:00
|
|
|
|
|
|
|
|
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);
|
2023-03-09 11:24:32 +01:00
|
|
|
if (!user)
|
|
|
|
|
return {
|
|
|
|
|
redirect: {
|
|
|
|
|
destination: "/login",
|
|
|
|
|
permanent: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
2023-01-31 15:42:04 +01:00
|
|
|
|
|
|
|
|
const { id: documentId } = context.query;
|
2023-02-01 18:32:59 +01:00
|
|
|
|
2023-02-14 11:12:07 +01:00
|
|
|
try {
|
2023-04-04 22:02:32 +00:00
|
|
|
const document: PrismaDocument = await getDocument(+documentId, context.req, context.res);
|
2023-01-31 15:42:04 +01:00
|
|
|
|
2023-02-14 11:17:08 +01:00
|
|
|
return {
|
|
|
|
|
props: {
|
2023-02-24 17:04:37 +01:00
|
|
|
document: JSON.parse(JSON.stringify({ ...document, document: "" })),
|
2023-02-14 11:17:08 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
notFound: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-01-31 15:42:04 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 17:42:20 +01:00
|
|
|
DocumentsDetailPage.getLayout = function getLayout(page: ReactElement) {
|
|
|
|
|
return <Layout>{page}</Layout>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default DocumentsDetailPage;
|