Skip to content

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

feat: make custom domain work on datarooms

Marc Seitza8b9275559cc
diff --git a/components/NotionPage.tsx b/components/NotionPage.tsx
index faa19da1..08cd3d5d 100644
--- a/components/NotionPage.tsx
+++ b/components/NotionPage.tsx
@@ -25,7 +25,7 @@ export const NotionPage = ({
documentId: string;
versionNumber: number;
documentName?: string;
- brand?: Brand | DataroomBrand;
+ brand?: Partial<Brand> | Partial<DataroomBrand> | null;
dataroomId?: string;
setDocumentData?: (data: any) => void;
}) => {
diff --git a/components/links/link-sheet/domain-section.tsx b/components/links/link-sheet/domain-section.tsx
index fd6c76c7..98a40323 100644
--- a/components/links/link-sheet/domain-section.tsx
+++ b/components/links/link-sheet/domain-section.tsx
@@ -61,16 +61,12 @@ export default function DomainSection({
<option key="papermark.io" value="papermark.io">
papermark.io
</option>
- {linkType === "DOCUMENT_LINK" ? (
- <>
- {domains?.map(({ slug }) => (
- <option key={slug} value={slug}>
- {slug}
- </option>
- ))}
- <option value="add_domain">Add a custom domain ✨</option>
- </>
- ) : null}
+ {domains?.map(({ slug }) => (
+ <option key={slug} value={slug}>
+ {slug}
+ </option>
+ ))}
+ <option value="add_domain">Add a custom domain ✨</option>
</select>
{data.domain && data.domain !== "papermark.io" ? (
diff --git a/components/view/DataroomViewer.tsx b/components/view/DataroomViewer.tsx
index e87b6691..44f9802a 100644
--- a/components/view/DataroomViewer.tsx
+++ b/components/view/DataroomViewer.tsx
@@ -50,7 +50,7 @@ export default function DataroomViewer({
setViewType,
setDocumentData,
}: {
- brand: DataroomBrand;
+ brand: Partial<DataroomBrand>;
viewId: string;
dataroomViewId: string;
dataroom: any;
diff --git a/components/view/PagesViewer.tsx b/components/view/PagesViewer.tsx
index 5d4b23f3..09015eea 100644
--- a/components/view/PagesViewer.tsx
+++ b/components/view/PagesViewer.tsx
@@ -42,7 +42,7 @@ export default function PagesViewer({
feedbackEnabled: boolean;
screenshotProtectionEnabled: boolean;
versionNumber: number;
- brand?: Brand | DataroomBrand;
+ brand?: Partial<Brand> | Partial<DataroomBrand> | null;
documentName?: string;
dataroomId?: string;
setDocumentData?: (data: any) => void;
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsx
index daa2367b..fd27129b 100644
--- a/components/view/dataroom/dataroom-view.tsx
+++ b/components/view/dataroom/dataroom-view.tsx
@@ -38,7 +38,7 @@ export default function DataroomView({
userEmail: string | null | undefined;
userId: string | null | undefined;
isProtected: boolean;
- brand?: DataroomBrand;
+ brand?: Partial<DataroomBrand> | null;
token?: string;
verifiedEmail?: string;
}) {
diff --git a/components/view/dataroom/nav-dataroom.tsx b/components/view/dataroom/nav-dataroom.tsx
index f9eecce3..17ac8451 100644
--- a/components/view/dataroom/nav-dataroom.tsx
+++ b/components/view/dataroom/nav-dataroom.tsx
@@ -34,7 +34,7 @@ export default function DataroomNav({
numPages?: number;
allowDownload?: boolean;
assistantEnabled?: boolean;
- brand?: DataroomBrand;
+ brand?: Partial<DataroomBrand>;
embeddedLinks?: string[];
viewId?: string;
linkId?: string;
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index caa16a5f..7c5d16ab 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -39,7 +39,7 @@ export default function DocumentView({
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
};
- brand?: Brand;
+ brand?: Partial<Brand> | null;
token?: string;
verifiedEmail?: string;
showPoweredByBanner?: boolean;
diff --git a/components/view/nav.tsx b/components/view/nav.tsx
index 99c23b68..9a20d4e6 100644
--- a/components/view/nav.tsx
+++ b/components/view/nav.tsx
@@ -42,7 +42,7 @@ export default function Nav({
numPages?: number;
allowDownload?: boolean;
assistantEnabled?: boolean;
- brand?: Brand | DataroomBrand;
+ brand?: Partial<Brand> | Partial<DataroomBrand> | null;
embeddedLinks?: string[];
viewId?: string;
linkId?: string;
diff --git a/components/view/view-data.tsx b/components/view/view-data.tsx
index 1ccb5815..522dd82d 100644
--- a/components/view/view-data.tsx
+++ b/components/view/view-data.tsx
@@ -19,7 +19,7 @@ export default function ViewData({
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
};
- brand?: Brand;
+ brand?: Partial<Brand> | null;
showPoweredByBanner?: boolean;
}) {
const { document } = link;
diff --git a/lib/types.ts b/lib/types.ts
index ce59441c..b2cf4e5a 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -63,6 +63,31 @@ export interface LinkWithDocument extends Link {
} | null;
}
+export interface LinkWithDataroom extends Link {
+ dataroom: {
+ id: string;
+ name: string;
+ teamId: string;
+ documents: {
+ id: string;
+ folderId: string | null;
+ document: {
+ id: string;
+ name: string;
+ versions: {
+ id: string;
+ versionNumber: number;
+ type: string;
+ hasPages: boolean;
+ file: string;
+ }[];
+ };
+ }[];
+ folders: DataroomFolder[];
+ lastUpdatedAt: Date;
+ };
+}
+
export interface Geo {
city?: string | undefined;
country?: string | undefined;
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index a6beda79..38d70aa0 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -4,6 +4,7 @@ import { getServerSession } from "next-auth/next";
import { generateEncrpytedPassword } from "@/lib/utils";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../auth/[...nextauth]";
+import { Brand, DataroomBrand } from "@prisma/client";
export default async function handle(
req: NextApiRequest,
@@ -34,37 +35,13 @@ export default async function handle(
metaDescription: true,
metaImage: true,
enableQuestion: true,
+ linkType: true,
feedback: {
select: {
id: true,
data: true,
},
},
- document: {
- select: {
- id: true,
- name: true,
- assistantEnabled: true,
- teamId: true,
- ownerId: true,
- team: {
- select: {
- plan: true,
- },
- },
- versions: {
- where: { isPrimary: true },
- select: {
- id: true,
- versionNumber: true,
- type: true,
- hasPages: true,
- file: true,
- },
- take: 1,
- },
- },
- },
},
});
@@ -78,21 +55,113 @@ export default async function handle(
return res.status(404).json({ error: "Link is archived" });
}
- let brand = await prisma.brand.findFirst({
- where: {
- teamId: link.document!.teamId!,
- },
- select: {
- logo: true,
- brandColor: true,
- },
- });
+ const linkType = link.linkType;
- if (!brand) {
- brand = null;
+ let brand: Partial<Brand> | Partial<DataroomBrand> | null = null;
+ let linkData: any;
+
+ if (linkType === "DOCUMENT_LINK") {
+ linkData = await prisma.link.findUnique({
+ where: { id: id },
+ select: {
+ document: {
+ select: {
+ id: true,
+ name: true,
+ assistantEnabled: true,
+ teamId: true,
+ ownerId: true,
+ team: {
+ select: {
+ plan: true,
+ },
+ },
+ versions: {
+ where: { isPrimary: true },
+ select: {
+ id: true,
+ versionNumber: true,
+ type: true,
+ hasPages: true,
+ file: true,
+ },
+ take: 1,
+ },
+ },
+ },
+ },
+ });
+
+ brand = await prisma.brand.findFirst({
+ where: {
+ teamId: linkData.document.teamId,
+ },
+ select: {
+ logo: true,
+ brandColor: true,
+ },
+ });
+ } else if (linkType === "DATAROOM_LINK") {
+ linkData = await prisma.link.findUnique({
+ where: { id: id },
+ select: {
+ dataroom: {
+ select: {
+ id: true,
+ name: true,
+ teamId: true,
+ documents: {
+ select: {
+ id: true,
+ folderId: true,
+ updatedAt: true,
+ document: {
+ select: {
+ id: true,
+ name: true,
+ versions: {
+ where: { isPrimary: true },
+ select: {
+ id: true,
+ versionNumber: true,
+ type: true,
+ hasPages: true,
+ file: true,
+ },
+ take: 1,
+ },
+ },
+ },
+ },
+ },
+ folders: {
+ orderBy: {
+ name: "asc",
+ },
+ },
+ },
+ },
+ },
+ });
+
+ brand = await prisma.dataroomBrand.findFirst({
+ where: {
+ dataroomId: linkData.dataroom.id,
+ },
+ select: {
+ logo: true,
+ banner: true,
+ brandColor: true,
+ },
+ });
}
- return res.status(200).json({ link, brand });
+ const returnLink = {
+ ...link,
+ ...linkData,
+ };
+
+ return res.status(200).json({ linkType, link: returnLink, brand });
} catch (error) {
return res.status(500).json({
message: "Internal Server Error",
@@ -114,7 +183,9 @@ export default async function handle(
const documentLink = linkType === "DOCUMENT_LINK";
const hashedPassword =
- password && password.length > 0 ? await generateEncrpytedPassword(password) : null;
+ password && password.length > 0
+ ? await generateEncrpytedPassword(password)
+ : null;
const exat = expiresAt ? new Date(expiresAt) : null;
let { domain, slug, ...linkData } = linkDomainData;
diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].ts
index 852afbc3..c1be534f 100644
--- a/pages/api/links/domains/[...domainSlug].ts
+++ b/pages/api/links/domains/[...domainSlug].ts
@@ -1,6 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "@/lib/prisma";
import { log } from "@/lib/utils";
+import { Brand, DataroomBrand } from "@prisma/client";
export default async function handle(
req: NextApiRequest,
@@ -45,6 +46,7 @@ export default async function handle(
metaDescription: true,
metaImage: true,
enableQuestion: true,
+ linkType: true,
feedback: {
select: {
id: true,
@@ -53,20 +55,21 @@ export default async function handle(
},
document: {
select: {
- id: true,
- name: true,
- ownerId: true,
- team: { select: { id: true, plan: true } },
- versions: {
- where: { isPrimary: true },
+ team: {
select: {
id: true,
- versionNumber: true,
- hasPages: true,
- type: true,
- file: true,
+ plan: true,
+ },
+ },
+ },
+ },
+ dataroom: {
+ select: {
+ team: {
+ select: {
+ id: true,
+ plan: true,
},
- take: 1,
},
},
},
@@ -74,7 +77,7 @@ export default async function handle(
});
// if link not found, return 404
- if (!link || !link.document!.team) {
+ if (!link) {
log({
message: `Link not found for custom domain _${domain}/${slug}_`,
type: "error",
@@ -82,45 +85,141 @@ export default async function handle(
});
return res.status(404).json({
error: "Link not found",
- message: `no link found, team ${link?.document!.team}`,
+ message: "No link found",
+ });
+ }
+
+ if (link.isArchived) {
+ return res.status(404).json({
+ error: "Link is archived",
+ message: "link is archived",
});
}
+ const teamPlan = link.document?.team?.plan || link.dataroom?.team.plan;
+ const teamId = link.document?.team?.id || link.dataroom?.team.id;
// if owner of document is on free plan, return 404
- if (link.document!.team.plan === "free") {
+ if (teamPlan === "free") {
log({
- message: `Link is from a free team _${link.document!.team.id}_ for custom domain _${domain}/${slug}_`,
+ message: `Link is from a free team _${teamId}_ for custom domain _${domain}/${slug}_`,
type: "info",
mention: true,
});
return res.status(404).json({
error: "Link not found",
- message: `link found, team ${link.document!.team.plan}`,
+ message: `link found, team ${teamPlan}`,
});
}
- if (link.isArchived) {
- return res.status(404).json({
- error: "Link is archived",
- message: "link is archived",
+ const linkType = link.linkType;
+ let brand: Partial<Brand> | Partial<DataroomBrand> | null = null;
+ let linkData: any;
+
+ if (linkType === "DOCUMENT_LINK") {
+ linkData = await prisma.link.findUnique({
+ where: { id: link.id },
+ select: {
+ document: {
+ select: {
+ id: true,
+ name: true,
+ teamId: true,
+ ownerId: true,
+ team: { select: { plan: true } },
+ versions: {
+ where: { isPrimary: true },
+ select: {
+ id: true,
+ versionNumber: true,
+ hasPages: true,
+ type: true,
+ file: true,
+ },
+ take: 1,
+ },
+ },
+ },
+ },
});
- }
- let brand = await prisma.brand.findFirst({
- where: {
- teamId: link.document!.team.id,
- },
- select: {
- logo: true,
- brandColor: true,
- },
- });
+ brand = await prisma.brand.findFirst({
+ where: {
+ teamId: linkData.document.teamId,
+ },
+ select: {
+ logo: true,
+ brandColor: true,
+ },
+ });
+ } else if (linkType === "DATAROOM_LINK") {
+ linkData = await prisma.link.findUnique({
+ where: { id: link.id },
+ select: {
+ dataroom: {
+ select: {
+ id: true,
+ name: true,
+ teamId: true,
+ documents: {
+ select: {
+ id: true,
+ folderId: true,
+ updatedAt: true,
+ document: {
+ select: {
+ id: true,
+ name: true,
+ versions: {
+ where: { isPrimary: true },
+ select: {
+ id: true,
+ versionNumber: true,
+ type: true,
+ hasPages: true,
+ file: true,
+ },
+ take: 1,
+ },
+ },
+ },
+ },
+ },
+ folders: {
+ orderBy: {
+ name: "asc",
+ },
+ },
+ },
+ },
+ },
+ });
- if (!brand) {
- brand = null;
+ brand = await prisma.dataroomBrand.findFirst({
+ where: {
+ dataroomId: linkData.dataroom.id,
+ },
+ select: {
+ logo: true,
+ banner: true,
+ brandColor: true,
+ },
+ });
}
- res.status(200).json({ link, brand });
+ // remove document and domain from link
+ const sanitizedLink = {
+ ...link,
+ document: undefined,
+ dataroom: undefined,
+ };
+
+ // clean up the link return object
+ const returnLink = {
+ ...sanitizedLink,
+ ...linkData,
+ };
+
+ res.status(200).json({ linkType, link: returnLink, brand });
} catch (error) {
log({
message: `Cannot get link for custom domain _${domainSlug}_ \n\n${error}`,
diff --git a/pages/view/[linkId]/index.tsx b/pages/view/[linkId]/index.tsx
index 6606a9a2..a4bb0989 100644
--- a/pages/view/[linkId]/index.tsx
+++ b/pages/view/[linkId]/index.tsx
@@ -5,79 +5,143 @@ import { useSession } from "next-auth/react";
import { ExtendedRecordMap } from "notion-types";
import notion from "@/lib/notion";
-import { CustomUser, LinkWithDocument } from "@/lib/types";
+import { CustomUser, LinkWithDataroom, LinkWithDocument } from "@/lib/types";
import { parsePageId } from "notion-utils";
import { GetStaticPropsContext } from "next";
import { useRouter } from "next/router";
-import { Brand } from "@prisma/client";
+import { Brand, DataroomBrand } from "@prisma/client";
import CustomMetatag from "@/components/view/custom-metatag";
-import Head from "next/head";
+import DataroomView from "@/components/view/dataroom/dataroom-view";
+
+type DocumentLinkData = {
+ linkType: "DOCUMENT_LINK";
+ link: LinkWithDocument;
+ brand: Brand | null;
+};
+
+type DataroomLinkData = {
+ linkType: "DATAROOM_LINK";
+ link: LinkWithDataroom;
+ brand: DataroomBrand | null;
+};
export const getStaticProps = async (context: GetStaticPropsContext) => {
const { linkId } = context.params as { linkId: string };
- // Fetch the link
- const res = await fetch(`${process.env.NEXTAUTH_URL}/api/links/${linkId}`);
- if (!res.ok) {
- return { notFound: true };
- }
- const { link, brand } = (await res.json()) as {
- link: LinkWithDocument;
- brand: Brand | null;
- };
+ try {
+ const res = await fetch(`${process.env.NEXTAUTH_URL}/api/links/${linkId}`);
+ if (!res.ok) {
+ throw new Error(`Failed to fetch: ${res.status}`);
+ }
+ const { linkType, link, brand } = (await res.json()) as
+ | DocumentLinkData
+ | DataroomLinkData;
- if (!link || !link.document) {
- return {
- notFound: true,
- };
- }
+ if (!link || !linkType) {
+ return {
+ notFound: true,
+ };
+ }
+
+ // Manage the data for the document link
+ if (linkType === "DOCUMENT_LINK") {
+ let pageId = null;
+ let recordMap = null;
- let pageId = null;
- let recordMap = null;
+ const { type, file, ...versionWithoutTypeAndFile } =
+ link.document.versions[0];
- const { type, file, ...versionWithoutTypeAndFile } =
- link.document.versions[0];
+ if (type === "notion") {
+ const notionPageId = parsePageId(file, { uuid: false });
+ if (!notionPageId) {
+ return {
+ notFound: true,
+ };
+ }
+
+ pageId = notionPageId;
+ recordMap = await notion.getPage(pageId);
+ }
+
+ const { team, ...linkDocument } = link.document;
+ const teamPlan = team?.plan || "free";
- if (type === "notion") {
- const notionPageId = parsePageId(file, { uuid: false });
- if (!notionPageId) {
return {
- notFound: true,
+ props: {
+ linkData: {
+ linkType: "DOCUMENT_LINK",
+ link: {
+ ...link,
+ document: {
+ ...linkDocument,
+ versions: [versionWithoutTypeAndFile],
+ },
+ },
+ brand,
+ },
+ notionData: {
+ rootNotionPageId: null, // do not pass rootNotionPageId to the client
+ recordMap,
+ },
+ meta: {
+ enableCustomMetatag: link.enableCustomMetatag || false,
+ metaTitle: link.metaTitle,
+ metaDescription: link.metaDescription,
+ metaImage: link.metaImage,
+ },
+ showPoweredByBanner: teamPlan === "free",
+ },
+ revalidate: brand ? 10 : false,
};
}
- pageId = notionPageId;
- recordMap = await notion.getPage(pageId);
- }
+ // Manage the data for the dataroom link
+ if (linkType === "DATAROOM_LINK") {
+ // iterate the link.documents and extract type and file and rest of the props
+ let documents = [];
+ for (const document of link.dataroom.documents) {
+ const { file, ...versionWithoutTypeAndFile } =
+ document.document.versions[0];
- const { team, ...linkDocument } = link.document;
- const teamPlan = team?.plan || "free";
-
- return {
- props: {
- // return link without file and type to avoid sending the file to the client
- link: {
- ...link,
- document: {
- ...linkDocument,
+ const newDocument = {
+ ...document.document,
+ dataroomDocumentId: document.id,
+ folderId: document.folderId,
versions: [versionWithoutTypeAndFile],
+ };
+
+ documents.push(newDocument);
+ }
+
+ return {
+ props: {
+ linkData: {
+ linkType: "DATAROOM_LINK",
+ link: {
+ ...link,
+ dataroom: {
+ ...link.dataroom,
+ documents,
+ lastUpdatedAt: null, // TODO: fix this to get the actual lastUpdatedAt
+ },
+ },
+ brand,
+ },
+ meta: {
+ enableCustomMetatag: link.enableCustomMetatag || false,
+ metaTitle: link.metaTitle,
+ metaDescription: link.metaDescription,
+ metaImage: link.metaImage,
+ },
+ showPoweredByBanner: false,
},
- },
- notionData: {
- rootNotionPageId: null, // do not pass rootNotionPageId to the client
- recordMap,
- },
- meta: {
- enableCustomMetatag: link.enableCustomMetatag || false,
- metaTitle: link.metaTitle,
- metaDescription: link.metaDescription,
- metaImage: link.metaImage,
- },
- brand, // pass brand to the client
- showPoweredByBanner: teamPlan === "free",
- },
- revalidate: brand ? 10 : false,
- };
+ revalidate: 10,
+ };
+ }
+ } catch (error) {
+ console.error("Fetching error:", error);
+ return { notFound: true };
+ }
};
export async function getStaticPaths() {
@@ -88,13 +152,12 @@ export async function getStaticPaths() {
}
export default function ViewPage({
- link,
+ linkData,
notionData,
meta,
- brand,
showPoweredByBanner,
}: {
- link: LinkWithDocument;
+ linkData: DocumentLinkData | DataroomLinkData;
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
@@ -105,103 +168,204 @@ export default function ViewPage({
metaDescription: string | null;
metaImage: string | null;
} | null;
- brand?: Brand;
showPoweredByBanner: boolean;
}) {
const router = useRouter();
+ const { data: session, status } = useSession();
+
+ if (router.isFallback) {
+ return (
+ <div className="h-screen flex items-center justify-center bg-black">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ );
+ }
+
const { token, email: verifiedEmail } = router.query as {
token: string;
email: string;
};
- const { data: session, status } = useSession();
+ const { linkType, link, brand } = linkData;
+
+ // Render the document view for DOCUMENT_LINK
+ if (linkType === "DOCUMENT_LINK") {
+ if (!linkData || status === "loading" || router.isFallback) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={meta?.enableCustomMetatag ?? false}
+ title={
+ meta?.metaTitle ?? link?.document?.name ?? "Papermark Document"
+ }
+ description={meta?.metaDescription ?? null}
+ imageUrl={meta?.metaImage ?? null}
+ url={`https://www.papermark.io/view/${router.query.linkId}`}
+ />
+ <div className="h-screen flex items-center justify-center">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ </>
+ );
+ }
+
+ const {
+ expiresAt,
+ emailProtected,
+ emailAuthenticated,
+ password: linkPassword,
+ isArchived,
+ } = link;
+
+ const { email: userEmail, id: userId } =
+ (session?.user as CustomUser) || {};
+
+ // If the link is expired, show a 404 page
+ if (expiresAt && new Date(expiresAt) < new Date()) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is expired." />
+ );
+ }
+
+ if (isArchived) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is archived." />
+ );
+ }
+
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
+ if (emailProtected || linkPassword) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle ?? link.document.name}
+ description={metaDescription}
+ imageUrl={metaImage}
+ url={`https://www.papermark.io/view/${router.query.linkId}`}
+ />
+ <DocumentView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={true}
+ notionData={notionData}
+ brand={brand}
+ token={token}
+ verifiedEmail={verifiedEmail}
+ showPoweredByBanner={showPoweredByBanner}
+ />
+ </>
+ );
+ }
- if (!link || status === "loading" || router.isFallback) {
return (
<>
<CustomMetatag
- enableBranding={meta?.enableCustomMetatag ?? false}
- title={
- meta?.metaTitle ?? link?.document?.name ?? "Papermark Document"
- }
- description={meta?.metaDescription ?? null}
- imageUrl={meta?.metaImage ?? null}
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle ?? link.document.name}
+ description={metaDescription}
+ imageUrl={metaImage}
url={`https://www.papermark.io/view/${router.query.linkId}`}
/>
- <div className="h-screen flex items-center justify-center">
- <LoadingSpinner className="h-20 w-20" />
- </div>
+ <DocumentView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={false}
+ notionData={notionData}
+ brand={brand}
+ showPoweredByBanner={showPoweredByBanner}
+ />
</>
);
}
- const {
- expiresAt,
- emailProtected,
- emailAuthenticated,
- password: linkPassword,
- isArchived,
- } = link;
+ // Render the dataroom view for DATAROOM_LINK
+ if (linkType === "DATAROOM_LINK") {
+ if (!link || status === "loading" || router.isFallback) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={meta?.enableCustomMetatag ?? false}
+ title={meta?.metaTitle ?? link?.dataroom.name ?? "Dataroom"}
+ description={meta?.metaDescription ?? null}
+ imageUrl={meta?.metaImage ?? null}
+ url={`https://www.papermark.io/view/${router.query.linkId}`}
+ />
+ <div className="h-screen flex items-center justify-center">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ </>
+ );
+ }
- const { email: userEmail, id: userId } = (session?.user as CustomUser) || {};
+ const {
+ expiresAt,
+ emailProtected,
+ emailAuthenticated,
+ password: linkPassword,
+ isArchived,
+ } = link;
- // If the link is expired, show a 404 page
- if (expiresAt && new Date(expiresAt) < new Date()) {
- return (
- <NotFound message="Sorry, the link you're looking for is expired." />
- );
- }
+ const { email: userEmail, id: userId } =
+ (session?.user as CustomUser) || {};
- if (isArchived) {
- return (
- <NotFound message="Sorry, the link you're looking for is archived." />
- );
- }
+ // If the link is expired, show a 404 page
+ if (expiresAt && new Date(expiresAt) < new Date()) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is expired." />
+ );
+ }
- const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+ if (isArchived) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is archived." />
+ );
+ }
+
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
+ if (emailProtected || linkPassword) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle}
+ description={metaDescription}
+ imageUrl={metaImage}
+ url={`https://www.papermark.io/view/${router.query.linkId}`}
+ />
+ <DataroomView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={true}
+ brand={brand}
+ token={token}
+ verifiedEmail={verifiedEmail}
+ />
+ </>
+ );
+ }
- if (emailProtected || linkPassword) {
return (
<>
<CustomMetatag
enableBranding={enableCustomMetatag ?? false}
- title={metaTitle ?? link.document.name}
+ title={metaTitle}
description={metaDescription}
imageUrl={metaImage}
url={`https://www.papermark.io/view/${router.query.linkId}`}
/>
- <DocumentView
+ <DataroomView
link={link}
userEmail={verifiedEmail ?? userEmail}
userId={userId}
- isProtected={true}
- notionData={notionData}
+ isProtected={false}
brand={brand}
- token={token}
- verifiedEmail={verifiedEmail}
- showPoweredByBanner={showPoweredByBanner}
/>
</>
);
}
-
- return (
- <>
- <CustomMetatag
- enableBranding={enableCustomMetatag ?? false}
- title={metaTitle ?? link.document.name}
- description={metaDescription}
- imageUrl={metaImage}
- url={`https://www.papermark.io/view/${router.query.linkId}`}
- />
- <DocumentView
- link={link}
- userEmail={verifiedEmail ?? userEmail}
- userId={userId}
- isProtected={false}
- notionData={notionData}
- brand={brand}
- showPoweredByBanner={showPoweredByBanner}
- />
- </>
- );
}
diff --git a/pages/view/domains/[domain]/[slug]/index.tsx b/pages/view/domains/[domain]/[slug]/index.tsx
index 0a25db81..29d43237 100644
--- a/pages/view/domains/[domain]/[slug]/index.tsx
+++ b/pages/view/domains/[domain]/[slug]/index.tsx
@@ -1,6 +1,6 @@
import LoadingSpinner from "@/components/ui/loading-spinner";
import DocumentView from "@/components/view/document-view";
-import { CustomUser, LinkWithDocument } from "@/lib/types";
+import { CustomUser, LinkWithDataroom, LinkWithDocument } from "@/lib/types";
import NotFound from "@/pages/404";
import { GetStaticPropsContext } from "next";
import { useSession } from "next-auth/react";
@@ -8,71 +8,144 @@ import { useRouter } from "next/router";
import { ExtendedRecordMap } from "notion-types";
import notion from "@/lib/notion";
import { parsePageId } from "notion-utils";
-import { Brand } from "@prisma/client";
+import { Brand, DataroomBrand } from "@prisma/client";
import CustomMetatag from "@/components/view/custom-metatag";
-import Head from "next/head";
+import DataroomView from "@/components/view/dataroom/dataroom-view";
+
+type DocumentLinkData = {
+ linkType: "DOCUMENT_LINK";
+ link: LinkWithDocument;
+ brand: Brand | null;
+};
+
+type DataroomLinkData = {
+ linkType: "DATAROOM_LINK";
+ link: LinkWithDataroom;
+ brand: DataroomBrand | null;
+};
export const getStaticProps = async (context: GetStaticPropsContext) => {
const { domain, slug } = context.params as { domain: string; slug: string };
- // Fetch the link
- const res = await fetch(
- `${process.env.NEXTAUTH_URL}/api/links/domains/${encodeURIComponent(
- domain,
- )}/${encodeURIComponent(slug)}`,
- );
- if (!res.ok) {
- return { notFound: true };
- }
- const { link, brand } = (await res.json()) as {
- link: LinkWithDocument;
- brand: Brand | null;
- };
+ try {
+ // Fetch the link
+ const res = await fetch(
+ `${process.env.NEXTAUTH_URL}/api/links/domains/${encodeURIComponent(
+ domain,
+ )}/${encodeURIComponent(slug)}`,
+ );
+ if (!res.ok) {
+ throw new Error(`Failed to fetch: ${res.status}`);
+ }
+ const { linkType, link, brand } = (await res.json()) as
+ | DocumentLinkData
+ | DataroomLinkData;
- let pageId = null;
- let recordMap = null;
+ if (!link || !linkType) {
+ return {
+ notFound: true,
+ };
+ }
+
+ // Manage the data for the document link
+ if (linkType === "DOCUMENT_LINK") {
+ let pageId = null;
+ let recordMap = null;
- const { type, file, ...versionWithoutTypeAndFile } =
- link.document.versions[0];
+ const { type, file, ...versionWithoutTypeAndFile } =
+ link.document.versions[0];
+
+ if (type === "notion") {
+ const notionPageId = parsePageId(file, { uuid: false });
+ if (!notionPageId) {
+ return {
+ notFound: true,
+ };
+ }
+
+ pageId = notionPageId;
+ recordMap = await notion.getPage(pageId);
+ }
+
+ const { team, ...linkDocument } = link.document;
+ const teamPlan = team?.plan || "free";
- if (type === "notion") {
- // regex match to get the page id from the notion url
- const notionPageId = parsePageId(file, { uuid: false });
- if (!notionPageId) {
return {
- notFound: true,
+ props: {
+ linkData: {
+ linkType: "DOCUMENT_LINK",
+ link: {
+ ...link,
+ document: {
+ ...linkDocument,
+ versions: [versionWithoutTypeAndFile],
+ },
+ },
+ brand,
+ },
+ notionData: {
+ rootNotionPageId: null, // do not pass rootNotionPageId to the client
+ recordMap,
+ },
+ meta: {
+ enableCustomMetatag: link.enableCustomMetatag || false,
+ metaTitle: link.metaTitle,
+ metaDescription: link.metaDescription,
+ metaImage: link.metaImage,
+ },
+ showPoweredByBanner: teamPlan === "free",
+ },
+ revalidate: brand ? 10 : false,
};
}
- pageId = notionPageId;
- recordMap = await notion.getPage(pageId);
- }
+ // Manage the data for the dataroom link
+ if (linkType === "DATAROOM_LINK") {
+ // iterate the link.documents and extract type and file and rest of the props
+ let documents = [];
+ for (const document of link.dataroom.documents) {
+ const { file, ...versionWithoutTypeAndFile } =
+ document.document.versions[0];
- return {
- props: {
- // return link without file and type to avoid sending the file to the client
- link: {
- ...link,
- document: {
- ...link.document,
+ const newDocument = {
+ ...document.document,
+ dataroomDocumentId: document.id,
+ folderId: document.folderId,
versions: [versionWithoutTypeAndFile],
+ };
+
+ documents.push(newDocument);
+ }
+
+ return {
+ props: {
+ linkData: {
+ linkType: "DATAROOM_LINK",
+ link: {
+ ...link,
+ dataroom: {
+ ...link.dataroom,
+ documents,
+ lastUpdatedAt: null, // TODO: fix this to get the actual lastUpdatedAt
+ },
+ },
+ brand,
+ },
+ meta: {
+ enableCustomMetatag: link.enableCustomMetatag || false,
+ metaTitle: link.metaTitle,
+ metaDescription: link.metaDescription,
+ metaImage: link.metaImage,
+ },
+ showPoweredByBanner: false,
},
- },
- notionData: {
- rootNotionPageId: pageId,
- recordMap,
- },
- meta: {
- enableCustomMetatag: link.enableCustomMetatag || false,
- metaTitle: link.metaTitle,
- metaDescription: link.metaDescription,
- metaImage: link.metaImage,
- metaUrl: `https://${domain}/${slug}`,
- },
- brand, // pass the brand to client
- },
- revalidate: 10,
- };
+ revalidate: 10,
+ };
+ }
+ } catch (error) {
+ console.error("Fetching error:", error);
+ return { notFound: true };
+ }
};
export async function getStaticPaths() {
@@ -83,12 +156,11 @@ export async function getStaticPaths() {
}
export default function ViewPage({
- link,
+ linkData,
notionData,
meta,
- brand,
}: {
- link: LinkWithDocument;
+ linkData: DocumentLinkData | DataroomLinkData;
notionData: {
rootNotionPageId: string | null;
recordMap: ExtendedRecordMap | null;
@@ -100,59 +172,183 @@ export default function ViewPage({
metaImage: string | null;
metaUrl: string | null;
} | null;
- brand?: Brand;
}) {
- const { data: session, status } = useSession();
const router = useRouter();
+ const { data: session, status } = useSession();
+
+ if (router.isFallback) {
+ return (
+ <div className="h-screen flex items-center justify-center bg-black">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ );
+ }
+
const { token, email: verifiedEmail } = router.query as {
token: string;
email: string;
};
+ const { linkType, link, brand } = linkData;
+
+ // Render the document view for DOCUMENT_LINK
+ if (linkType === "DOCUMENT_LINK") {
+ if (!link || status === "loading") {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={meta?.enableCustomMetatag ?? false}
+ title={
+ meta?.metaTitle ?? link?.document?.name ?? "Papermark Document"
+ }
+ description={meta?.metaDescription ?? null}
+ imageUrl={meta?.metaImage ?? null}
+ url={meta?.metaUrl ?? ""}
+ />
+ <div className="h-screen flex items-center justify-center">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ </>
+ );
+ }
+
+ const {
+ expiresAt,
+ emailProtected,
+ password: linkPassword,
+ isArchived,
+ } = link;
+
+ const { email: userEmail, id: userId } =
+ (session?.user as CustomUser) || {};
+
+ // If the link is expired, show a 404 page
+ if (expiresAt && new Date(expiresAt) < new Date()) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is expired." />
+ );
+ }
+
+ if (isArchived) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is archived." />
+ );
+ }
+
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
+ if (emailProtected || linkPassword) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle}
+ description={metaDescription}
+ imageUrl={metaImage}
+ url={meta?.metaUrl ?? ""}
+ />
+ <DocumentView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={true}
+ notionData={notionData}
+ brand={brand}
+ token={token}
+ verifiedEmail={verifiedEmail}
+ />
+ </>
+ );
+ }
- if (!link || status === "loading") {
return (
<>
<CustomMetatag
- enableBranding={meta?.enableCustomMetatag ?? false}
- title={
- meta?.metaTitle ?? link?.document?.name ?? "Papermark Document"
- }
- description={meta?.metaDescription ?? null}
- imageUrl={meta?.metaImage ?? null}
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle}
+ description={metaDescription}
+ imageUrl={metaImage}
url={meta?.metaUrl ?? ""}
/>
- <div className="h-screen flex items-center justify-center">
- <LoadingSpinner className="h-20 w-20" />
- </div>
+ <DocumentView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={false}
+ notionData={notionData}
+ brand={brand}
+ />
</>
);
}
- const {
- expiresAt,
- emailProtected,
- password: linkPassword,
- isArchived,
- } = link;
+ // Render the dataroom view for DATAROOM_LINK
+ if (linkType === "DATAROOM_LINK") {
+ if (!link || status === "loading" || router.isFallback) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={meta?.enableCustomMetatag ?? false}
+ title={meta?.metaTitle ?? link?.dataroom.name ?? "Dataroom"}
+ description={meta?.metaDescription ?? null}
+ imageUrl={meta?.metaImage ?? null}
+ url={meta?.metaUrl ?? ""}
+ />
+ <div className="h-screen flex items-center justify-center">
+ <LoadingSpinner className="h-20 w-20" />
+ </div>
+ </>
+ );
+ }
- const { email: userEmail, id: userId } = (session?.user as CustomUser) || {};
+ const {
+ expiresAt,
+ emailProtected,
+ emailAuthenticated,
+ password: linkPassword,
+ isArchived,
+ } = link;
- // If the link is expired, show a 404 page
- if (expiresAt && new Date(expiresAt) < new Date()) {
- return (
- <NotFound message="Sorry, the link you're looking for is expired." />
- );
- }
+ const { email: userEmail, id: userId } =
+ (session?.user as CustomUser) || {};
- if (isArchived) {
- return (
- <NotFound message="Sorry, the link you're looking for is archived." />
- );
- }
+ // If the link is expired, show a 404 page
+ if (expiresAt && new Date(expiresAt) < new Date()) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is expired." />
+ );
+ }
- const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+ if (isArchived) {
+ return (
+ <NotFound message="Sorry, the link you're looking for is archived." />
+ );
+ }
+
+ const { enableCustomMetatag, metaTitle, metaDescription, metaImage } = link;
+
+ if (emailProtected || linkPassword) {
+ return (
+ <>
+ <CustomMetatag
+ enableBranding={enableCustomMetatag ?? false}
+ title={metaTitle}
+ description={metaDescription}
+ imageUrl={metaImage}
+ url={meta?.metaUrl ?? ""}
+ />
+ <DataroomView
+ link={link}
+ userEmail={verifiedEmail ?? userEmail}
+ userId={userId}
+ isProtected={true}
+ brand={brand}
+ token={token}
+ verifiedEmail={verifiedEmail}
+ />
+ </>
+ );
+ }
- if (emailProtected || linkPassword) {
return (
<>
<CustomMetatag
@@ -162,37 +358,14 @@ export default function ViewPage({
imageUrl={metaImage}
url={meta?.metaUrl ?? ""}
/>
- <DocumentView
+ <DataroomView
link={link}
userEmail={verifiedEmail ?? userEmail}
userId={userId}
- isProtected={true}
- notionData={notionData}
+ isProtected={false}
brand={brand}
- token={token}
- verifiedEmail={verifiedEmail}
/>
</>
);
}
-
- return (
- <>
- <CustomMetatag
- enableBranding={enableCustomMetatag ?? false}
- title={metaTitle}
- description={metaDescription}
- imageUrl={metaImage}
- url={meta?.metaUrl ?? ""}
- />
- <DocumentView
- link={link}
- userEmail={verifiedEmail ?? userEmail}
- userId={userId}
- isProtected={false}
- notionData={notionData}
- brand={brand}
- />
- </>
- );
}