Skip to content

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

feat: add dataroom

Marc Seitz08ccac9c775b
diff --git a/components/datarooms/add-dataroom-document-modal.tsx b/components/datarooms/add-dataroom-document-modal.tsx
new file mode 100644
index 00000000..7e203a59
--- /dev/null
+++ b/components/datarooms/add-dataroom-document-modal.tsx
@@ -0,0 +1,118 @@
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import { useTeam } from "@/context/team-context";
+import { useState } from "react";
+import { toast } from "sonner";
+import { mutate } from "swr";
+import { SidebarFolderTreeSelection } from "@/components/sidebar-folders";
+import { useRouter } from "next/router";
+
+export function AddDataroomDocumentModal({
+ open,
+ setOpen,
+ dataroomId,
+ documentName,
+}: {
+ open: boolean;
+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;
+ dataroomId?: string;
+ documentName?: string;
+}) {
+ const router = useRouter();
+ const [folderId, setFolderId] = useState<string>("");
+ const [documentId, setDocumentId] = useState<string>("");
+ const [loading, setLoading] = useState<boolean>(false);
+
+ const teamInfo = useTeam();
+
+ /** current folder name */
+ const currentFolderPath = router.query.name as string[] | undefined;
+
+ const handleSubmit = async (event: any) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ if (folderId === "") return;
+
+ setLoading(true);
+ try {
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ documentId: documentId,
+ folderPathName: currentFolderPath?.join("/"),
+ }),
+ },
+ );
+
+ if (!response.ok) {
+ const { message } = await response.json();
+ setLoading(false);
+ toast.error(message);
+ return;
+ }
+
+ const { newPath, oldPath } = (await response.json()) as {
+ newPath: string;
+ oldPath: string;
+ };
+
+ toast.success("Document moved successfully!");
+
+ // mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders`);
+ // mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders${oldPath}`);
+ // mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders${newPath}`).then(
+ // () => {
+ // router.push(`/documents/tree${newPath}`);
+ // },
+ // );
+ } catch (error) {
+ console.error("Error moving document", error);
+ toast.error("Failed to move document. Try again.");
+ } finally {
+ setLoading(false);
+ setOpen(false);
+ }
+ };
+
+ return (
+ <Dialog open={open} onOpenChange={setOpen}>
+ <DialogContent className="sm:max-w-[425px]">
+ <DialogHeader className="text-start">
+ <DialogTitle>Add Document</DialogTitle>
+ <DialogDescription>Add your document to dataroom</DialogDescription>
+ </DialogHeader>
+ <form>
+ <div className="mb-2">
+ <SidebarFolderTreeSelection
+ selectedFolderId={folderId}
+ setFolderId={setFolderId}
+ />
+ </div>
+
+ <DialogFooter>
+ <Button
+ onClick={handleSubmit}
+ className="w-full h-9"
+ loading={loading}
+ >
+ Add to dataroom
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/components/datarooms/add-dataroom-modal.tsx b/components/datarooms/add-dataroom-modal.tsx
new file mode 100644
index 00000000..d3c881c4
--- /dev/null
+++ b/components/datarooms/add-dataroom-modal.tsx
@@ -0,0 +1,113 @@
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { useTeam } from "@/context/team-context";
+import { useState } from "react";
+import { toast } from "sonner";
+import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+import { usePlan } from "@/lib/swr/use-billing";
+import { useAnalytics } from "@/lib/analytics";
+import { mutate } from "swr";
+
+export function AddDataroomModal({ children }: { children?: React.ReactNode }) {
+ const [dataroomName, setDataroomName] = useState<string>("");
+ const [loading, setLoading] = useState<boolean>(false);
+ const [open, setOpen] = useState<boolean>(false);
+
+ const teamInfo = useTeam();
+ const { plan } = usePlan();
+ const analytics = useAnalytics();
+
+ const handleSubmit = async (event: any) => {
+ event.preventDefault();
+ event.stopPropagation();
+
+ if (dataroomName == "") return;
+
+ setLoading(true);
+
+ try {
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ name: dataroomName,
+ }),
+ },
+ );
+
+ if (!response.ok) {
+ const { message } = await response.json();
+ setLoading(false);
+ toast.error(message);
+ return;
+ }
+
+ analytics.capture("Dataroom Created", { dataroomName: dataroomName });
+ toast.success("Dataroom successfully created! 🎉");
+
+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/datarooms`);
+ } catch (error) {
+ setLoading(false);
+ toast.error("Error adding folder. Please try again.");
+ return;
+ } finally {
+ setLoading(false);
+ setOpen(false);
+ }
+ };
+
+ // If the team is on a free plan, show the upgrade modal
+ if (plan && plan.plan === "free") {
+ if (children) {
+ return (
+ <UpgradePlanModal clickedPlan="Pro" trigger={"add_dataroom_overview"}>
+ {children}
+ </UpgradePlanModal>
+ );
+ }
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={setOpen}>
+ <DialogTrigger asChild>{children}</DialogTrigger>
+ <DialogContent className="sm:max-w-[425px]">
+ <DialogHeader className="text-start">
+ <DialogTitle>Create dataroom</DialogTitle>
+ <DialogDescription>
+ Start creating a dataroom with a name.
+ </DialogDescription>
+ </DialogHeader>
+ <form onSubmit={handleSubmit}>
+ <Label htmlFor="dataroom-name" className="opacity-80">
+ Dataroom Name
+ </Label>
+ <Input
+ id="dataroom-name"
+ placeholder="ACME Aquisition"
+ className="w-full mt-1 mb-4"
+ onChange={(e) => setDataroomName(e.target.value)}
+ />
+ <DialogFooter>
+ <Button type="submit" className="w-full h-9" loading={loading}>
+ Add new dataroom
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/components/datarooms/dataroom-breadcrumb.tsx b/components/datarooms/dataroom-breadcrumb.tsx
new file mode 100644
index 00000000..9b32d0d5
--- /dev/null
+++ b/components/datarooms/dataroom-breadcrumb.tsx
@@ -0,0 +1,79 @@
+import React, { useMemo } from "react";
+import Link from "next/link";
+import {
+ Breadcrumb,
+ BreadcrumbItem,
+ BreadcrumbLink,
+ BreadcrumbList,
+ BreadcrumbPage,
+ BreadcrumbSeparator,
+} from "@/components/ui/breadcrumb";
+import { useRouter } from "next/router";
+import { useDataroomFolderWithParents } from "@/lib/swr/use-dataroom";
+
+function BreadcrumbComponentBase({
+ name,
+ dataroomId,
+}: {
+ name: string[];
+ dataroomId: string;
+}) {
+ const { folders: folderNames } = useDataroomFolderWithParents({
+ name,
+ dataroomId,
+ });
+
+ return (
+ <Breadcrumb>
+ <BreadcrumbList>
+ <BreadcrumbItem key={"root"}>
+ <BreadcrumbLink asChild>
+ <Link href={`/datarooms/${dataroomId}/documents`}>Home</Link>
+ </BreadcrumbLink>
+ </BreadcrumbItem>
+ {folderNames &&
+ folderNames.map((item, index: number, array) => {
+ return (
+ <React.Fragment key={index}>
+ <BreadcrumbSeparator />
+ {index === array.length - 1 ? (
+ <BreadcrumbItem>
+ <BreadcrumbPage className="capitalize">
+ {item.name}
+ </BreadcrumbPage>
+ </BreadcrumbItem>
+ ) : (
+ <BreadcrumbItem>
+ <BreadcrumbLink asChild>
+ <Link
+ href={`/datarooms/${dataroomId}/documents${item.path}`}
+ className="capitalize"
+ >
+ {item.name}
+ </Link>
+ </BreadcrumbLink>
+ </BreadcrumbItem>
+ )}
+ </React.Fragment>
+ );
+ })}
+ </BreadcrumbList>
+ </Breadcrumb>
+ );
+}
+
+const BreadcrumbComponent = () => {
+ const router = useRouter();
+ const name = router.query.name as string[];
+ const dataroomId = router.query.id as string;
+
+ // Use useMemo to memoize the base component with the current name value.
+ // This way, BreadcrumbComponentBase is only re-rendered when name changes.
+ const MemoizedBreadcrumbComponent = useMemo(() => {
+ return <BreadcrumbComponentBase name={name} dataroomId={dataroomId} />;
+ }, [name, dataroomId]);
+
+ return MemoizedBreadcrumbComponent;
+};
+
+export { BreadcrumbComponent };
diff --git a/components/datarooms/dataroom-card.tsx b/components/datarooms/dataroom-card.tsx
new file mode 100644
index 00000000..a39d62c5
--- /dev/null
+++ b/components/datarooms/dataroom-card.tsx
@@ -0,0 +1,107 @@
+import { timeAgo } from "@/lib/utils";
+import Link from "next/link";
+import { TeamContextType } from "@/context/team-context";
+import { Button } from "@/components/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { MoreVertical, FolderIcon } from "lucide-react";
+import { useRef } from "react";
+import { FolderWithCount } from "@/lib/swr/use-documents";
+import { Dataroom } from "@prisma/client";
+
+export default function DataroomCard({
+ dataroom,
+}: {
+ dataroom: Dataroom & { _count: { documents: number } };
+}) {
+ const dropdownRef = useRef<HTMLDivElement | null>(null);
+
+ return (
+ <li className="group/row relative rounded-lg p-3 border-0 dark:bg-secondary ring-1 ring-gray-400 dark:ring-gray-500 transition-all hover:ring-gray-500 hover:dark:ring-gray-400 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">
+ <FolderIcon className="w-8 h-8 " strokeWidth={1} />
+ </div>
+
+ <div className="flex-col">
+ <div className="flex items-center">
+ <h2 className="min-w-0 text-sm font-semibold leading-6 text-foreground truncate max-w-[150px] sm:max-w-md">
+ <Link
+ href={`/datarooms/${dataroom.id}`}
+ className="truncate w-full"
+ >
+ <span>{dataroom.name}</span>
+ <span className="absolute inset-0" />
+ </Link>
+ </h2>
+ </div>
+ <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">
+ <p className="truncate">{timeAgo(dataroom.createdAt)}</p>
+ <p>•</p>
+ <p className="truncate">
+ {dataroom._count.documents}{" "}
+ {folder._count.documents === 1 ? "Document" : "Documents"}
+ </p>
+ <p>•</p>
+ <p className="truncate">
+ {folder._count.childFolders}{" "}
+ {folder._count.childFolders === 1 ? "Folder" : "Folders"}
+ </p>
+ </div>
+ </div>
+ </div>
+
+ <div className="flex flex-row space-x-2">
+ {/* <Link
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ href={`/documents/${prismaDocument.id}`}
+ className="flex items-center z-10 space-x-1 rounded-md bg-gray-200 dark:bg-gray-700 px-1.5 sm:px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <BarChart className="h-3 sm:h-4 w-3 sm:w-4 text-muted-foreground" />
+ <p className="whitespace-nowrap text-xs sm:text-sm text-muted-foreground">
+ {nFormatter(prismaDocument._count.views)}
+ <span className="ml-1 hidden sm:inline-block">views</span>
+ </p>
+ </Link> */}
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ // size="icon"
+ variant="outline"
+ className="h-8 lg:h-9 w-8 lg:w-9 p-0 z-10 bg-transparent border-gray-200 dark:border-gray-700 hover:bg-gray-200 hover:dark:bg-gray-700"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="w-4 h-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" ref={dropdownRef}>
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuSeparator />
+
+ {/* <DropdownMenuItem
+ onClick={(event) => handleButtonClick(event, prismaDocument.id)}
+ className="text-destructive focus:bg-destructive focus:text-destructive-foreground duration-200"
+ >
+ {isFirstClick ? (
+ "Really delete?"
+ ) : (
+ <>
+ <TrashIcon className="w-4 h-4 mr-2" /> Delete document
+ </>
+ )}
+ </DropdownMenuItem> */}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </li>
+ );
+}
diff --git a/components/datarooms/dataroom-document-card.tsx b/components/datarooms/dataroom-document-card.tsx
new file mode 100644
index 00000000..6e4786d1
--- /dev/null
+++ b/components/datarooms/dataroom-document-card.tsx
@@ -0,0 +1,148 @@
+import { nFormatter, timeAgo } from "@/lib/utils";
+import Link from "next/link";
+import { type DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
+import { TeamContextType } from "@/context/team-context";
+import BarChart from "@/components/shared/icons/bar-chart";
+import Image from "next/image";
+import NotionIcon from "@/components/shared/icons/notion";
+import { toast } from "sonner";
+import { Button } from "@/components/ui/button";
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { TrashIcon, MoreVertical, FolderInputIcon } from "lucide-react";
+import { mutate } from "swr";
+import { useCopyToClipboard } from "@/lib/utils/use-copy-to-clipboard";
+import Check from "@/components/shared/icons/check";
+import Copy from "@/components/shared/icons/copy";
+import { useEffect, useRef, useState } from "react";
+import { useTheme } from "next-themes";
+import { MoveToFolderModal } from "@/components/documents/move-folder-modal";
+import { type DataroomFolderDocument } from "@/lib/swr/use-dataroom";
+
+type DocumentsCardProps = {
+ document: DataroomFolderDocument;
+ teamInfo: TeamContextType | null;
+};
+export default function DataroomDocumentCard({
+ document,
+ teamInfo,
+}: DocumentsCardProps) {
+ const { theme, systemTheme } = useTheme();
+ const isLight =
+ theme === "light" || (theme === "system" && systemTheme === "light");
+
+ const { isCopied, copyToClipboard } = useCopyToClipboard({});
+ const [isFirstClick, setIsFirstClick] = useState<boolean>(false);
+ const [menuOpen, setMenuOpen] = useState<boolean>(false);
+ const [moveFolderOpen, setMoveFolderOpen] = useState<boolean>(false);
+ const dropdownRef = useRef<HTMLDivElement | null>(null);
+
+ return (
+ <>
+ <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">
+ {document.document.type === "notion" ? (
+ <NotionIcon className="w-8 h-8" />
+ ) : (
+ <Image
+ src={`/_icons/${document.document.type}${isLight ? "-light" : ""}.svg`}
+ alt="File icon"
+ width={50}
+ height={50}
+ />
+ )}
+ </div>
+
+ <div className="flex-col">
+ <div className="flex items-center">
+ <h2 className="min-w-0 text-sm font-semibold leading-6 text-foreground truncate max-w-[150px] sm:max-w-md">
+ <Link
+ href={`/documents/${document.document.id}`}
+ className="truncate w-full"
+ >
+ <span>{document.document.name}</span>
+ <span className="absolute inset-0" />
+ </Link>
+ </h2>
+ </div>
+ <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">
+ <p className="truncate">{timeAgo(document.createdAt)}</p>
+ <p>•</p>
+ {document.document._count.versions > 1 ? (
+ <>
+ <p>•</p>
+ <p className="truncate">{`${document.document._count.versions} Versions`}</p>
+ </>
+ ) : null}
+ </div>
+ </div>
+ </div>
+
+ <div className="flex flex-row space-x-2">
+ <Link
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ href={`/documents/${document.document.id}`}
+ className="flex items-center z-10 space-x-1 rounded-md bg-gray-200 dark:bg-gray-700 px-1.5 sm:px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <BarChart className="h-3 sm:h-4 w-3 sm:w-4 text-muted-foreground" />
+ <p className="whitespace-nowrap text-xs sm:text-sm text-muted-foreground">
+ {nFormatter(document.document._count.views)}
+ <span className="ml-1 hidden sm:inline-block">views</span>
+ </p>
+ </Link>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ // size="icon"
+ variant="outline"
+ className="h-8 lg:h-9 w-8 lg:w-9 p-0 z-10 bg-transparent border-gray-200 dark:border-gray-700 hover:bg-gray-200 hover:dark:bg-gray-700"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="w-4 h-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" ref={dropdownRef}>
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuItem onClick={() => setMoveFolderOpen(true)}>
+ <FolderInputIcon className="w-4 h-4 mr-2" />
+ Move to folder
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+
+ {/* <DropdownMenuItem
+ onClick={(event) => handleButtonClick(event, prismaDocument.id)}
+ className="text-destructive focus:bg-destructive focus:text-destructive-foreground duration-200"
+ >
+ {isFirstClick ? (
+ "Really delete?"
+ ) : (
+ <>
+ <TrashIcon className="w-4 h-4 mr-2" /> Delete document
+ </>
+ )}
+ </DropdownMenuItem> */}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ </li>
+ {moveFolderOpen ? (
+ <MoveToFolderModal
+ open={moveFolderOpen}
+ setOpen={setMoveFolderOpen}
+ documentId={document.id}
+ documentName={document.document.name}
+ />
+ ) : null}
+ </>
+ );
+}
diff --git a/components/datarooms/dataroom-folders.tsx b/components/datarooms/dataroom-folders.tsx
new file mode 100644
index 00000000..e6e86af6
--- /dev/null
+++ b/components/datarooms/dataroom-folders.tsx
@@ -0,0 +1,234 @@
+import { useRouter } from "next/router";
+import { FileTree } from "@/components/ui/nextra-filetree";
+import { memo, useMemo } from "react";
+import {
+ useDataroomFoldersTree,
+ type DRFolderWithDocuments,
+} from "@/lib/swr/use-dataroom";
+
+// Helper function to build nested folder structure
+const buildNestedFolderStructure = (folders: DRFolderWithDocuments[]) => {
+ const folderMap = new Map();
+
+ // Initialize every folder with an additional childFolders property
+ folders.forEach((folder) => {
+ folderMap.set(folder.id, { ...folder, childFolders: [] });
+ });
+
+ const rootFolders: DRFolderWithDocuments[] = [];
+
+ folderMap.forEach((folder, id) => {
+ if (folder.parentId) {
+ const parent = folderMap.get(folder.parentId);
+ parent.childFolders.push(folder);
+ } else {
+ rootFolders.push(folder);
+ }
+ });
+
+ return rootFolders;
+};
+
+const FolderComponent = memo(
+ ({ folder }: { folder: DRFolderWithDocuments }) => {
+ const router = useRouter();
+
+ // Memoize the rendering of the current folder's documents
+ const documents = useMemo(
+ () =>
+ folder.documents.map((doc) => (
+ <FileTree.File
+ key={doc.id}
+ name={doc.name}
+ onToggle={() => router.push(`/documents/${doc.id}`)}
+ />
+ )),
+ [folder.documents, router.query.name],
+ );
+
+ // Recursively render child folders if they exist
+ const childFolders = useMemo(
+ () =>
+ folder.childFolders.map((childFolder) => (
+ <FolderComponent key={childFolder.id} folder={childFolder} />
+ )),
+ [folder.childFolders],
+ );
+
+ return (
+ <FileTree.Folder
+ name={folder.name}
+ key={folder.id}
+ active={
+ folder.path === "/" + (router.query.name as string[])?.join("/")
+ }
+ childActive={router.query.name?.includes(folder.name)}
+ onToggle={() => router.push(`/documents/tree${folder.path}`)}
+ >
+ {childFolders}
+ {documents}
+ </FileTree.Folder>
+ );
+ },
+);
+FolderComponent.displayName = "FolderComponent";
+
+const FolderComponentSelection = memo(
+ ({
+ folder,
+ selectedFolderId,
+ setFolderId,
+ selectedDocumentId,
+ setDocumentId,
+ }: {
+ folder: DRFolderWithDocuments;
+ selectedFolderId: string;
+ setFolderId: React.Dispatch<React.SetStateAction<string>>;
+ selectedDocumentId?: string;
+ setDocumentId?: React.Dispatch<React.SetStateAction<string>>;
+ }) => {
+ const router = useRouter();
+ // Memoize the rendering of the current folder's documents
+ const documents = useMemo(
+ () =>
+ folder.documents.map((doc) => (
+ <div
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setDocumentId(doc.id);
+ }}
+ >
+ <FileTree.File
+ key={doc.id}
+ name={doc.document.name}
+ // onToggle={() => router.push(`/documents/${doc.id}`)}
+ />
+ </div>
+ )),
+ [folder.documents, router.query.name, selectedDocumentId, setDocumentId],
+ );
+ // Recursively render child folders if they exist
+ const childFolders = useMemo(
+ () =>
+ folder.childFolders.map((childFolder) => (
+ <FolderComponentSelection
+ key={childFolder.id}
+ folder={childFolder}
+ selectedFolderId={selectedFolderId}
+ setFolderId={setFolderId}
+ />
+ )),
+ [folder.childFolders, selectedFolderId, setFolderId],
+ );
+
+ return (
+ <div
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setFolderId(folder.id);
+ }}
+ >
+ <FileTree.Folder
+ name={folder.name}
+ key={folder.id}
+ active={folder.id === selectedFolderId}
+ >
+ {childFolders}
+ {documents}
+ </FileTree.Folder>
+ </div>
+ );
+ },
+);
+FolderComponentSelection.displayName = "FolderComponentSelection";
+
+const DataroomFolders = ({ folders }: { folders: DRFolderWithDocuments[] }) => {
+ const nestedFolders = useMemo(() => {
+ if (folders) {
+ return buildNestedFolderStructure(folders);
+ }
+ return [];
+ }, [folders]);
+
+ return (
+ <FileTree>
+ {nestedFolders.map((folder) => (
+ <FolderComponent key={folder.id} folder={folder} />
+ ))}
+ </FileTree>
+ );
+};
+
+export function DataroomFolderTree({ dataroomId }: { dataroomId: string }) {
+ const { folders, error } = useDataroomFoldersTree({ dataroomId });
+
+ if (!folders || error) return null;
+
+ return <DataroomFolders folders={folders} />;
+}
+
+const DataroomFoldersSelection = ({
+ folders,
+ selectedFolderId,
+ setFolderId,
+ selectedDocumentId,
+ setDocumentId,
+}: {
+ folders: DRFolderWithDocuments[];
+ selectedFolderId: string;
+ setFolderId: React.Dispatch<React.SetStateAction<string>>;
+ selectedDocumentId?: string;
+ setDocumentId?: React.Dispatch<React.SetStateAction<string>>;
+}) => {
+ const nestedFolders = useMemo(() => {
+ if (folders) {
+ return buildNestedFolderStructure(folders);
+ }
+ return [];
+ }, [folders]);
+
+ return (
+ <FileTree>
+ {nestedFolders.map((folder) => (
+ <FolderComponentSelection
+ key={folder.id}
+ folder={folder}
+ selectedFolderId={selectedFolderId}
+ setFolderId={setFolderId}
+ selectedDocumentId={selectedDocumentId}
+ setDocumentId={setDocumentId}
+ />
+ ))}
+ </FileTree>
+ );
+};
+
+export function DataroomFolderTreeSelection({
+ dataroomId,
+ selectedFolderId,
+ setFolderId,
+ selectedDocumentId,
+ setDocumentId,
+}: {
+ dataroomId: string;
+ selectedFolderId: string;
+ setFolderId: React.Dispatch<React.SetStateAction<string>>;
+ selectedDocumentId?: string;
+ setDocumentId?: React.Dispatch<React.SetStateAction<string>>;
+}) {
+ const { folders, error } = useDataroomFoldersTree({ dataroomId });
+
+ if (!folders || error) return null;
+
+ return (
+ <DataroomFoldersSelection
+ folders={folders}
+ selectedFolderId={selectedFolderId}
+ setFolderId={setFolderId}
+ selectedDocumentId={selectedDocumentId}
+ setDocumentId={setDocumentId}
+ />
+ );
+}
diff --git a/components/datarooms/dataroom-header.tsx b/components/datarooms/dataroom-header.tsx
new file mode 100644
index 00000000..3685466e
--- /dev/null
+++ b/components/datarooms/dataroom-header.tsx
@@ -0,0 +1,41 @@
+export const DataroomHeader = ({
+ title,
+ description,
+ actions,
+}: {
+ title: string;
+ description: string;
+ actions?: React.ReactNode[];
+}) => {
+ const actionRows: React.ReactNode[][] = [];
+ if (actions) {
+ for (let i = 0; i < actions.length; i += 3) {
+ actionRows.push(actions.slice(i, i + 3));
+ }
+ }
+
+ return (
+ <section className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12">
+ <div className="space-y-1">
+ <h1 className="text-xl sm:text-2xl text-foreground font-semibold tracking-tight">
+ {title}
+ </h1>
+ <p className="text-xs sm:text-sm text-muted-foreground font-mono">
+ {description}
+ </p>
+ </div>
+ <div className="flex items-center gap-x-1">
+ {actionRows.map((row, i) => (
+ <ul
+ key={i.toString()}
+ className="flex flex-wrap items-center justify-end gap-2 md:gap-4 md:flex-nowrap"
+ >
+ {row.map((action, i) => (
+ <li key={i}>{action}</li>
+ ))}
+ </ul>
+ ))}
+ </div>
+ </section>
+ );
+};
diff --git a/lib/id-helper.ts b/lib/id-helper.ts
index ab867bd7..3d1a4f2e 100644
--- a/lib/id-helper.ts
+++ b/lib/id-helper.ts
@@ -34,8 +34,9 @@ export class IdGenerator<TPrefixes extends string> {
export const newId = new IdGenerator({
view: "view",
- inv: "inv",
+ inv: "inv", // invitation
email: "email",
doc: "doc",
page: "page",
+ dataroom: "dr",
}).id;
diff --git a/lib/swr/use-dataroom.ts b/lib/swr/use-dataroom.ts
new file mode 100644
index 00000000..dafc765b
--- /dev/null
+++ b/lib/swr/use-dataroom.ts
@@ -0,0 +1,201 @@
+import { type NextRouter, useRouter } from "next/router";
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { Dataroom, DataroomDocument, DataroomFolder } from "@prisma/client";
+import { useTeam } from "@/context/team-context";
+import { LinkWithViews } from "@/lib/types";
+
+export type DataroomFolderWithCount = DataroomFolder & {
+ _count: {
+ documents: number;
+ childFolders: number;
+ };
+};
+
+function getBaseInfo(): {
+ teamId: string | undefined;
+ id: string | undefined;
+ router: NextRouter;
+} {
+ const router = useRouter();
+
+ const { id } = router.query as {
+ id: string;
+ };
+
+ const teamInfo = useTeam();
+ const teamId = teamInfo?.currentTeam?.id;
+
+ return { teamId, id, router };
+}
+
+export function useDataroom() {
+ const { teamId, id } = getBaseInfo();
+
+ const { data: dataroom, error } = useSWR<Dataroom>(
+ teamId && id && `/api/teams/${teamId}/datarooms/${id}`,
+ fetcher,
+ { dedupingInterval: 10000 },
+ );
+
+ return {
+ dataroom,
+ loading: !error && !dataroom,
+ error,
+ };
+}
+
+export function useDataroomLinks() {
+ const { teamId, id } = getBaseInfo();
+
+ const { data: links, error } = useSWR<LinkWithViews[]>(
+ teamId && id && `/api/teams/${teamId}/datarooms/${id}/links`,
+ fetcher,
+ { dedupingInterval: 10000 },
+ );
+
+ return {
+ links,
+ loading: !error && !links,
+ error,
+ };
+}
+
+export function useDataroomDocuments() {
+ const { teamId, id } = getBaseInfo();
+
+ const { data: documents, error } = useSWR<DataroomFolderDocument[]>(
+ teamId && id && `/api/teams/${teamId}/datarooms/${id}/documents`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ documents,
+ loading: !documents && !error,
+ error,
+ };
+}
+
+export function useDataroomFolders({
+ root,
+ name,
+}: {
+ root?: boolean;
+ name?: string[];
+}) {
+ const { teamId, id } = getBaseInfo();
+
+ const { data: folders, error } = useSWR<DataroomFolderWithCount[]>(
+ teamId &&
+ id &&
+ `/api/teams/${teamId}/datarooms/${id}/folders${root ? "?root=true" : name ? `/${name.join("/")}` : ""}`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ folders,
+ loading: !folders && !error,
+ error,
+ };
+}
+
+export type DRFolderWithDocuments = DataroomFolder & {
+ childFolders: DRFolderWithDocuments[];
+ documents: {
+ id: string;
+ folderId: string;
+ document: {
+ id: string;
+ name: string;
+ type: string;
+ };
+ }[];
+};
+
+export function useDataroomFoldersTree({ dataroomId }: { dataroomId: string }) {
+ const { teamId } = getBaseInfo();
+
+ const { data: folders, error } = useSWR<DRFolderWithDocuments[]>(
+ teamId && `/api/teams/${teamId}/datarooms/${dataroomId}/folders`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ folders,
+ loading: !folders && !error,
+ error,
+ };
+}
+
+export function useDataroomFolderWithParents({
+ name,
+ dataroomId,
+}: {
+ name: string[];
+ dataroomId: string;
+}) {
+ const { teamId } = getBaseInfo();
+
+ const { data: folders, error } = useSWR<{ name: string; path: string }[]>(
+ teamId &&
+ name &&
+ `/api/teams/${teamId}/datarooms/${dataroomId}/folders/parents/${name.join("/")}`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ folders,
+ loading: !folders && !error,
+ error,
+ };
+}
+
+export type DataroomFolderDocument = DataroomDocument & {
+ document: {
+ id: string;
+ name: string;
+ type: string;
+ _count: {
+ views: number;
+ versions: number;
+ };
+ };
+};
+
+export function useDataroomFolderDocuments({ name }: { name: string[] }) {
+ const { teamId, id } = getBaseInfo();
+
+ const { data: documents, error } = useSWR<DataroomFolderDocument[]>(
+ teamId &&
+ id &&
+ name &&
+ `/api/teams/${teamId}/datarooms/${id}/folders/documents/${name.join("/")}`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ documents,
+ loading: !documents && !error,
+ error,
+ };
+}
diff --git a/lib/swr/use-datarooms.ts b/lib/swr/use-datarooms.ts
new file mode 100644
index 00000000..991b7797
--- /dev/null
+++ b/lib/swr/use-datarooms.ts
@@ -0,0 +1,30 @@
+import useSWR from "swr";
+import { fetcher } from "@/lib/utils";
+import { useTeam } from "@/context/team-context";
+import { Dataroom } from "@prisma/client";
+
+export type DataroomWithCount = Dataroom & {
+ _count: {
+ documents: number;
+ };
+};
+
+export default function useDatarooms() {
+ const teamInfo = useTeam();
+
+ const { data: datarooms, error } = useSWR<DataroomWithCount[]>(
+ teamInfo?.currentTeam?.id &&
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms`,
+ fetcher,
+ {
+ revalidateOnFocus: false,
+ dedupingInterval: 30000,
+ },
+ );
+
+ return {
+ datarooms,
+ loading: !datarooms && !error,
+ error,
+ };
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/documents.ts b/pages/api/teams/[teamId]/datarooms/[id]/documents.ts
new file mode 100644
index 00000000..882d8d77
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/documents.ts
@@ -0,0 +1,146 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+import slugify from "@sindresorhus/slugify";
+import { newId } from "@/lib/id-helper";
+import { log } from "@/lib/utils";
+import { errorhandler } from "@/lib/errorHandler";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/documents
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const documents = await prisma.dataroomDocument.findMany({
+ where: {
+ dataroomId: dataroomId,
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ include: {
+ document: {
+ select: {
+ id: true,
+ name: true,
+ type: true,
+ },
+ },
+ },
+ });
+
+ const documentsWithCount = documents.map((document) => ({
+ ...document,
+ document: { ...document.document, _count: { views: 0, versions: 0 } },
+ }));
+
+ return res.status(200).json(documentsWithCount);
+ } catch (error) {
+ console.error("Request error", error);
+ return res
+ .status(500)
+ .json({ error: "Error fetching documents from dataroom" });
+ }
+ } else if (req.method === "POST") {
+ // POST /api/teams/:teamId/datarooms/:id/documents
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ res.status(401).end("Unauthorized");
+ return;
+ }
+
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+
+ // Assuming data is an object with `name` and `description` properties
+ const { documentId, folderPathName } = req.body as {
+ documentId: string;
+ folderPathName?: string;
+ };
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const folder = await prisma.dataroomFolder.findUnique({
+ where: {
+ dataroomId_path: {
+ dataroomId,
+ path: "/" + folderPathName,
+ },
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ const document = await prisma.dataroomDocument.create({
+ data: {
+ documentId,
+ dataroomId,
+ folderId: folder?.id,
+ },
+ });
+
+ return res.status(201).json(document);
+ } catch (error) {
+ log({
+ message: `Failed to create dataroom document. \n\n*teamId*: _${teamId}_, \n\n*dataroomId*: ${dataroomId} \n\n ${error}`,
+ type: "error",
+ });
+ errorhandler(error, res);
+ }
+ } else {
+ // We only allow GET requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts
new file mode 100644
index 00000000..ce8f2fad
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/[...name].ts
@@ -0,0 +1,83 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/folders/:name
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const {
+ teamId,
+ id: dataroomId,
+ name,
+ } = req.query as { teamId: string; id: string; name: string[] };
+
+ const path = "/" + name.join("/"); // construct the materialized path
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const parentFolder = await prisma.dataroomFolder.findUnique({
+ where: {
+ dataroomId_path: {
+ dataroomId,
+ path,
+ },
+ },
+ select: {
+ id: true,
+ parentId: true,
+ },
+ });
+
+ if (!parentFolder) {
+ return res.status(404).end("Parent Folder not found");
+ }
+
+ const folders = await prisma.dataroomFolder.findMany({
+ where: {
+ dataroomId,
+ parentId: parentFolder.id,
+ },
+ include: {
+ _count: {
+ select: { documents: true, childFolders: true },
+ },
+ },
+ });
+
+ return res.status(200).json(folders);
+ } catch (error) {
+ console.error("Request error", error);
+ return res.status(500).json({ error: "Error fetching folders" });
+ }
+ } else {
+ // We only allow POST requests
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/documents/[...name].ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/documents/[...name].ts
new file mode 100644
index 00000000..950d1e8a
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/documents/[...name].ts
@@ -0,0 +1,99 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/folders/documents/:name
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const {
+ teamId,
+ id: dataroomId,
+ name,
+ } = req.query as { teamId: string; id: string; name: string[] };
+
+ const path = "/" + name.join("/"); // construct the materialized path
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const folder = await prisma.dataroomFolder.findUnique({
+ where: {
+ dataroomId_path: {
+ dataroomId,
+ path,
+ },
+ },
+ select: {
+ id: true,
+ parentId: true,
+ },
+ });
+
+ if (!folder) {
+ return res.status(404).end("Folder not found");
+ }
+
+ const documents = await prisma.dataroomDocument.findMany({
+ where: {
+ dataroomId: dataroomId,
+ folderId: folder.id,
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ select: {
+ id: true,
+ folderId: true,
+ createdAt: true,
+ updatedAt: true,
+ document: {
+ select: {
+ id: true,
+ name: true,
+ type: true,
+ _count: {
+ select: { views: true, versions: true },
+ },
+ },
+ },
+ },
+ });
+
+ return res.status(200).json(documents);
+ } catch (error) {
+ console.error("Request error", error);
+ return res
+ .status(500)
+ .json({ error: "Error fetching dataroom folder documents" });
+ }
+ } else {
+ // We only allow GET requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts
new file mode 100644
index 00000000..3c17754b
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/index.ts
@@ -0,0 +1,182 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+import slugify from "@sindresorhus/slugify";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/folders
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const {
+ teamId,
+ id: dataroomId,
+ root,
+ } = req.query as { teamId: string; id: string; root?: string };
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ /** if root is present then only get root folders */
+ if (root === "true") {
+ const folders = await prisma.dataroomFolder.findMany({
+ where: {
+ dataroomId,
+ parentId: null,
+ },
+ include: {
+ _count: {
+ select: { documents: true, childFolders: true },
+ },
+ },
+ });
+
+ return res.status(200).json(folders);
+ }
+
+ const folders = await prisma.dataroomFolder.findMany({
+ where: {
+ dataroomId,
+ },
+ include: {
+ documents: {
+ select: {
+ id: true,
+ folderId: true,
+ document: {
+ select: {
+ id: true,
+ name: true,
+ type: true,
+ },
+ },
+ },
+ },
+ childFolders: {
+ include: {
+ documents: {
+ select: {
+ id: true,
+ folderId: true,
+ document: {
+ select: {
+ id: true,
+ name: true,
+ type: true,
+ },
+ },
+ },
+ },
+ },
+ },
+ },
+ });
+
+ return res.status(200).json(folders);
+ } catch (error) {
+ console.error("Request error", error);
+ return res.status(500).json({ error: "Error fetching folders" });
+ }
+ } else if (req.method === "POST") {
+ // POST /api/teams/:teamId/datarooms/:id/folders
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ res.status(401).end("Unauthorized");
+ return;
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const { name, path } = req.body as { name: string; path?: string };
+
+ const childFolderPath = path
+ ? "/" + path + "/" + slugify(name)
+ : "/" + slugify(name);
+
+ const parentFolderPath = path ? "/" + path : "/";
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const parentFolder = await prisma.dataroomFolder.findUnique({
+ where: {
+ dataroomId_path: {
+ dataroomId: dataroomId,
+ path: parentFolderPath,
+ },
+ },
+ select: {
+ id: true,
+ name: true,
+ path: true,
+ },
+ });
+
+ const folder = await prisma.dataroomFolder.create({
+ data: {
+ name: name,
+ path: childFolderPath,
+ parentId: parentFolder?.id ?? null,
+ dataroomId: dataroomId,
+ },
+ });
+
+ const folderWithDocs = {
+ ...folder,
+ documents: [],
+ childFolders: [],
+ parentFolderPath: parentFolderPath,
+ };
+
+ res.status(201).json(folderWithDocs);
+ } catch (error) {
+ console.error("Request error", error);
+ res.status(500).json({ error: "Error creating folder" });
+ }
+ } else {
+ // We only allow POST requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/folders/parents/[...name].ts b/pages/api/teams/[teamId]/datarooms/[id]/folders/parents/[...name].ts
new file mode 100644
index 00000000..9c44682e
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/folders/parents/[...name].ts
@@ -0,0 +1,79 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/folders/parents/:name
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const {
+ teamId,
+ id: dataroomId,
+ name,
+ } = req.query as { teamId: string; id: string; name: string[] };
+
+ let folderNames = [];
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ for (let i = 0; i < name.length; i++) {
+ const path = "/" + name.slice(0, i + 1).join("/"); // construct the materialized path
+ console.log("path", path);
+
+ const folder = await prisma.dataroomFolder.findUnique({
+ where: {
+ dataroomId_path: {
+ dataroomId,
+ path,
+ },
+ },
+ select: {
+ id: true,
+ parentId: true,
+ name: true,
+ },
+ });
+
+ if (!folder) {
+ return res.status(404).end("Parent Folder not found");
+ }
+
+ folderNames.push({ name: folder.name, path: path });
+ }
+
+ return res.status(200).json(folderNames);
+ } catch (error) {
+ console.error("Request error", error);
+ return res.status(500).json({ error: "Error fetching folders" });
+ }
+ } else {
+ // We only allow POST requests
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/index.ts
new file mode 100644
index 00000000..971d011a
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/index.ts
@@ -0,0 +1,58 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+import { errorhandler } from "@/lib/errorHandler";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const dataroom = await prisma.dataroom.findUnique({
+ where: {
+ id: dataroomId,
+ },
+ });
+
+ return res.status(200).json(dataroom);
+ } catch (error) {
+ errorhandler(error, res);
+ }
+ } else {
+ // We only allow GET requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/links.ts b/pages/api/teams/[teamId]/datarooms/[id]/links.ts
new file mode 100644
index 00000000..8ff0f713
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/[id]/links.ts
@@ -0,0 +1,78 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import { authOptions } from "../../../../auth/[...nextauth]";
+import { log } from "@/lib/utils";
+import { CustomUser } from "@/lib/types";
+import { getTeamWithUsersAndDocument } from "@/lib/team/helper";
+import { errorhandler } from "@/lib/errorHandler";
+import prisma from "@/lib/prisma";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms/:id/links
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const { teamId, id: dataroomId } = req.query as {
+ teamId: string;
+ id: string;
+ };
+
+ const userId = (session.user as CustomUser).id;
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const links = await prisma.link.findMany({
+ where: {
+ dataroomId,
+ linkType: "DATAROOM_LINK",
+ },
+ orderBy: {
+ createdAt: "asc",
+ },
+ include: {
+ views: {
+ orderBy: {
+ viewedAt: "desc",
+ },
+ },
+ _count: {
+ select: { views: true },
+ },
+ },
+ });
+
+ return res.status(200).json(links);
+ } catch (error) {
+ log({
+ message: `Failed to get links for dataroom: _${dataroomId}_. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``,
+ type: "error",
+ });
+ errorhandler(error, res);
+ }
+ } else {
+ // We only allow GET requests
+ res.setHeader("Allow", ["GET"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/api/teams/[teamId]/datarooms/index.ts b/pages/api/teams/[teamId]/datarooms/index.ts
new file mode 100644
index 00000000..38aec7cc
--- /dev/null
+++ b/pages/api/teams/[teamId]/datarooms/index.ts
@@ -0,0 +1,111 @@
+import { NextApiRequest, NextApiResponse } from "next";
+import { getServerSession } from "next-auth/next";
+import prisma from "@/lib/prisma";
+import { authOptions } from "@/pages/api/auth/[...nextauth]";
+import { CustomUser } from "@/lib/types";
+import slugify from "@sindresorhus/slugify";
+import { newId } from "@/lib/id-helper";
+
+export default async function handle(
+ req: NextApiRequest,
+ res: NextApiResponse,
+) {
+ if (req.method === "GET") {
+ // GET /api/teams/:teamId/datarooms
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const userId = (session.user as CustomUser).id;
+ const { teamId } = req.query as { teamId: string };
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const datarooms = await prisma.dataroom.findMany({
+ where: {
+ teamId: teamId,
+ },
+ include: {
+ _count: {
+ select: { documents: true },
+ },
+ },
+ });
+
+ return res.status(200).json(datarooms);
+ } catch (error) {
+ console.error("Request error", error);
+ return res.status(500).json({ error: "Error fetching datarooms" });
+ }
+ } else if (req.method === "POST") {
+ // POST /api/teams/:teamId/datarooms
+ const session = await getServerSession(req, res, authOptions);
+ if (!session) {
+ res.status(401).end("Unauthorized");
+ return;
+ }
+
+ const userId = (session.user as CustomUser).id;
+
+ const { teamId } = req.query as { teamId: string };
+ const { name } = req.body as { name: string };
+
+ try {
+ // Check if the user is part of the team
+ const team = await prisma.team.findUnique({
+ where: {
+ id: teamId,
+ users: {
+ some: {
+ userId: userId,
+ },
+ },
+ },
+ });
+
+ if (!team) {
+ return res.status(401).end("Unauthorized");
+ }
+
+ const pId = newId("dataroom");
+
+ const dataroom = await prisma.dataroom.create({
+ data: {
+ name: name,
+ teamId: teamId,
+ pId: pId,
+ },
+ });
+
+ const dataroomWithCount = {
+ ...dataroom,
+ _count: { documents: 0 },
+ };
+
+ res.status(201).json(dataroomWithCount);
+ } catch (error) {
+ console.error("Request error", error);
+ res.status(500).json({ error: "Error creating dataroom" });
+ }
+ } else {
+ // We only allow POST requests
+ res.setHeader("Allow", ["GET", "POST"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+}
diff --git a/pages/datarooms/[id]/documents/[...name].tsx b/pages/datarooms/[id]/documents/[...name].tsx
new file mode 100644
index 00000000..3b9ef902
--- /dev/null
+++ b/pages/datarooms/[id]/documents/[...name].tsx
@@ -0,0 +1,185 @@
+import useDocuments, { useRootFolders } from "@/lib/swr/use-documents";
+import { useTeam } from "@/context/team-context";
+import DocumentCard from "@/components/documents/document-card";
+import { Skeleton } from "@/components/ui/skeleton";
+import { FileIcon, FolderIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
+import { AddDocumentModal } from "@/components/documents/add-document-modal";
+import { Separator } from "@/components/ui/separator";
+import AppLayout from "@/components/layouts/app";
+import { Button } from "@/components/ui/button";
+import Folder from "@/components/shared/icons/folder";
+import FolderCard from "@/components/documents/folder-card";
+import { EmptyDocuments } from "@/components/documents/empty-document";
+import { AddFolderModal } from "@/components/folders/add-folder-modal";
+import {
+ useDataroom,
+ useDataroomFolderDocuments,
+ useDataroomFolders,
+} from "@/lib/swr/use-dataroom";
+import { DataroomHeader } from "@/components/datarooms/dataroom-header";
+import { NavMenu } from "@/components/navigation-menu";
+import { BreadcrumbComponent } from "@/components/datarooms/dataroom-breadcrumb";
+import { useRouter } from "next/router";
+import DataroomDocumentCard from "@/components/datarooms/dataroom-document-card";
+
+export default function Documents() {
+ const router = useRouter();
+ const { name } = router.query as { name: string[] };
+
+ const { dataroom } = useDataroom();
+ const { folders } = useDataroomFolders({ name });
+ const { documents } = useDataroomFolderDocuments({ name });
+
+ const teamInfo = useTeam();
+
+ return (
+ <AppLayout>
+ <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 px-1">
+ <header>
+ <DataroomHeader
+ title={dataroom?.name ?? ""}
+ description={dataroom?.pId ?? ""}
+ actions={[
+ <AddDocumentModal isDataroom={true} dataroomId={dataroom?.id}>
+ <Button
+ className="flex-1 text-left group flex gap-x-3 items-center justify-start px-3"
+ title="Add New Document"
+ >
+ <PlusIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
+ <span>Add New Document</span>
+ </Button>
+ </AddDocumentModal>,
+ <AddFolderModal isDataroom={true} dataroomId={dataroom?.id}>
+ <Button
+ size="icon"
+ variant="outline"
+ className="bg-gray-50 dark:bg-black border-gray-500 hover:bg-gray-200 hover:dark:bg-muted"
+ >
+ <FolderPlusIcon
+ className="w-5 h-5 shrink-0"
+ aria-hidden="true"
+ />
+ </Button>
+ </AddFolderModal>,
+ ]}
+ />
+
+ <NavMenu
+ navigation={[
+ {
+ label: "Overview",
+ href: `/datarooms/${dataroom?.id}`,
+ segment: `${dataroom?.id}`,
+ },
+ {
+ label: "Documents",
+ href: `/datarooms/${dataroom?.id}/documents`,
+ segment: "documents",
+ },
+ {
+ label: "Analytics",
+ href: `/datarooms/${dataroom?.id}/analytics`,
+ segment: "analytics",
+ },
+ {
+ label: "Settings",
+ href: `/datarooms/${dataroom?.id}/settings`,
+ segment: "settings",
+ },
+ ]}
+ />
+ </header>
+
+ <div className="grid md:grid-cols-4 gap-2">
+ <div className="md:col-span-1">Tree</div>
+ <div className="md:col-span-3 space-y-4">
+ <BreadcrumbComponent />
+ <section className="flex items-center gap-x-2 mb-2">
+ {folders && folders.length > 0 ? (
+ <p className="text-sm text-gray-400 flex items-center gap-x-1">
+ <FolderIcon className="w-4 h-4" />
+ <span>{folders.length} folders</span>
+ </p>
+ ) : null}
+ {documents && documents.length > 0 ? (
+ <p className="text-sm text-gray-400 flex items-center gap-x-1">
+ <FileIcon className="w-4 h-4" />
+ <span>{documents.length} documents</span>
+ </p>
+ ) : null}
+ </section>
+ {/* Folders list */}
+ <ul role="list" className="space-y-4">
+ {folders
+ ? folders.map((folder) => {
+ return (
+ <FolderCard
+ key={folder.id}
+ folder={folder}
+ teamInfo={teamInfo}
+ isDataroom={true}
+ dataroomId={dataroom?.id}
+ />
+ );
+ })
+ : Array.from({ length: 3 }).map((_, i) => (
+ <li
+ key={i}
+ className="relative w-full py-5 px-4 border rounded-lg flex items-center space-x-3 sm:px-6 lg:px-6"
+ >
+ <Skeleton key={i} className="h-9 w-9" />
+ <div>
+ <Skeleton key={i} className="h-4 w-32" />
+ <Skeleton key={i + 1} className="mt-2 h-3 w-12" />
+ </div>
+ <Skeleton
+ key={i + 1}
+ className="h-5 w-20 absolute top-[50%] transform -translate-y-[50%] right-5"
+ />
+ </li>
+ ))}
+ </ul>
+
+ {/* Documents list */}
+ <ul role="list" className="space-y-4">
+ {documents
+ ? documents.map((document) => {
+ return (
+ <DataroomDocumentCard
+ key={document.id}
+ document={document}
+ teamInfo={teamInfo}
+ />
+ );
+ })
+ : Array.from({ length: 3 }).map((_, i) => (
+ <li
+ key={i}
+ className="relative w-full py-5 px-4 border rounded-lg flex items-center space-x-3 sm:px-6 lg:px-6"
+ >
+ <Skeleton key={i} className="h-9 w-9" />
+ <div>
+ <Skeleton key={i} className="h-4 w-32" />
+ <Skeleton key={i + 1} className="mt-2 h-3 w-12" />
+ </div>
+ <Skeleton
+ key={i + 1}
+ className="h-5 w-20 absolute top-[50%] transform -translate-y-[50%] right-5"
+ />
+ </li>
+ ))}
+ </ul>
+ </div>
+ </div>
+
+ <div className="space-y-4">
+ {documents && documents.length === 0 && (
+ <div className="flex items-center justify-center">
+ <EmptyDocuments />
+ </div>
+ )}
+ </div>
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/datarooms/[id]/documents/index.tsx b/pages/datarooms/[id]/documents/index.tsx
new file mode 100644
index 00000000..03c2cf5e
--- /dev/null
+++ b/pages/datarooms/[id]/documents/index.tsx
@@ -0,0 +1,180 @@
+import useDocuments, { useRootFolders } from "@/lib/swr/use-documents";
+import { useTeam } from "@/context/team-context";
+import DocumentCard from "@/components/documents/document-card";
+import { Skeleton } from "@/components/ui/skeleton";
+import { FileIcon, FolderIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
+import { AddDocumentModal } from "@/components/documents/add-document-modal";
+import { Separator } from "@/components/ui/separator";
+import AppLayout from "@/components/layouts/app";
+import { Button } from "@/components/ui/button";
+import Folder from "@/components/shared/icons/folder";
+import FolderCard from "@/components/documents/folder-card";
+import { EmptyDocuments } from "@/components/documents/empty-document";
+import { AddFolderModal } from "@/components/folders/add-folder-modal";
+import {
+ useDataroom,
+ useDataroomDocuments,
+ useDataroomFolders,
+} from "@/lib/swr/use-dataroom";
+import { DataroomHeader } from "@/components/datarooms/dataroom-header";
+import { NavMenu } from "@/components/navigation-menu";
+import { BreadcrumbComponent } from "@/components/datarooms/dataroom-breadcrumb";
+import DataroomDocumentCard from "@/components/datarooms/dataroom-document-card";
+
+export default function Documents() {
+ const { dataroom } = useDataroom();
+ const { documents } = useDataroomDocuments();
+ const { folders } = useDataroomFolders({ root: true });
+ const teamInfo = useTeam();
+
+ return (
+ <AppLayout>
+ <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 px-1">
+ <header>
+ <DataroomHeader
+ title={dataroom?.name ?? ""}
+ description={dataroom?.pId ?? ""}
+ actions={[
+ <AddDocumentModal isDataroom={true} dataroomId={dataroom?.id}>
+ <Button
+ className="flex-1 text-left group flex gap-x-3 items-center justify-start px-3"
+ title="Add New Document"
+ >
+ <PlusIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
+ <span>Add New Document</span>
+ </Button>
+ </AddDocumentModal>,
+ <AddFolderModal isDataroom={true} dataroomId={dataroom?.id}>
+ <Button
+ size="icon"
+ variant="outline"
+ className="bg-gray-50 dark:bg-black border-gray-500 hover:bg-gray-200 hover:dark:bg-muted"
+ >
+ <FolderPlusIcon
+ className="w-5 h-5 shrink-0"
+ aria-hidden="true"
+ />
+ </Button>
+ </AddFolderModal>,
+ ]}
+ />
+
+ <NavMenu
+ navigation={[
+ {
+ label: "Overview",
+ href: `/datarooms/${dataroom?.id}`,
+ segment: `${dataroom?.id}`,
+ },
+ {
+ label: "Documents",
+ href: `/datarooms/${dataroom?.id}/documents`,
+ segment: "documents",
+ },
+ {
+ label: "Analytics",
+ href: `/datarooms/${dataroom?.id}/analytics`,
+ segment: "analytics",
+ },
+ {
+ label: "Settings",
+ href: `/datarooms/${dataroom?.id}/settings`,
+ segment: "settings",
+ },
+ ]}
+ />
+ </header>
+
+ <div className="grid md:grid-cols-4 gap-2">
+ <div className="md:col-span-1">Tree</div>
+ <div className="md:col-span-3 space-y-4">
+ <BreadcrumbComponent />
+ <section className="flex items-center gap-x-2 mb-2">
+ {folders && folders.length > 0 ? (
+ <p className="text-sm text-gray-400 flex items-center gap-x-1">
+ <FolderIcon className="w-4 h-4" />
+ <span>{folders.length} folders</span>
+ </p>
+ ) : null}
+ {documents && documents.length > 0 ? (
+ <p className="text-sm text-gray-400 flex items-center gap-x-1">
+ <FileIcon className="w-4 h-4" />
+ <span>{documents.length} documents</span>
+ </p>
+ ) : null}
+ </section>
+ {/* Folders list */}
+ <ul role="list" className="space-y-4">
+ {folders
+ ? folders.map((folder) => {
+ return (
+ <FolderCard
+ key={folder.id}
+ folder={folder}
+ teamInfo={teamInfo}
+ isDataroom={true}
+ dataroomId={dataroom?.id}
+ />
+ );
+ })
+ : Array.from({ length: 3 }).map((_, i) => (
+ <li
+ key={i}
+ className="relative w-full py-5 px-4 border rounded-lg flex items-center space-x-3 sm:px-6 lg:px-6"
+ >
+ <Skeleton key={i} className="h-9 w-9" />
+ <div>
+ <Skeleton key={i} className="h-4 w-32" />
+ <Skeleton key={i + 1} className="mt-2 h-3 w-12" />
+ </div>
+ <Skeleton
+ key={i + 1}
+ className="h-5 w-20 absolute top-[50%] transform -translate-y-[50%] right-5"
+ />
+ </li>
+ ))}
+ </ul>
+
+ {/* Documents list */}
+ <ul role="list" className="space-y-4">
+ {documents
+ ? documents.map((document) => {
+ return (
+ <DataroomDocumentCard
+ key={document.id}
+ document={document}
+ teamInfo={teamInfo}
+ />
+ );
+ })
+ : Array.from({ length: 3 }).map((_, i) => (
+ <li
+ key={i}
+ className="relative w-full py-5 px-4 border rounded-lg flex items-center space-x-3 sm:px-6 lg:px-6"
+ >
+ <Skeleton key={i} className="h-9 w-9" />
+ <div>
+ <Skeleton key={i} className="h-4 w-32" />
+ <Skeleton key={i + 1} className="mt-2 h-3 w-12" />
+ </div>
+ <Skeleton
+ key={i + 1}
+ className="h-5 w-20 absolute top-[50%] transform -translate-y-[50%] right-5"
+ />
+ </li>
+ ))}
+ </ul>
+ </div>
+ </div>
+
+ <div className="space-y-4">
+ {documents && documents.length === 0 && (
+ <div className="flex items-center justify-center">
+ <EmptyDocuments />
+ </div>
+ )}
+ </div>
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/datarooms/[id]/index.tsx b/pages/datarooms/[id]/index.tsx
new file mode 100644
index 00000000..eb73a685
--- /dev/null
+++ b/pages/datarooms/[id]/index.tsx
@@ -0,0 +1,77 @@
+import { DataroomHeader } from "@/components/datarooms/dataroom-header";
+import AppLayout from "@/components/layouts/app";
+import LinkSheet from "@/components/links/link-sheet";
+import LinksTable from "@/components/links/links-table";
+import { NavMenu } from "@/components/navigation-menu";
+import { Button } from "@/components/ui/button";
+import { useDataroom, useDataroomLinks } from "@/lib/swr/use-dataroom";
+import { useState } from "react";
+
+export default function DataroomPage() {
+ const { dataroom } = useDataroom();
+ const { links } = useDataroomLinks();
+
+ const [isLinkSheetOpen, setIsLinkSheetOpen] = useState<boolean>(false);
+
+ if (!dataroom) {
+ return <div>Loading...</div>;
+ }
+
+ return (
+ <AppLayout>
+ <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 px-1">
+ <header>
+ <DataroomHeader
+ title={dataroom.name}
+ description={dataroom.pId}
+ actions={[
+ <Button onClick={() => setIsLinkSheetOpen(true)}>
+ Create Link
+ </Button>,
+ ]}
+ />
+
+ <NavMenu
+ navigation={[
+ {
+ label: "Overview",
+ href: `/datarooms/${dataroom.id}`,
+ segment: `${dataroom.id}`,
+ },
+ {
+ label: "Documents",
+ href: `/datarooms/${dataroom.id}/documents`,
+ segment: "documents",
+ },
+ {
+ label: "Analytics",
+ href: `/datarooms/${dataroom.id}/analytics`,
+ segment: "analytics",
+ },
+ {
+ label: "Settings",
+ href: `/datarooms/${dataroom.id}/settings`,
+ segment: "settings",
+ },
+ ]}
+ />
+ </header>
+
+ <div className="space-y-4">
+ {/* Links */}
+ <LinksTable links={links} targetType={"DATAROOM"} />
+
+ {/* Visitors */}
+ {/* <VisitorsTable numPages={primaryVersion.numPages!} /> */}
+
+ <LinkSheet
+ linkType={"DATAROOM_LINK"}
+ isOpen={isLinkSheetOpen}
+ setIsOpen={setIsLinkSheetOpen}
+ existingLinks={links}
+ />
+ </div>
+ </div>
+ </AppLayout>
+ );
+}
diff --git a/pages/datarooms/index.tsx b/pages/datarooms/index.tsx
new file mode 100644
index 00000000..207c5161
--- /dev/null
+++ b/pages/datarooms/index.tsx
@@ -0,0 +1,83 @@
+import { AddDataroomModal } from "@/components/datarooms/add-dataroom-modal";
+import AppLayout from "@/components/layouts/app";
+import { Button } from "@/components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+} from "@/components/ui/card";
+import { Separator } from "@/components/ui/separator";
+import useDatarooms from "@/lib/swr/use-datarooms";
+import { PlusIcon } from "lucide-react";
+import Link from "next/link";
+
+export default function DataroomsPage() {
+ const { datarooms } = useDatarooms();
+
+ return (
+ <AppLayout>
+ <main className="p-4 sm:py-4 sm:px-4 sm:m-4">
+ <section className="flex items-center justify-between mb-4 md:mb-8 lg:mb-12">
+ <div className="space-y-1">
+ <h2 className="text-xl sm:text-2xl text-foreground font-semibold tracking-tight">
+ Datarooms
+ </h2>
+ <p className="text-xs sm:text-sm text-muted-foreground">
+ Manage your datarooms
+ </p>
+ </div>
+ <div className="flex items-center gap-x-1">
+ <AddDataroomModal>
+ <Button
+ className="flex-1 text-left group flex gap-x-3 items-center justify-start px-3"
+ title="Add New Document"
+ >
+ <PlusIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
+ <span>Create New Dataroom</span>
+ </Button>
+ </AddDataroomModal>
+ </div>
+ {/* </div> */}
+ </section>
+
+ <Separator className="mb-5 bg-gray-200 dark:bg-gray-800" />
+
+ <div className="space-y-4">
+ <ul className="grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-2 xl:grid-cols-3">
+ {datarooms &&
+ datarooms.map((dataroom) => (
+ <Link key={dataroom.id} href={`/datarooms/${dataroom.id}`}>
+ <Card className="hover:border-primary/50 group relative overflow-hidden duration-500 ">
+ <CardHeader>
+ <div className="flex items-center justify-between">
+ <CardTitle className="truncate">
+ {dataroom.name}
+ </CardTitle>
+ </div>
+ <CardDescription>{dataroom.pId}</CardDescription>
+ </CardHeader>
+ <CardContent>
+ <dl className="divide-y divide-gray-100 text-sm leading-6 ">
+ <div className="flex justify-between gap-x-4 py-3">
+ <dt className="text-gray-500 dark:text-gray-400">
+ Documents
+ </dt>
+ <dd className="flex items-start gap-x-2">
+ <div className="font-medium text-gray-900 dark:text-gray-200">
+ {dataroom._count.documents ?? 0}
+ </div>
+ </dd>
+ </div>
+ </dl>
+ </CardContent>
+ </Card>
+ </Link>
+ ))}
+ </ul>
+ </div>
+ </main>
+ </AppLayout>
+ );
+}