Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add dataroom specific navbar
Marc Seitz6efc30b0f6a6
diff --git a/components/view/DataroomViewer.tsx b/components/view/DataroomViewer.tsxindex f59f1bca..61589847 100644--- a/components/view/DataroomViewer.tsx+++ b/components/view/DataroomViewer.tsx@@ -1,9 +1,4 @@-import {- Brand,- Dataroom,- DataroomDocument,- DataroomFolder,-} from "@prisma/client";+import { Brand, Dataroom, DataroomBrand, DataroomFolder } from "@prisma/client";import Nav from "./nav";import { Button } from "../ui/button";import FolderCard from "./dataroom/folder-card";@@ -15,8 +10,24 @@ import {BreadcrumbItem,BreadcrumbLink,BreadcrumbList,+ BreadcrumbPage,+ BreadcrumbSeparator,} from "../ui/breadcrumb";import Link from "next/link";+import DataroomNav from "./dataroom/nav-dataroom";+import { FileTree } from "../ui/nextra-filetree";+import { ViewFolderTree } from "../datarooms/folders";+import React from "react";+import {+ Sheet,+ SheetContent,+ SheetOverlay,+ SheetPortal,+ SheetTrigger,+} from "../ui/sheet";+import { MenuIcon, PanelLeftIcon, XIcon } from "lucide-react";+import * as SheetPrimitive from "@radix-ui/react-dialog";+import { cn } from "@/lib/utils";type DataroomDocument = {dataroomDocumentId: string;@@ -38,7 +49,7 @@ export default function DataroomViewer({setViewType,setDocumentData,}: {- brand: Brand;+ brand: DataroomBrand;viewId: string;dataroomViewId: string;dataroom: any;@@ -60,28 +71,105 @@ export default function DataroomViewer({documents: DataroomDocument[];folders: DataroomFolder[];};- console.log("documents, ", documents);++ console.log("dataroom", dataroom);return (<>- <Nav brand={brand} viewId={viewId} />+ <DataroomNav brand={brand} viewId={viewId} dataroom={dataroom} /><divstyle={{ height: "calc(100vh - 64px)" }}className="flex items-center relative bg-white dark:bg-black">- <div className="flex justify-center mx-auto relative h-full w-full">- <ScrollArea className="flex-grow " showScrollbar>- <div className="relative overflow-hidden mx-2 sm:mx-3 md:mx-5 lg:mx-7 xl:mx-10 mt-4 md:mt-5 lg:mt-8 mb-10 space-y-8 p-3 w-1/2">- <Breadcrumb>- <BreadcrumbList>- <BreadcrumbItem key={"root"}>- <BreadcrumbLink asChild>- <BreadcrumbLink onClick={() => setFolderId(null)}>- Home+ <div className="flex items-start justify-center mx-auto relative h-full w-full">+ {/* Tree view */}+ <div className="hidden md:flex h-full overflow-auto md:mx-5 lg:mx-7 xl:mx-10 mt-4 md:mt-5 lg:mt-8 mb-10 space-y-8 py-3 w-1/4 ">+ <ViewFolderTree+ folders={folders}+ documents={documents}+ setFolderId={setFolderId}+ folderId={folderId}+ />+ </div>++ {/* Detail view */}+ <ScrollArea className="flex-grow h-full" showScrollbar>+ <div className="md:mx-5 lg:mx-7 xl:mx-10 mt-4 md:mt-5 lg:mt-8 mb-10 space-y-8 p-3">+ <div className="flex items-center gap-x-2">+ {/* sidebar for mobile */}+ <div className="flex md:hidden">+ <Sheet>+ <SheetTrigger asChild>+ <button className="text-muted-foreground lg:hidden hover:text-black">+ <PanelLeftIcon className="h-5 w-5" aria-hidden="true" />+ </button>+ </SheetTrigger>+ <SheetPortal>+ <SheetOverlay className="fixed top-[35dvh] z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0" />+ <SheetPrimitive.Content+ className={cn(+ "fixed top-[35dvh] z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",+ "left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-lg",+ "w-[280px] sm:w-[300px] lg:hidden p-0 m-0",+ )}+ >+ <div className="h-full overflow-auto mt-8 space-y-8 py-3 px-2">+ <ViewFolderTree+ folders={folders}+ documents={documents}+ setFolderId={setFolderId}+ folderId={folderId}+ />+ </div>+ <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">+ <XIcon className="h-4 w-4" />+ <span className="sr-only">Close</span>+ </SheetPrimitive.Close>+ </SheetPrimitive.Content>+ </SheetPortal>+ {/* <SheetContent+ side="left"+ className="w-[280px] sm:w-[300px] lg:hidden p-0 m-0 top-56"+ >+ <div className="h-full overflow-auto md:mx-5 lg:mx-7 xl:mx-10 mt-4 md:mt-5 lg:mt-8 mb-10 space-y-8 py-3 px-2">+ <ViewFolderTree+ folders={folders}+ documents={documents}+ setFolderId={setFolderId}+ folderId={folderId}+ />+ </div>+ </SheetContent> */}+ </Sheet>+ </div>++ <Breadcrumb>+ <BreadcrumbList>+ <BreadcrumbItem key={"root"}>+ <BreadcrumbLink asChild>+ <BreadcrumbLink onClick={() => setFolderId(null)}>+ Home+ </BreadcrumbLink></BreadcrumbLink>- </BreadcrumbLink>- </BreadcrumbItem>- </BreadcrumbList>- </Breadcrumb>+ </BreadcrumbItem>+ {folders &&+ folders+ .filter((folder) => folder.id === folderId)+ .map((folder, index: number, array) => {+ console.log("folder", folder);+ return (+ <React.Fragment key={index}>+ <BreadcrumbSeparator />+ <BreadcrumbItem>+ <BreadcrumbPage className="capitalize">+ {folder.name}+ </BreadcrumbPage>+ </BreadcrumbItem>+ </React.Fragment>+ );+ })}+ </BreadcrumbList>+ </Breadcrumb>+ </div><div className="space-y-4">{/* Folders list */}<ul role="list" className="space-y-4">diff --git a/components/view/dataroom/nav-dataroom.tsx b/components/view/dataroom/nav-dataroom.tsxnew file mode 100644index 00000000..f9eecce3--- /dev/null+++ b/components/view/dataroom/nav-dataroom.tsx@@ -0,0 +1,202 @@+import Link from "next/link";+import { Button } from "../../ui/button";+import PapermarkSparkle from "../../shared/icons/papermark-sparkle";+import { ArrowUpRight, Download } from "lucide-react";+import { Brand, DataroomBrand } from "@prisma/client";+import Image from "next/image";+import { toast } from "sonner";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuTrigger,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuShortcut,+} from "@/components/ui/dropdown-menu";+import { timeAgo } from "@/lib/utils";++export default function DataroomNav({+ pageNumber,+ numPages,+ allowDownload,+ assistantEnabled,+ brand,+ viewId,+ linkId,+ type,+ embeddedLinks,+ isDataroom,+ setDocumentData,+ dataroom,+}: {+ pageNumber?: number;+ numPages?: number;+ allowDownload?: boolean;+ assistantEnabled?: boolean;+ brand?: DataroomBrand;+ embeddedLinks?: string[];+ viewId?: string;+ linkId?: string;+ type?: "pdf" | "notion";+ isDataroom?: boolean;+ setDocumentData?: (data: any) => void;+ dataroom?: any;+}) {+ const downloadFile = async () => {+ if (!allowDownload || type === "notion") return;+ try {+ const response = await fetch(`/api/links/download`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({ linkId, viewId }),+ });++ if (!response.ok) {+ toast.error("Error downloading file");+ return;+ }++ const { downloadUrl } = await response.json();+ window.open(downloadUrl, "_blank");+ } catch (error) {+ console.error("Error downloading file:", error);+ }+ };++ return (+ <nav+ className="bg-black"+ style={{+ backgroundColor: brand && brand.brandColor ? brand.brandColor : "black",+ }}+ >+ <div className="mx-auto px-2 sm:px-6 lg:px-8">+ <div className="relative flex h-12 items-center justify-between">+ <div className="flex flex-1 justify-start items-center">+ <div className="flex flex-shrink-0 items-center relative h-6 w-36">+ {brand && brand.logo ? (+ <Image+ className="object-contain"+ src={brand.logo}+ alt="Logo"+ fill+ quality={100}+ priority+ />+ ) : (+ <Link+ href="https://www.papermark.io"+ target="_blank"+ className="text-2xl font-bold tracking-tighter text-white"+ >+ Papermark+ </Link>+ )}+ </div>+ {isDataroom && setDocumentData ? (+ <div>+ <Button+ onClick={() => setDocumentData(null)}+ className="text-white text-sm font-medium"+ variant="link"+ >+ Dataroom Home+ </Button>+ </div>+ ) : null}+ </div>+ <div className="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0 space-x-4">+ {embeddedLinks && embeddedLinks.length > 0 ? (+ <DropdownMenu>+ <DropdownMenuTrigger>+ <Button className="text-sm font-medium text-white bg-gray-900 hover:bg-gray-900/80">+ Links on Page+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent className="space-y-2" align="end">+ <DropdownMenuLabel>Links on current page</DropdownMenuLabel>+ <DropdownMenuSeparator />+ {embeddedLinks.map((link, index) => (+ <Link+ href={link}+ target="_blank"+ rel="noopener noreferrer"+ key={index}+ >+ <DropdownMenuItem className="group h-10">+ <span className="w-[200px] truncate group-focus:text-clip group-focus:overflow-x-auto">+ {link}+ </span>+ <DropdownMenuShortcut className="pl-2 opacity-0 group-hover:opacity-60 group-focus:opacity-60">+ <ArrowUpRight />+ </DropdownMenuShortcut>+ </DropdownMenuItem>+ </Link>+ ))}+ </DropdownMenuContent>+ </DropdownMenu>+ ) : null}+ {assistantEnabled ? (+ <Link href={`/view/${linkId}/chat`}>+ <Button+ className="text-white bg-gray-900 hover:bg-gray-900/80 m-1"+ variant={"special"}+ size={"icon"}+ style={{+ backgroundSize: "200% auto",+ }}+ title="Open AI Document Assistant"+ >+ <PapermarkSparkle className="h-5 w-5" />+ </Button>+ </Link>+ ) : null}+ {allowDownload ? (+ <Button+ onClick={downloadFile}+ className="text-white bg-gray-900 hover:bg-gray-900/80 m-1"+ size="icon"+ title="Download document"+ >+ <Download className="w-5 h-5" />+ </Button>+ ) : null}+ {pageNumber && numPages ? (+ <div className="bg-gray-900 text-white rounded-md h-10 px-4 py-2 items-center flex text-sm font-medium">+ <span>{pageNumber}</span>+ <span className="text-gray-400"> / {numPages}</span>+ </div>+ ) : null}+ </div>+ </div>+ </div>+ {brand && brand.banner ? (+ <div className="relative h-[30vh]">+ <Image+ className="object-cover w-full h-[30vh]"+ src={brand.banner}+ alt="Banner"+ width={1920}+ height={320}+ quality={100}+ priority+ />+ <div className="absolute bottom-5 w-fit backdrop-blur-md bg-white/30 rounded-r-md">+ <div className="px-5 sm:px-10 py-2">+ <div className="text-3xl">{dataroom.name}</div>+ <time+ className="text-sm"+ dateTime={new Date(dataroom.lastUpdatedAt).toISOString()}+ >+ {`Last updated ${timeAgo(dataroom.lastUpdatedAt)}`}+ </time>+ </div>+ </div>+ </div>+ ) : null}+ </nav>+ );+}diff --git a/pages/api/links/[id]/dataroom.ts b/pages/api/links/[id]/dataroom.tsindex bf4588f8..513a03e5 100644--- a/pages/api/links/[id]/dataroom.ts+++ b/pages/api/links/[id]/dataroom.ts@@ -93,7 +93,14 @@ export default async function handle(brand = null;}- return res.status(200).json({ link, brand });+ const lastUpdatedAt = link.dataroom?.documents.reduce((acc, doc) => {+ if (doc.updatedAt.getTime() > acc.getTime()) {+ return doc.updatedAt;+ }+ return acc;+ }, new Date(0));++ return res.status(200).json({ link, brand, lastUpdatedAt });} catch (error) {return res.status(500).json({message: "Internal Server Error",diff --git a/pages/view/d/[linkId]/index.tsx b/pages/view/d/[linkId]/index.tsxindex 1f214072..7d527cfb 100644--- a/pages/view/d/[linkId]/index.tsx+++ b/pages/view/d/[linkId]/index.tsx@@ -31,6 +31,7 @@ export interface LinkWithDataroom extends Link {};}[];folders: DataroomFolder[];+ lastUpdatedAt: Date;};}@@ -45,9 +46,10 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {if (!res.ok) {return { notFound: true };}- const { link, brand } = (await res.json()) as {+ const { link, brand, lastUpdatedAt } = (await res.json()) as {link: LinkWithDataroom;brand: DataroomBrand | null;+ lastUpdatedAt: Date;};if (!link || !link.dataroom) {@@ -83,7 +85,7 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {// return link without file and type to avoid sending the file to the clientlink: {...link,- dataroom: { ...link.dataroom, documents: documents },+ dataroom: { ...link.dataroom, documents: documents, lastUpdatedAt },},meta: {enableCustomMetatag: link.enableCustomMetatag || false,