Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: add notion docs in dataroom

Marc Seitzf09cc86b2674
diff --git a/components/NotionPage.tsx b/components/NotionPage.tsx
index b38f0c76..14797024 100644
--- a/components/NotionPage.tsx
+++ b/components/NotionPage.tsx
@@ -4,7 +4,7 @@ import { NotionRenderer } from "react-notion-x";
// core styles shared by all of react-notion-x (required)
import "react-notion-x/src/styles.css";
import Nav from "./view/nav";
-import { Brand } from "@prisma/client";
+import { Brand, DataroomBrand } from "@prisma/client";
export const NotionPage = ({
recordMap,
@@ -14,6 +14,8 @@ export const NotionPage = ({
documentId,
versionNumber,
brand,
+ dataroomId,
+ setDocumentData,
}: {
recordMap: ExtendedRecordMap;
rootPageId?: string;
@@ -21,7 +23,9 @@ export const NotionPage = ({
linkId: string;
documentId: string;
versionNumber: number;
- brand?: Brand;
+ brand?: Brand | DataroomBrand;
+ dataroomId?: string;
+ setDocumentData?: (data: any) => void;
}) => {
const [pageNumber, setPageNumber] = useState<number>(1); // start on first page
const [maxScrollPercentage, setMaxScrollPercentage] = useState<number>(0);
@@ -112,7 +116,12 @@ export const NotionPage = ({
return (
<>
<div className="bg-white">
- <Nav brand={brand} type="notion" />
+ <Nav
+ brand={brand}
+ isDataroom={dataroomId ? true : false}
+ setDocumentData={setDocumentData}
+ type="notion"
+ />
<div>
<NotionRenderer
diff --git a/components/view/DataroomViewer.tsx b/components/view/DataroomViewer.tsx
index 61589847..e87b6691 100644
--- a/components/view/DataroomViewer.tsx
+++ b/components/view/DataroomViewer.tsx
@@ -36,6 +36,7 @@ type DataroomDocument = {
name: string;
versions: {
id: string;
+ type: string;
versionNumber: number;
hasPages: boolean;
}[];
@@ -61,6 +62,7 @@ export default function DataroomViewer({
id: string;
name: string;
hasPages: boolean;
+ documentType: "pdf" | "notion";
documentVersionId: string;
documentVersionNumber: number;
} | null>
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsx
index 27e811a7..8238d6c5 100644
--- a/components/view/dataroom/dataroom-view.tsx
+++ b/components/view/dataroom/dataroom-view.tsx
@@ -7,6 +7,7 @@ import { usePlausible } from "next-plausible";
import { toast } from "sonner";
import LoadingSpinner from "@/components/ui/loading-spinner";
import EmailVerificationMessage from "../email-verification-form";
+import { ExtendedRecordMap } from "notion-types";
import { Brand, DataroomBrand } from "@prisma/client";
import { useRouter } from "next/router";
@@ -14,12 +15,14 @@ import { useAnalytics } from "@/lib/analytics";
import DataroomViewer from "../DataroomViewer";
import PagesViewer from "../PagesViewer";
import { LinkWithDataroom } from "@/pages/view/d/[linkId]";
+import { NotionPage } from "@/components/NotionPage";
export type DEFAULT_DOCUMENT_VIEW_TYPE = {
viewId: string;
dataroomViewId?: string;
file: string | null;
pages: { file: string; pageNumber: string; embeddedLinks: string[] }[] | null;
+ notionData: { recordMap: ExtendedRecordMap | null } | null;
};
export default function DataroomView({
@@ -52,6 +55,7 @@ export default function DataroomView({
viewId: "",
file: null,
pages: null,
+ notionData: null,
});
const [data, setData] = useState<DEFAULT_ACCESS_FORM_TYPE>(
DEFAULT_ACCESS_FORM_DATA,
@@ -62,6 +66,7 @@ export default function DataroomView({
id: string;
name: string;
hasPages: boolean;
+ documentType: "pdf" | "notion";
documentVersionId: string;
documentVersionNumber: number;
} | null>(null);
@@ -103,7 +108,8 @@ export default function DataroomView({
setVerificationRequested(true);
setIsLoading(false);
} else {
- const { viewId, file, pages } = fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;
+ const { viewId, file, pages, notionData } =
+ fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;
plausible("dataroomViewed"); // track the event
analytics.identify(
userEmail ?? verifiedEmail ?? data.email ?? undefined,
@@ -122,6 +128,7 @@ export default function DataroomView({
viewType === "DATAROOM_VIEW" ? viewId : prev.dataroomViewId,
file,
pages,
+ notionData,
}));
setSubmitted(true);
setVerificationRequested(false);
@@ -168,6 +175,7 @@ export default function DataroomView({
pages: null,
file: null,
viewId: "",
+ notionData: null,
}));
// This effect is specifically for handling changes to `documentData` post-mount
}, [documentData]);
@@ -205,37 +213,59 @@ export default function DataroomView({
</div>
);
}
+
+ if (submitted && documentData) {
+ return viewData.notionData?.recordMap ? (
+ <div className="bg-gray-950">
+ <NotionPage
+ recordMap={viewData.notionData.recordMap}
+ viewId={viewData.viewId}
+ linkId={link.id}
+ documentId={documentData.id}
+ versionNumber={documentData.documentVersionNumber}
+ brand={brand}
+ dataroomId={dataroom.id}
+ setDocumentData={setDocumentData}
+ />
+ </div>
+ ) : viewData.pages ? (
+ <div className="bg-gray-950">
+ <PagesViewer
+ pages={viewData.pages}
+ viewId={viewData.viewId}
+ linkId={link.id}
+ documentId={documentData.id}
+ allowDownload={link.allowDownload!}
+ feedbackEnabled={link.enableFeedback!}
+ versionNumber={documentData.documentVersionNumber}
+ brand={brand}
+ dataroomId={dataroom.id}
+ setDocumentData={setDocumentData}
+ />
+ </div>
+ ) : null;
+ }
+
+ if (submitted && !documentData) {
+ return (
+ <div className="bg-gray-950">
+ <DataroomViewer
+ brand={brand!}
+ viewId={viewData.viewId}
+ dataroomViewId={viewData.dataroomViewId!}
+ dataroom={dataroom}
+ setDocumentData={setDocumentData}
+ setViewType={setViewType}
+ />
+ </div>
+ );
+ }
+
return (
<div className="bg-gray-950">
- {submitted ? (
- documentData && viewData.pages ? (
- <PagesViewer
- pages={viewData.pages}
- viewId={viewData.viewId}
- linkId={link.id}
- documentId={documentData.id}
- allowDownload={link.allowDownload!}
- feedbackEnabled={link.enableFeedback!}
- versionNumber={documentData.documentVersionNumber}
- brand={brand}
- dataroomId={dataroom.id}
- setDocumentData={setDocumentData}
- />
- ) : (
- <DataroomViewer
- brand={brand!}
- viewId={viewData.viewId}
- dataroomViewId={viewData.dataroomViewId!}
- dataroom={dataroom}
- setDocumentData={setDocumentData}
- setViewType={setViewType}
- />
- )
- ) : (
- <div className="h-screen flex items-center justify-center">
- <LoadingSpinner className="h-20 w-20" />
- </div>
- )}
+ <div className="h-screen flex items-center justify-center">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
</div>
);
}
diff --git a/components/view/dataroom/document-card.tsx b/components/view/dataroom/document-card.tsx
index 399d19f8..7778628e 100644
--- a/components/view/dataroom/document-card.tsx
+++ b/components/view/dataroom/document-card.tsx
@@ -31,6 +31,7 @@ type DRDocument = {
name: string;
versions: {
id: string;
+ type: string;
versionNumber: number;
hasPages: boolean;
}[];
@@ -43,6 +44,7 @@ type DocumentsCardProps = {
id: string;
name: string;
hasPages: boolean;
+ documentType: "pdf" | "notion";
documentVersionId: string;
documentVersionNumber: number;
}) => void;
@@ -61,12 +63,16 @@ export default function DocumentCard({
<li className="group/row relative rounded-lg p-3 border-0 dark:bg-secondary ring-1 ring-gray-200 dark:ring-gray-700 transition-all hover:ring-gray-300 hover:dark:ring-gray-500 hover:bg-secondary sm:p-4 flex justify-between items-center">
<div className="min-w-0 flex shrink items-center space-x-2 sm:space-x-4">
<div className="w-8 mx-0.5 sm:mx-1 text-center flex justify-center items-center">
- <Image
- src={`/_icons/pdf${isLight ? "-light" : ""}.svg`}
- alt="File icon"
- width={50}
- height={50}
- />
+ {document.versions[0].type === "notion" ? (
+ <NotionIcon className="w-8 h-8" />
+ ) : (
+ <Image
+ src={`/_icons/pdf${isLight ? "-light" : ""}.svg`}
+ alt="File icon"
+ width={50}
+ height={50}
+ />
+ )}
</div>
<div className="flex-col">
@@ -80,6 +86,9 @@ export default function DocumentCard({
id: document.id,
name: document.name,
hasPages: document.versions[0].hasPages,
+ documentType: document.versions[0].type as
+ | "pdf"
+ | "notion",
documentVersionId: document.versions[0].id,
documentVersionNumber: document.versions[0].versionNumber,
});
diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.ts
index 8ed1d9b3..1d6ccf81 100644
--- a/pages/api/views-dataroom.ts
+++ b/pages/api/views-dataroom.ts
@@ -5,6 +5,9 @@ import { newId } from "@/lib/id-helper";
import { sendVerificationEmail } from "@/lib/emails/send-email-verification";
import { getFile } from "@/lib/files/get-file";
import sendNotification from "@/lib/api/notification-helper";
+import { parsePageId } from "notion-utils";
+import notion from "@/lib/notion";
+import { record } from "zod";
export default async function handle(
req: NextApiRequest,
@@ -239,12 +242,13 @@ export default async function handle(
viewId: newDataroomView.id,
file: null,
pages: null,
+ notionData: null,
};
return res.status(200).json(returnObject);
} catch (error) {
log({
- message: `Failed to record view for ${linkId}. \n\n ${error}`,
+ message: `Failed to record view for dataroom link: ${linkId}. \n\n ${error}`,
type: "error",
mention: true,
});
@@ -270,9 +274,10 @@ export default async function handle(
console.timeEnd("create-view");
// if document version has pages, then return pages
+ // otherwise, check if notion document,
+ // if notion, return recordMap from document version file
// otherwise, return file from document version
- let documentPages, documentVersion;
- // let documentPagesPromise, documentVersionPromise;
+ let documentPages, documentVersion, recordMap;
if (hasPages) {
// get pages from document version
console.time("get-pages");
@@ -306,6 +311,7 @@ export default async function handle(
select: {
file: true,
storageType: true,
+ type: true,
},
});
@@ -314,6 +320,16 @@ export default async function handle(
return;
}
+ if (documentVersion.type === "notion") {
+ let notionPageId = parsePageId(documentVersion.file, { uuid: false });
+ if (!notionPageId) {
+ notionPageId = "";
+ }
+
+ const pageId = notionPageId;
+ recordMap = await notion.getPage(pageId);
+ }
+
documentVersion.file = await getFile({
data: documentVersion.file,
type: documentVersion.storageType,
@@ -324,8 +340,12 @@ export default async function handle(
const returnObject = {
message: "View recorded",
viewId: newView.id,
- file: documentVersion ? documentVersion.file : null,
+ file:
+ documentVersion && documentVersion.type === "pdf"
+ ? documentVersion.file
+ : null,
pages: documentPages ? documentPages : null,
+ notionData: recordMap ? { recordMap } : null,
};
return res.status(200).json(returnObject);
diff --git a/pages/view/d/[linkId]/index.tsx b/pages/view/d/[linkId]/index.tsx
index a5995706..5f248cfb 100644
--- a/pages/view/d/[linkId]/index.tsx
+++ b/pages/view/d/[linkId]/index.tsx
@@ -67,7 +67,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
// iterate the link.documents and extract type and file and rest of the props
let documents = [];
for (const document of link.dataroom.documents) {
- const { type, file, ...versionWithoutTypeAndFile } =
+ const { file, ...versionWithoutTypeAndFile } =
document.document.versions[0];
const newDocument = {