Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Add /documents/hidden page to view and unhide hidden documents
Cursor Agent148db50c7831
diff --git a/components/documents/hidden-document-card.tsx b/components/documents/hidden-document-card.tsxnew file mode 100644index 00000000..c689c918--- /dev/null+++ b/components/documents/hidden-document-card.tsx@@ -0,0 +1,280 @@+import Link from "next/link";++import { useEffect, useRef, useState } from "react";++import { TeamContextType } from "@/context/team-context";+import {+ EyeIcon,+ MoreVertical,+ ServerIcon,+ TrashIcon,+} from "lucide-react";+import { useTheme } from "next-themes";+import { toast } from "sonner";+import { mutate } from "swr";++import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";+import { cn, nFormatter, timeAgo } from "@/lib/utils";+import { fileIcon } from "@/lib/utils/get-file-icon";++import BarChart from "@/components/shared/icons/bar-chart";+import { Button } from "@/components/ui/button";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { Checkbox } from "@/components/ui/checkbox";+import { BadgeTooltip } from "@/components/ui/tooltip";++type HiddenDocumentCardProps = {+ document: DocumentWithLinksAndLinkCountAndViewCount;+ teamInfo: TeamContextType | null;+ isSelected?: boolean;+ onSelect?: () => void;+};++export function HiddenDocumentCard({+ document: prismaDocument,+ teamInfo,+ isSelected,+ onSelect,+}: HiddenDocumentCardProps) {+ const { theme, systemTheme } = useTheme();+ const isLight =+ theme === "light" || (theme === "system" && systemTheme === "light");++ const [isFirstClick, setIsFirstClick] = useState<boolean>(false);+ const [menuOpen, setMenuOpen] = useState<boolean>(false);+ const [isHovered, setIsHovered] = useState<boolean>(false);++ const dropdownRef = useRef<HTMLDivElement | null>(null);++ useEffect(() => {+ function handleClickOutside(event: { target: any }) {+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {+ setMenuOpen(false);+ setIsFirstClick(false);+ }+ }++ document.addEventListener("mousedown", handleClickOutside);+ return () => {+ document.removeEventListener("mousedown", handleClickOutside);+ };+ }, []);++ const handleButtonClick = (event: any, documentId: string) => {+ event.stopPropagation();+ event.preventDefault();++ if (isFirstClick) {+ handleDeleteDocument(documentId);+ setIsFirstClick(false);+ setMenuOpen(false);+ } else {+ setIsFirstClick(true);+ }+ };++ const handleDeleteDocument = async (documentId: string) => {+ if (!isFirstClick) {+ setIsFirstClick(true);+ return;+ }++ toast.promise(+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/documents/${documentId}`, {+ method: "DELETE",+ }).then(async (res) => {+ if (!res.ok) {+ const error = await res.json();+ throw new Error(error.message || "Failed to delete document");+ }+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hidden`);+ }),+ {+ loading: "Deleting document...",+ success: "Document deleted successfully.",+ error: (err) => err.message || "Failed to delete document. Try again.",+ },+ );+ };++ const handleMenuStateChange = (open: boolean) => {+ if (isSelected) return;++ if (isFirstClick) {+ setMenuOpen(true);+ return;+ }++ if (!open) {+ setIsFirstClick(false);+ setMenuOpen(false);+ } else {+ setMenuOpen(true);+ }+ };++ const handleUnhideDocument = async (event: any) => {+ event.stopPropagation();+ event.preventDefault();++ toast.promise(+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hide`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ documentIds: [prismaDocument.id],+ hidden: false,+ }),+ }).then(async (res) => {+ if (!res.ok) {+ const error = await res.json();+ throw new Error(error.message || "Failed to unhide document");+ }+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hidden`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders?root=true`);+ setMenuOpen(false);+ }),+ {+ loading: "Unhiding document...",+ success: "Document is now visible in All Documents.",+ error: (err) =>+ err.message || "Failed to unhide document. Try again.",+ },+ );+ };++ return (+ <div+ className={cn(+ "group/row relative flex items-center justify-between gap-x-2 rounded-lg border-0 bg-white p-3 ring-1 ring-gray-200 transition-all hover:bg-secondary hover:ring-gray-300 dark:bg-secondary dark:ring-gray-700 hover:dark:ring-gray-500 sm:p-4",+ isHovered && "bg-secondary ring-gray-300 dark:ring-gray-500",+ isSelected && "ring-2 ring-primary",+ )}+ onMouseEnter={() => setIsHovered(true)}+ onMouseLeave={() => setIsHovered(false)}+ >+ <div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">+ {isSelected || isHovered ? (+ <div+ className="mx-0.5 flex w-8 items-center justify-center sm:mx-1"+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ onSelect?.();+ }}+ >+ <Checkbox+ checked={isSelected}+ className="h-5 w-5"+ aria-label={isSelected ? "Deselect document" : "Select document"}+ />+ </div>+ ) : (+ <div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">+ {fileIcon({+ fileType: prismaDocument.type ?? "",+ className: "h-8 w-8",+ isLight,+ })}+ </div>+ )}++ <div className="flex-col">+ <div className="flex items-center">+ <h2 className="min-w-0 max-w-[250px] truncate text-sm font-semibold leading-6 text-foreground sm:max-w-md">+ <Link+ href={`/documents/${prismaDocument.id}`}+ className="w-full truncate"+ >+ <span>{prismaDocument.name}</span>+ <span className="absolute inset-0" />+ </Link>+ </h2>+ {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>+ <p>•</p>+ <p className="truncate">+ {prismaDocument._count.links}{" "}+ {prismaDocument._count.links === 1 ? "Link" : "Links"}+ </p>+ {prismaDocument._count.versions > 1 ? (+ <>+ <p>•</p>+ <p className="truncate">{`${prismaDocument._count.versions} Versions`}</p>+ </>+ ) : null}+ </div>+ </div>+ </div>++ <div className="flex flex-row space-x-2">+ <Link+ onClick={(e) => {+ e.stopPropagation();+ }}+ href={`/documents/${prismaDocument.id}`}+ className="z-20 flex items-center space-x-1 rounded-md bg-gray-200 px-1.5 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100 dark:bg-gray-700 sm:px-2"+ >+ <BarChart className="h-3 w-3 text-muted-foreground sm:h-4 sm:w-4" />+ <p className="whitespace-nowrap text-xs text-muted-foreground sm:text-sm">+ {nFormatter(prismaDocument._count.views)}+ <span className="ml-1 hidden sm:inline-block">views</span>+ </p>+ </Link>++ <DropdownMenu open={menuOpen} onOpenChange={handleMenuStateChange}>+ <DropdownMenuTrigger asChild>+ <Button+ variant="outline"+ className="z-20 h-8 w-8 border-gray-200 bg-transparent p-0 hover:bg-gray-200 dark:border-gray-700 hover:dark:bg-gray-700 lg:h-9 lg:w-9"+ >+ <span className="sr-only">Open menu</span>+ <MoreVertical className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" ref={dropdownRef}>+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuItem onClick={handleUnhideDocument}>+ <EyeIcon className="mr-2 h-4 w-4" />+ Show in All Documents+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ onClick={(event) => handleButtonClick(event, prismaDocument.id)}+ className="text-destructive duration-200 focus:bg-destructive focus:text-destructive-foreground"+ >+ {isFirstClick ? (+ "Really delete?"+ ) : (+ <>+ <TrashIcon className="mr-2 h-4 w-4" /> Delete document+ </>+ )}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ </div>+ );+}diff --git a/components/documents/hidden-documents-list.tsx b/components/documents/hidden-documents-list.tsxnew file mode 100644index 00000000..eb7ab621--- /dev/null+++ b/components/documents/hidden-documents-list.tsx@@ -0,0 +1,381 @@+import { memo, useCallback, useMemo, useState } from "react";+import React from "react";++import { TeamContextType } from "@/context/team-context";+import {+ EyeIcon,+ FileIcon,+ FolderIcon,+ Trash2Icon,+ XIcon,+} from "lucide-react";+import { toast } from "sonner";+import { mutate } from "swr";++import { FolderWithCount } from "@/lib/swr/use-documents";+import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";++import { Skeleton } from "@/components/ui/skeleton";++import { Button } from "../ui/button";+import { Checkbox } from "../ui/checkbox";+import { Portal } from "../ui/portal";+import { ButtonTooltip } from "../ui/tooltip";+import { useDeleteDocumentsAndFoldersModal } from "./actions/delete-documents-modal";+import { useDeleteFolderModal } from "./actions/delete-folder-modal";+import { HiddenDocumentCard } from "./hidden-document-card";+import { HiddenFolderCard } from "./hidden-folder-card";++export function HiddenDocumentsList({+ folders,+ documents,+ teamInfo,+ loading,+ foldersLoading,+}: {+ folders: FolderWithCount[] | undefined;+ documents: DocumentWithLinksAndLinkCountAndViewCount[] | undefined;+ teamInfo: TeamContextType | null;+ loading: boolean;+ foldersLoading: boolean;+}) {+ const [selectedDocuments, setSelectedDocuments] = useState<string[]>([]);+ const [selectedFolders, setSelectedFolders] = useState<string[]>([]);+ const [isUnhiding, setIsUnhiding] = useState(false);++ const { setDeleteModalOpen, setFolderToDelete, DeleteFolderModal } =+ useDeleteFolderModal(teamInfo);++ const handleDeleteFolder = useCallback(+ (folderId: string) => {+ const folderToDelete = folders?.find((f) => f.id === folderId);+ if (folderToDelete) {+ setFolderToDelete(folderToDelete);+ setDeleteModalOpen(true);+ setSelectedFolders((prev) => prev.filter((id) => id !== folderId));+ }+ },+ [folders, setFolderToDelete, setDeleteModalOpen, setSelectedFolders],+ );++ const { setShowDeleteItemsModal, DeleteItemsModal } =+ useDeleteDocumentsAndFoldersModal({+ documentIds: selectedDocuments,+ setSelectedDocuments,+ folderIds: selectedFolders,+ setSelectedFolder: setSelectedFolders,+ });++ const totalSelectedItem = [...selectedDocuments, ...selectedFolders].length;++ const selectedDocumentsLength = useMemo(+ () => selectedDocuments && selectedDocuments.length,+ [selectedDocuments],+ );++ const selectedFoldersLength = useMemo(+ () => selectedFolders && selectedFolders.length,+ [selectedFolders],+ );++ const handleSelect = useCallback(+ (id: string, type: "document" | "folder") => {+ if (type === "folder") {+ setSelectedFolders((prev) =>+ prev.includes(id)+ ? prev.filter((docId) => docId !== id)+ : [...prev, id],+ );+ } else {+ setSelectedDocuments((prev) =>+ prev.includes(id)+ ? prev.filter((docId) => docId !== id)+ : [...prev, id],+ );+ }+ },+ [],+ );++ const resetSelection = () => {+ setSelectedDocuments([]);+ setSelectedFolders([]);+ };++ const handleBulkUnhide = useCallback(async () => {+ if (selectedDocuments.length === 0 && selectedFolders.length === 0) return;++ setIsUnhiding(true);++ try {+ const promises: Promise<Response>[] = [];++ // Unhide documents+ if (selectedDocuments.length > 0) {+ promises.push(+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hide`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ documentIds: selectedDocuments,+ hidden: false,+ }),+ }),+ );+ }++ // Unhide folders (cascades to children)+ if (selectedFolders.length > 0) {+ promises.push(+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/folders/hide`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ folderIds: selectedFolders,+ hidden: false,+ }),+ }),+ );+ }++ const results = await Promise.all(promises);++ // Check for errors+ for (const res of results) {+ if (!res.ok) {+ const error = await res.json();+ throw new Error(error.message || "Failed to unhide items");+ }+ }++ // Revalidate data+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders?root=true`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hidden`);++ // Reset selection+ setSelectedDocuments([]);+ setSelectedFolders([]);++ toast.success(+ `Successfully unhidden ${selectedDocuments.length > 0 ? `${selectedDocuments.length} document${selectedDocuments.length > 1 ? "s" : ""}` : ""}${selectedDocuments.length > 0 && selectedFolders.length > 0 ? " and " : ""}${selectedFolders.length > 0 ? `${selectedFolders.length} folder${selectedFolders.length > 1 ? "s" : ""}` : ""}`,+ );+ } catch (error) {+ toast.error(+ error instanceof Error ? error.message : "Failed to unhide items",+ );+ } finally {+ setIsUnhiding(false);+ }+ }, [selectedDocuments, selectedFolders, teamInfo?.currentTeam?.id]);++ const HeaderContent = memo(() => {+ if (selectedDocumentsLength > 0 || selectedFoldersLength > 0) {+ const totalItems = (documents?.length || 0) + (folders?.length || 0);+ const isAllSelected = totalItems === totalSelectedItem;++ const handleSelectAll = () => {+ if (isAllSelected) {+ setSelectedDocuments([]);+ setSelectedFolders([]);+ } else {+ const allDocumentIds = documents?.map((doc) => doc.id) || [];+ const allFolderIds = folders?.map((folder) => folder.id) || [];+ setSelectedDocuments(allDocumentIds);+ setSelectedFolders(allFolderIds);+ }+ };++ return (+ <div className="mb-2 flex items-center gap-x-1 rounded-3xl bg-gray-100 text-sm text-foreground dark:bg-gray-800">+ <div className="ml-5 flex h-8 w-8 items-center justify-center rounded-full hover:bg-gray-200 hover:dark:bg-gray-700">+ <ButtonTooltip+ content={isAllSelected ? "Deselect all" : "Select all"}+ >+ <Checkbox+ id="select-all"+ checked={isAllSelected}+ onCheckedChange={handleSelectAll}+ className="h-5 w-5"+ aria-label={isAllSelected ? "Deselect all" : "Select all"}+ />+ </ButtonTooltip>+ </div>+ <ButtonTooltip content="Clear selection">+ <Button+ onClick={resetSelection}+ className="mx-1.5 my-1 size-8 rounded-full hover:bg-gray-200 hover:dark:bg-gray-700"+ variant="ghost"+ size="icon"+ >+ <XIcon className="h-5 w-5" />+ </Button>+ </ButtonTooltip>+ {selectedDocumentsLength ? (+ <div className="mr-2 tabular-nums">+ {selectedDocumentsLength} document+ {selectedDocumentsLength > 1 ? "s" : ""} selected+ </div>+ ) : null}+ {selectedFoldersLength ? (+ <div className="mr-2 tabular-nums">+ {selectedFoldersLength} folder+ {selectedFoldersLength > 1 ? "s" : ""} selected+ </div>+ ) : null}+ <ButtonTooltip content="Unhide (Show in All Documents)">+ <Button+ onClick={handleBulkUnhide}+ disabled={isUnhiding}+ className="mx-1.5 my-1 size-8 rounded-full hover:bg-gray-200 hover:dark:bg-gray-700"+ variant="ghost"+ size="icon"+ >+ <EyeIcon className="h-5 w-5" />+ </Button>+ </ButtonTooltip>+ <ButtonTooltip content="Delete">+ <Button+ onClick={() => setShowDeleteItemsModal(true)}+ className="mx-1.5 my-1 size-8 rounded-full hover:bg-destructive hover:text-destructive-foreground"+ variant="ghost"+ size="icon"+ >+ <Trash2Icon className="h-5 w-5" />+ </Button>+ </ButtonTooltip>+ </div>+ );+ } else {+ return (+ <div className="mb-2 flex items-center gap-x-2 pt-5">+ {folders && folders.length > 0 && (+ <p className="flex items-center gap-x-1 text-sm text-gray-400">+ <FolderIcon className="h-5 w-5" />+ <span>+ {folders.length} folder{folders.length > 1 ? "s" : ""}+ </span>+ </p>+ )}+ {documents && documents.length > 0 && (+ <p className="flex items-center gap-x-1 text-sm text-gray-400">+ <FileIcon className="h-5 w-5" />+ <span>+ {documents.length} document{documents.length > 1 ? "s" : ""}+ </span>+ </p>+ )}+ </div>+ );+ }+ });+ HeaderContent.displayName = "HeaderContent";++ const isEmpty =+ !loading &&+ !foldersLoading &&+ (!documents || documents.length === 0) &&+ (!folders || folders.length === 0);++ return (+ <>+ <div className="space-y-4">+ {/* Folders list */}+ <ul role="list" className="space-y-4">+ {folders && !foldersLoading+ ? folders.map((folder) => {+ const isSelected = selectedFolders.includes(folder.id);+ return (+ <li key={folder.id}>+ <HiddenFolderCard+ folder={folder}+ teamInfo={teamInfo}+ isSelected={isSelected}+ onSelect={() => handleSelect(folder.id, "folder")}+ onDelete={handleDeleteFolder}+ />+ </li>+ );+ })+ : foldersLoading &&+ Array.from({ length: 2 }).map((_, i) => (+ <li+ key={i}+ className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 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="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"+ />+ </li>+ ))}+ </ul>++ {/* Documents list */}+ <ul role="list" className="space-y-4">+ {documents && !loading+ ? documents.map((document) => {+ const isSelected = selectedDocuments.includes(document.id);+ return (+ <li key={document.id}>+ <HiddenDocumentCard+ document={document}+ teamInfo={teamInfo}+ isSelected={isSelected}+ onSelect={() => handleSelect(document.id, "document")}+ />+ </li>+ );+ })+ : loading &&+ Array.from({ length: 3 }).map((_, i) => (+ <li+ key={i}+ className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 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="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"+ />+ </li>+ ))}+ </ul>++ <Portal containerId={"documents-header-count"}>+ <HeaderContent />+ </Portal>++ {isEmpty && (+ <div className="flex flex-col items-center justify-center py-12">+ <EyeIcon className="mb-4 h-12 w-12 text-gray-400" strokeWidth={1} />+ <h3 className="mb-2 text-lg font-medium text-gray-900 dark:text-gray-100">+ No hidden documents or folders+ </h3>+ <p className="text-sm text-muted-foreground">+ Documents and folders you hide from All Documents will appear+ here.+ </p>+ </div>+ )}+ </div>++ <DeleteFolderModal />+ <DeleteItemsModal />+ </>+ );+}diff --git a/components/documents/hidden-folder-card.tsx b/components/documents/hidden-folder-card.tsxnew file mode 100644index 00000000..294044fd--- /dev/null+++ b/components/documents/hidden-folder-card.tsx@@ -0,0 +1,173 @@+import { useRouter } from "next/router";++import { useState } from "react";++import { TeamContextType } from "@/context/team-context";+import {+ EyeIcon,+ FolderIcon,+ MoreVertical,+ TrashIcon,+} from "lucide-react";+import { toast } from "sonner";+import { mutate } from "swr";++import { FolderWithCount } from "@/lib/swr/use-documents";+import { timeAgo } from "@/lib/utils";++import { Button } from "@/components/ui/button";+import { Checkbox } from "@/components/ui/checkbox";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";++type HiddenFolderCardProps = {+ folder: FolderWithCount;+ teamInfo: TeamContextType | null;+ isSelected?: boolean;+ onSelect?: () => void;+ onDelete?: (folderId: string) => void;+};++export function HiddenFolderCard({+ folder,+ teamInfo,+ isSelected,+ onSelect,+ onDelete,+}: HiddenFolderCardProps) {+ const router = useRouter();+ const [menuOpen, setMenuOpen] = useState<boolean>(false);+ const [isHovered, setIsHovered] = useState<boolean>(false);++ const folderPath = `/documents/tree${folder.path}`;++ const handleCardClick = (e: React.MouseEvent) => {+ router.push(folderPath);+ };++ const handleUnhideFolder = async (e: React.MouseEvent) => {+ e.preventDefault();+ e.stopPropagation();++ toast.promise(+ fetch(`/api/teams/${teamInfo?.currentTeam?.id}/folders/hide`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ folderIds: [folder.id],+ hidden: false,+ }),+ }).then(async (res) => {+ if (!res.ok) {+ const error = await res.json();+ throw new Error(error.message || "Failed to unhide folder");+ }+ // Revalidate the folders and documents+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders?root=true`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/folders`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents`);+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/documents/hidden`);+ setMenuOpen(false);+ }),+ {+ loading: "Unhiding folder...",+ success: "Folder is now visible in All Documents.",+ error: (err) => err.message || "Failed to unhide folder. Try again.",+ },+ );+ };++ return (+ <div+ onClick={handleCardClick}+ onMouseEnter={() => setIsHovered(true)}+ onMouseLeave={() => setIsHovered(false)}+ className={`group/row relative flex cursor-pointer items-center justify-between rounded-lg border-0 bg-white p-3 ring-1 ring-gray-400 transition-all hover:bg-secondary hover:ring-gray-500 dark:bg-secondary dark:ring-gray-500 hover:dark:ring-gray-400 sm:p-4 ${isSelected ? "ring-2 ring-primary" : ""}`}+ >+ <div className="flex min-w-0 shrink items-center space-x-2 sm:space-x-4">+ {isSelected || isHovered ? (+ <div+ className="mx-0.5 flex w-8 items-center justify-center sm:mx-1"+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ onSelect?.();+ }}+ >+ <Checkbox+ checked={isSelected}+ className="h-5 w-5"+ aria-label={isSelected ? "Deselect folder" : "Select folder"}+ />+ </div>+ ) : (+ <div className="mx-0.5 flex w-8 items-center justify-center text-center sm:mx-1">+ <FolderIcon className="h-8 w-8" strokeWidth={1} />+ </div>+ )}++ <div className="flex-col">+ <div className="flex items-center">+ <h2 className="min-w-0 max-w-[150px] truncate text-sm font-semibold leading-6 text-foreground sm:max-w-md">+ {folder.name}+ </h2>+ </div>+ <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-muted-foreground">+ <p className="truncate">{timeAgo(folder.createdAt)}</p>+ <p>•</p>+ <p className="truncate">+ {folder._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">+ <DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>+ <DropdownMenuTrigger asChild>+ <Button+ variant="outline"+ className="z-10 h-8 w-8 border-gray-200 bg-transparent p-0 hover:bg-gray-200 dark:border-gray-700 hover:dark:bg-gray-700 lg:h-9 lg:w-9"+ >+ <span className="sr-only">Open menu</span>+ <MoreVertical className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="w-64">+ <DropdownMenuLabel>Actions</DropdownMenuLabel>+ <DropdownMenuItem onClick={handleUnhideFolder}>+ <EyeIcon className="mr-2 h-4 w-4" />+ Show in All Documents+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ onClick={(event) => {+ event.preventDefault();+ event.stopPropagation();+ onDelete?.(folder.id);+ setMenuOpen(false);+ }}+ className="text-destructive duration-200 focus:bg-destructive focus:text-destructive-foreground"+ >+ <TrashIcon className="mr-2 h-4 w-4" /> Delete Folder+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ </div>+ );+}diff --git a/lib/swr/use-documents.ts b/lib/swr/use-documents.tsindex 69606949..8588cf62 100644--- a/lib/swr/use-documents.ts+++ b/lib/swr/use-documents.ts@@ -160,3 +160,28 @@ export function useRootFolders() {error,};}++export function useHiddenDocuments() {+ const teamInfo = useTeam();++ const { data, error, mutate } = useSWR<{+ folders: FolderWithCount[];+ documents: DocumentWithLinksAndLinkCountAndViewCount[];+ }>(+ teamInfo?.currentTeam?.id &&+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/hidden`,+ fetcher,+ {+ revalidateOnFocus: false,+ dedupingInterval: 30000,+ },+ );++ return {+ folders: data?.folders,+ documents: data?.documents,+ loading: !data && !error,+ error,+ mutate,+ };+}diff --git a/pages/api/teams/[teamId]/documents/hidden/index.ts b/pages/api/teams/[teamId]/documents/hidden/index.tsnew file mode 100644index 00000000..6d31ba49--- /dev/null+++ b/pages/api/teams/[teamId]/documents/hidden/index.ts@@ -0,0 +1,170 @@+import { NextApiRequest, NextApiResponse } from "next";++import { authOptions } from "@/pages/api/auth/[...nextauth]";+import { getServerSession } from "next-auth/next";++import { errorhandler } from "@/lib/errorHandler";+import prisma from "@/lib/prisma";+import { CustomUser } from "@/lib/types";++export default async function handle(+ req: NextApiRequest,+ res: NextApiResponse,+) {+ if (req.method === "GET") {+ // GET /api/teams/:teamId/documents/hidden+ const session = await getServerSession(req, res, authOptions);+ if (!session) {+ return res.status(401).end("Unauthorized");+ }++ const { teamId } = req.query as { teamId: string };+ const userId = (session.user as CustomUser).id;++ try {+ const teamAccess = await prisma.userTeam.findUnique({+ where: {+ userId_teamId: {+ userId: userId,+ teamId: teamId,+ },+ },+ });++ if (!teamAccess) {+ return res.status(401).end("Unauthorized");+ }++ // Fetch root-level hidden folders (folders whose parent is not hidden)+ // This prevents showing nested hidden folders whose parents are already shown+ const hiddenFolders = await prisma.folder.findMany({+ where: {+ teamId: teamId,+ hiddenInAllDocuments: true,+ // Only show root-level hidden folders (parent is null or parent is not hidden)+ OR: [+ { parentId: null },+ {+ parentFolder: {+ hiddenInAllDocuments: false,+ },+ },+ ],+ },+ include: {+ _count: {+ select: {+ documents: true,+ childFolders: true,+ },+ },+ },+ orderBy: {+ createdAt: "desc",+ },+ });++ // Fetch root-level hidden documents (documents not in a hidden folder)+ // Only show documents that are directly hidden, not documents in hidden folders+ const hiddenDocuments = await prisma.document.findMany({+ where: {+ teamId: teamId,+ hiddenInAllDocuments: true,+ // Only show documents that are either:+ // 1. In no folder (root level)+ // 2. In a folder that is NOT hidden (document was individually hidden)+ OR: [+ { folderId: null },+ {+ folder: {+ hiddenInAllDocuments: false,+ },+ },+ ],+ },+ include: {+ folder: {+ select: {+ name: true,+ path: true,+ },+ },+ },+ orderBy: {+ createdAt: "desc",+ },+ });++ // Get counts for documents+ const documentIds = hiddenDocuments.map((d) => d.id);++ const [linkCounts, viewCounts, versionCounts, dataroomCounts] =+ await Promise.all([+ prisma.link.groupBy({+ by: ["documentId"],+ where: {+ documentId: { in: documentIds },+ deletedAt: null,+ },+ _count: { id: true },+ }),+ prisma.view.groupBy({+ by: ["documentId"],+ where: {+ documentId: { in: documentIds },+ },+ _count: { id: true },+ }),+ prisma.documentVersion.groupBy({+ by: ["documentId"],+ where: {+ documentId: { in: documentIds },+ },+ _count: { id: true },+ }),+ prisma.dataroomDocument.groupBy({+ by: ["documentId"],+ where: {+ documentId: { in: documentIds },+ },+ _count: { id: true },+ }),+ ]);++ // Create lookup maps for counts+ const linkCountMap = new Map(+ linkCounts.map((lc) => [lc.documentId, lc._count.id]),+ );+ const viewCountMap = new Map(+ viewCounts.map((vc) => [vc.documentId, vc._count.id]),+ );+ const versionCountMap = new Map(+ versionCounts.map((vsc) => [vsc.documentId, vsc._count.id]),+ );+ const dataroomCountMap = new Map(+ dataroomCounts.map((dc) => [dc.documentId, dc._count.id]),+ );++ // Combine documents with their counts+ const documentsWithCounts = hiddenDocuments.map((document) => ({+ ...document,+ _count: {+ links: linkCountMap.get(document.id) || 0,+ views: viewCountMap.get(document.id) || 0,+ versions: versionCountMap.get(document.id) || 0,+ datarooms: dataroomCountMap.get(document.id) || 0,+ },+ }));++ return res.status(200).json({+ folders: hiddenFolders,+ documents: documentsWithCounts,+ });+ } catch (error) {+ errorhandler(error, res);+ }+ } else {+ res.setHeader("Allow", ["GET"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+}diff --git a/pages/documents/hidden.tsx b/pages/documents/hidden.tsxnew file mode 100644index 00000000..3eca1d71--- /dev/null+++ b/pages/documents/hidden.tsx@@ -0,0 +1,56 @@+import Link from "next/link";++import { useTeam } from "@/context/team-context";+import { ArrowLeftIcon, EyeOffIcon } from "lucide-react";++import { useHiddenDocuments } from "@/lib/swr/use-documents";++import { HiddenDocumentsList } from "@/components/documents/hidden-documents-list";+import AppLayout from "@/components/layouts/app";+import { Button } from "@/components/ui/button";+import { Separator } from "@/components/ui/separator";++export default function HiddenDocumentsPage() {+ const teamInfo = useTeam();+ const { folders, documents, loading } = useHiddenDocuments();++ return (+ <AppLayout>+ <div className="sticky top-0 mb-4 min-h-[calc(100vh-72px)] rounded-lg bg-white p-4 dark:bg-gray-900 sm:mx-4 sm:pt-8">+ <section className="mb-4 flex items-center justify-between space-x-2 sm:space-x-0">+ <div className="space-y-0 sm:space-y-1">+ <div className="flex items-center gap-x-2">+ <Link href="/documents">+ <Button variant="ghost" size="icon" className="h-8 w-8">+ <ArrowLeftIcon className="h-4 w-4" />+ </Button>+ </Link>+ <div className="flex items-center gap-x-2">+ <EyeOffIcon className="h-6 w-6 text-muted-foreground" />+ <h2 className="text-xl font-semibold tracking-tight text-foreground sm:text-2xl">+ Hidden Documents+ </h2>+ </div>+ </div>+ <p className="ml-10 text-xs leading-4 text-muted-foreground sm:text-sm sm:leading-none">+ Documents and folders hidden from All Documents. You can unhide+ them to show them again.+ </p>+ </div>+ </section>++ <section id="documents-header-count" />++ <Separator className="mb-5 bg-gray-200 dark:bg-gray-800" />++ <HiddenDocumentsList+ documents={documents}+ folders={folders}+ teamInfo={teamInfo}+ loading={loading}+ foldersLoading={loading}+ />+ </div>+ </AppLayout>+ );+}diff --git a/pages/documents/index.tsx b/pages/documents/index.tsxindex ee4852f6..2cc8047e 100644--- a/pages/documents/index.tsx+++ b/pages/documents/index.tsx@@ -1,7 +1,9 @@import { useRouter } from "next/router";+import Link from "next/link";+import { useTeam } from "@/context/team-context";-import { FolderPlusIcon, PlusIcon } from "lucide-react";+import { EyeOffIcon, FolderPlusIcon, PlusIcon } from "lucide-react";import useDocuments, { useRootFolders } from "@/lib/swr/use-documents";import { handleInvitationStatus } from "@/lib/utils";@@ -91,6 +93,16 @@ export default function Documents() {<SearchBoxPersisted loading={isValidating} inputClassName="h-10" /></div><SortButton />+ <Link href="/documents/hidden">+ <Button+ variant="outline"+ size="icon"+ className="border-gray-500 bg-gray-50 hover:bg-gray-200 dark:bg-black hover:dark:bg-muted"+ title="View hidden documents"+ >+ <EyeOffIcon className="h-5 w-5 shrink-0" aria-hidden="true" />+ </Button>+ </Link></div><section id="documents-header-count" />