Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add dataroom association to each document
Marc Seitze159ee4ad560
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsxindex 0b952792..09b2f353 100644--- a/components/documents/document-card.tsx+++ b/components/documents/document-card.tsx@@ -13,6 +13,7 @@ import {FolderInputIcon,Layers2Icon,MoreVertical,+ ServerIcon,TrashIcon,} from "lucide-react";import { useTheme } from "next-themes";@@ -40,6 +41,7 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";+import { BadgeTooltip } from "@/components/ui/tooltip";type DocumentsCardProps = {document: DocumentWithLinksAndLinkCountAndViewCount;@@ -227,21 +229,16 @@ export default function DocumentsCard({<span className="absolute inset-0" /></Link></h2>- {/* <div className="ml-2 flex">- <button- className="group z-10 rounded-md bg-gray-200 p-1 transition-all duration-75 hover:scale-105 hover:bg-emerald-100 active:scale-95 dark:bg-gray-700 hover:dark:bg-emerald-200"- onClick={() =>- handleCopyToClipboard(prismaDocument.links[0].id)- }- title="Copy to clipboard"- >- {isCopied ? (- <Check className="size-3 text-muted-foreground group-hover:text-emerald-700" />- ) : (- <Copy className="size-3 text-muted-foreground group-hover:text-emerald-700" />- )}- </button>- </div> */}+ {prismaDocument._count.datarooms > 0 && (+ <div className="z-20">+ <BadgeTooltip+ content={`In ${prismaDocument._count.datarooms} dataroom${prismaDocument._count.datarooms > 1 ? "s" : ""}`}+ key="dataroom"+ >+ <ServerIcon className="ml-2 h-4 w-4 text-[#fb7a00] hover:text-[#fb7a00]/90" />+ </BadgeTooltip>+ </div>+ )}</div><div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground"><p className="truncate">{timeAgo(prismaDocument.createdAt)}</p>diff --git a/components/documents/document-header.tsx b/components/documents/document-header.tsxindex 148b5565..5ab415fa 100644--- a/components/documents/document-header.tsx+++ b/components/documents/document-header.tsx@@ -1,3 +1,4 @@+import Link from "next/link";import { useRouter } from "next/router";import { useEffect, useRef, useState } from "react";@@ -6,14 +7,15 @@ import { useTeam } from "@/context/team-context";import { PlanEnum } from "@/ee/stripe/constants";import { Document, DocumentVersion } from "@prisma/client";import {- AlertCircleIcon,+ ArrowRightIcon,BetweenHorizontalStartIcon,+ ChevronRight,CloudDownloadIcon,DownloadIcon,FileDownIcon,MoonIcon,+ ServerIcon,SheetIcon,- Sparkles,SunIcon,TrashIcon,ViewIcon,@@ -26,7 +28,10 @@ import { mutate } from "swr";import { getFile } from "@/lib/files/get-file";import { usePlan } from "@/lib/swr/use-billing";import useDatarooms from "@/lib/swr/use-datarooms";-import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";+import {+ DocumentWithLinksAndLinkCountAndViewCount,+ DocumentWithVersion,+} from "@/lib/types";import { cn } from "@/lib/utils";import { fileIcon } from "@/lib/utils/get-file-icon";@@ -34,6 +39,11 @@ import FileUp from "@/components/shared/icons/file-up";import MoreVertical from "@/components/shared/icons/more-vertical";import PapermarkSparkle from "@/components/shared/icons/papermark-sparkle";import { Button } from "@/components/ui/button";+import {+ Collapsible,+ CollapsibleContent,+ CollapsibleTrigger,+} from "@/components/ui/collapsible";import {DropdownMenu,DropdownMenuContent,@@ -60,7 +70,7 @@ export default function DocumentHeader({teamId,actions,}: {- prismaDocument: Document & { hasPageLinks?: boolean };+ prismaDocument: DocumentWithVersion;primaryVersion: DocumentVersion;teamId: string;actions?: React.ReactNode[];@@ -94,6 +104,9 @@ export default function DocumentHeader({}}+ // Check if document is in any datarooms+ const dataroomCount = prismaDocument.datarooms?.length || 0;+const handleUpgradeClick = (plan: PlanEnum, trigger: string) => {setSelectedPlan(plan);setPlanModalTrigger(trigger);@@ -820,6 +833,41 @@ export default function DocumentHeader({</div></div>+ {/* Datarooms collapsible section */}+ {dataroomCount > 0 && (+ <div className="mb-2">+ <Collapsible className="w-full">+ <CollapsibleTrigger className="flex w-full items-center text-sm font-medium">+ <div className="flex items-center space-x-2 [&[data-state=open]>svg.chevron]:rotate-180">+ <ChevronRight className="h-4 w-4 transition-transform duration-200" />+ <ServerIcon className="h-4 w-4 text-[#fb7a00]" />+ <span>+ In {dataroomCount} dataroom{dataroomCount > 1 ? "s" : ""}+ </span>+ </div>+ </CollapsibleTrigger>+ <CollapsibleContent className="pl-6 pt-2">+ <ul className="space-y-1">+ {prismaDocument.datarooms?.map((item) => (+ <li+ key={item.dataroom.id}+ className="flex items-center space-x-2 text-sm"+ >+ <ArrowRightIcon className="h-3.5 w-3.5" />+ <Link+ href={`/datarooms/${item.dataroom.id}/documents`}+ className="hover:underline"+ >+ {item.dataroom.name}+ </Link>+ </li>+ ))}+ </ul>+ </CollapsibleContent>+ </Collapsible>+ </div>+ )}+{isFree && prismaDocument.hasPageLinks && (<AlertBannerid="in-document-links-alert"diff --git a/lib/types.ts b/lib/types.tsindex 35fc953a..d59fef27 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -29,6 +29,7 @@ export interface DocumentWithLinksAndLinkCountAndViewCount extends Document {links: number;views: number;versions: number;+ datarooms: number;};links: Link[];folder: {@@ -44,6 +45,12 @@ export interface DocumentWithVersion extends Document {name: string;path: string;};+ datarooms: {+ dataroom: {+ id: string;+ name: string;+ };+ }[];hasPageLinks: boolean;}diff --git a/pages/api/teams/[teamId]/documents/[id]/index.ts b/pages/api/teams/[teamId]/documents/[id]/index.tsindex 2d3051cd..c926b0e4 100644--- a/pages/api/teams/[teamId]/documents/[id]/index.ts+++ b/pages/api/teams/[teamId]/documents/[id]/index.ts@@ -44,6 +44,16 @@ export default async function handle(path: true,},},+ datarooms: {+ select: {+ dataroom: {+ select: {+ id: true,+ name: true,+ },+ },+ },+ },},},});diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex 77817fad..9d5a8067 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -2,27 +2,15 @@ import { NextApiRequest, NextApiResponse } from "next";import { authOptions } from "@/pages/api/auth/[...nextauth]";import { DocumentStorageType, Prisma } from "@prisma/client";-import { waitUntil } from "@vercel/functions";import { getServerSession } from "next-auth/next";-import { parsePageId } from "notion-utils";import { hashToken } from "@/lib/api/auth/token";import { processDocument } from "@/lib/api/documents/process-document";import { errorhandler } from "@/lib/errorHandler";-import notion from "@/lib/notion";import prisma from "@/lib/prisma";import { getTeamWithUsersAndDocument } from "@/lib/team/helper";-import {- convertCadToPdfTask,- convertFilesToPdfTask,-} from "@/lib/trigger/convert-files";-import { processVideo } from "@/lib/trigger/optimize-video-files";-import { convertPdfToImageRoute } from "@/lib/trigger/pdf-to-image-route";import { CustomUser } from "@/lib/types";-import { getExtension, log } from "@/lib/utils";-import { conversionQueue } from "@/lib/utils/trigger-utils";-import { sendDocumentCreatedWebhook } from "@/lib/webhook/triggers/document-created";-import { sendLinkCreatedWebhook } from "@/lib/webhook/triggers/link-created";+import { log } from "@/lib/utils";export const config = {// in order to enable `waitUntil` function@@ -138,7 +126,12 @@ export default async function handle(},}),_count: {- select: { links: true, views: true, versions: true },+ select: {+ links: true,+ views: true,+ versions: true,+ datarooms: true,+ },},},});diff --git a/pages/api/teams/[teamId]/folders/documents/[...name].ts b/pages/api/teams/[teamId]/folders/documents/[...name].tsindex 741798b3..aeeb39fd 100644--- a/pages/api/teams/[teamId]/folders/documents/[...name].ts+++ b/pages/api/teams/[teamId]/folders/documents/[...name].ts@@ -66,7 +66,12 @@ export default async function handle(},include: {_count: {- select: { links: true, views: true, versions: true },+ select: {+ links: true,+ views: true,+ versions: true,+ datarooms: true,+ },},links: {take: 1,