Skip to content

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

ui: enable 'Generate Index File' in dataroom view

Ashish Viradiya97e400a07834
diff --git a/components/links/link-sheet/index-file-section.tsx b/components/links/link-sheet/index-file-section.tsx
new file mode 100644
index 00000000..e006cab2
--- /dev/null
+++ b/components/links/link-sheet/index-file-section.tsx
@@ -0,0 +1,37 @@
+import { useEffect, useState } from "react";
+
+import { DEFAULT_LINK_TYPE } from ".";
+import LinkItem from "./link-item";
+
+export default function IndexFileSection({
+ data,
+ setData,
+}: {
+ data: DEFAULT_LINK_TYPE;
+ setData: React.Dispatch<React.SetStateAction<DEFAULT_LINK_TYPE>>;
+}) {
+ const { enableIndexFile } = data;
+ const [enabled, setEnabled] = useState<boolean>(false);
+
+ useEffect(() => {
+ setEnabled(enableIndexFile);
+ }, [enableIndexFile]);
+
+ const handleEnableIndexFile = () => {
+ const updatedEnableIndexFile = !enabled;
+ setData({ ...data, enableIndexFile: updatedEnableIndexFile });
+ setEnabled(updatedEnableIndexFile);
+ };
+
+ return (
+ <div className="pb-5">
+ <LinkItem
+ title="Enable index file generation"
+ enabled={enabled}
+ link="https://www.papermark.com/help/article/link-settings"
+ action={handleEnableIndexFile}
+ tooltipContent="Allow visitors to generate an index file of all documents in the dataroom."
+ />
+ </div>
+ );
+}
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 587a4978..b863a940 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -86,6 +86,7 @@ export const DEFAULT_LINK_PROPS = (
isFileRequestOnly: false,
uploadFolderId: null,
uploadFolderName: "Home",
+ enableIndexFile: false,
});
export type DEFAULT_LINK_TYPE = {
@@ -124,6 +125,7 @@ export type DEFAULT_LINK_TYPE = {
isFileRequestOnly: boolean;
uploadFolderId: string | null;
uploadFolderName: string;
+ enableIndexFile: boolean;
};
export default function LinkSheet({
@@ -746,4 +748,4 @@ export default function LinkSheet({
</SheetContent>
</Sheet>
);
-}
+}
\ No newline at end of file
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index 06ff86b3..3fcc9715 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -24,6 +24,7 @@ import { ProBannerSection } from "@/components/links/link-sheet/pro-banner-secti
import AgreementSection from "./agreement-section";
import ConversationSection from "./conversation-section";
import CustomFieldsSection from "./custom-fields-section";
+import IndexFileSection from "./index-file-section";
import QuestionSection from "./question-section";
import ScreenshotProtectionSection from "./screenshot-protection-section";
import UploadSection from "./upload-section";
@@ -96,6 +97,9 @@ export const LinkOptions = ({
targetId={targetId}
/>
) : null}
+ {linkType === LinkType.DATAROOM_LINK ? (
+ <IndexFileSection {...{ data, setData }} />
+ ) : null}
<OGSection
{...{ data, setData }}
isAllowed={
@@ -230,4 +234,4 @@ export const LinkOptions = ({
/>
</div>
);
-};
+};
\ No newline at end of file
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 92a21713..0f642688 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -175,6 +175,7 @@ export default function LinksTable({
isFileRequestOnly: link.isFileRequestOnly ?? false,
uploadFolderId: link.uploadFolderId ?? null,
uploadFolderName: link.uploadFolderName ?? "Home",
+ enableIndexFile: link.enableIndexFile ?? false,
});
//wait for dropdown to close before opening the link sheet
setTimeout(() => {
@@ -743,4 +744,4 @@ export default function LinksTable({
</div>
</>
);
-}
+}
\ No newline at end of file
diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsx
index 690dc4dc..5aa8d268 100644
--- a/components/view/dataroom/dataroom-view.tsx
+++ b/components/view/dataroom/dataroom-view.tsx
@@ -266,10 +266,13 @@ export default function DataroomView({
linkId={link.id}
dataroom={dataroom}
allowDownload={link.allowDownload!}
+ enableIndexFile={link.enableIndexFile}
folderId={folderId}
setFolderId={setFolderId}
viewerId={viewData.viewerId}
viewData={viewData}
+ isEmbedded={isEmbedded}
+ viewerEmail={viewData.viewerEmail ?? data.email ?? verifiedEmail ?? userEmail ?? undefined}
/>
</div>
);
diff --git a/components/view/dataroom/index-file-dialog.tsx b/components/view/dataroom/index-file-dialog.tsx
new file mode 100644
index 00000000..a0d50ae6
--- /dev/null
+++ b/components/view/dataroom/index-file-dialog.tsx
@@ -0,0 +1,193 @@
+import { useState } from "react";
+
+import {
+ FileJson,
+ FileSlidersIcon,
+ FileSpreadsheet,
+ FileText,
+} from "lucide-react";
+import { toast } from "sonner";
+
+import { useAnalytics } from "@/lib/analytics";
+import { IndexFileFormat } from "@/lib/types/index-file";
+
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { Separator } from "@/components/ui/separator";
+import { ButtonTooltip } from "@/components/ui/tooltip";
+
+interface IndexFileDialogProps {
+ linkId: string;
+ viewId: string;
+ disabled?: boolean;
+ dataroomId: string;
+ isEmbedded?: boolean;
+ viewerEmail?: string;
+ viewerId?: string;
+ verifiedEmail?: string;
+}
+
+export default function IndexFileDialog({
+ linkId,
+ viewId,
+ disabled = false,
+ dataroomId,
+ isEmbedded,
+ viewerEmail,
+ viewerId,
+ verifiedEmail,
+}: IndexFileDialogProps) {
+ const [isLoading, setIsLoading] = useState(false);
+ const [selectedFormat, setSelectedFormat] =
+ useState<IndexFileFormat>("excel");
+ const [isOpen, setIsOpen] = useState(false);
+ const analytics = useAnalytics();
+
+ const handleGenerateIndex = async () => {
+ if (!linkId) {
+ toast.error("Something went wrong. Please try again.");
+ return;
+ }
+
+ try {
+ setIsLoading(true);
+
+ const response = await fetch(`/api/links/generate-index`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ linkId,
+ format: selectedFormat,
+ dataroomId,
+ }),
+ });
+
+ if (!response.ok) {
+ const errorData = await response.json();
+ throw new Error(errorData.error || "Failed to generate index");
+ }
+ analytics.identify(viewerEmail);
+ analytics.capture("Index File Downloaded By Viewer", {
+ linkId: linkId,
+ dataroomId: dataroomId,
+ linkType: "dataroom",
+ viewerId: viewerId,
+ viewerEmail: viewerEmail,
+ isEmbedded,
+ format: selectedFormat,
+ viewId: viewId,
+ });
+
+ // Get filename from Content-Disposition header
+ const contentDisposition = response.headers.get("Content-Disposition");
+ const filename = contentDisposition?.split("filename=")[1] || "index";
+
+ // Create a blob from the response
+ const blob = await response.blob();
+
+ // Create a download link and trigger it
+ const url = window.URL.createObjectURL(blob);
+ const link = document.createElement("a");
+ link.href = url;
+ link.download = filename;
+ link.rel = "noopener noreferrer";
+ document.body.appendChild(link);
+ link.click();
+
+ setTimeout(() => {
+ window.URL.revokeObjectURL(url);
+ document.body.removeChild(link);
+ }, 100);
+
+ toast.success("Index file generated successfully");
+ setIsOpen(false);
+ } catch (error) {
+ console.error("Error generating index:", error);
+ toast.error(
+ error instanceof Error ? error.message : "Failed to generate index",
+ );
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ return (
+ <Dialog open={isOpen} onOpenChange={setIsOpen}>
+ <ButtonTooltip content="Generate Index File">
+ <DialogTrigger asChild>
+ <Button
+ className="m-1 bg-gray-900 text-white hover:bg-gray-900/80"
+ size="icon"
+ loading={isLoading}
+ disabled={disabled}
+ type="button"
+ >
+ <FileSlidersIcon className="h-5 w-5" />
+ </Button>
+ </DialogTrigger>
+ </ButtonTooltip>
+ <DialogContent className="sm:max-w-md">
+ <DialogHeader>
+ <DialogTitle>Generate Dataroom Index File</DialogTitle>
+ <DialogDescription>
+ Select a format to generate the index file.
+ </DialogDescription>
+ </DialogHeader>
+ <div className="grid gap-4 py-4">
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Select Format</h4>
+ <div className="grid grid-cols-2 gap-2">
+ <Button
+ variant={selectedFormat === "excel" ? "default" : "outline"}
+ onClick={() => {
+ setSelectedFormat("excel");
+ }}
+ className="justify-start"
+ size="sm"
+ >
+ <FileSpreadsheet className="mr-2 h-4 w-4" />
+ Excel
+ </Button>
+ <Button
+ variant={selectedFormat === "csv" ? "default" : "outline"}
+ onClick={() => setSelectedFormat("csv")}
+ className="justify-start"
+ size="sm"
+ >
+ <FileText className="mr-2 h-4 w-4" />
+ CSV
+ </Button>
+ <Button
+ variant={selectedFormat === "json" ? "default" : "outline"}
+ onClick={() => setSelectedFormat("json")}
+ className="justify-start"
+ size="sm"
+ >
+ <FileJson className="mr-2 h-4 w-4" />
+ JSON
+ </Button>
+ </div>
+ </div>
+ </div>
+ <DialogFooter>
+ <Button
+ onClick={handleGenerateIndex}
+ disabled={isLoading || disabled}
+ >
+ {isLoading ? "Generating..." : "Generate"}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/components/view/dataroom/nav-dataroom.tsx b/components/view/dataroom/nav-dataroom.tsx
index c1988fa9..b728f297 100644
--- a/components/view/dataroom/nav-dataroom.tsx
+++ b/components/view/dataroom/nav-dataroom.tsx
@@ -17,6 +17,7 @@ import { TooltipProvider } from "@/components/ui/tooltip";
import { Button } from "../../ui/button";
import { ConversationSidebar } from "../conversations/sidebar";
+import IndexFileDialog from "./index-file-dialog";
export default function DataroomNav({
allowDownload,
@@ -28,6 +29,9 @@ export default function DataroomNav({
dataroomId,
viewerId,
conversationsEnabled,
+ enableIndexFile,
+ isEmbedded,
+ viewerEmail,
}: {
allowDownload?: boolean;
brand?: Partial<DataroomBrand>;
@@ -38,6 +42,9 @@ export default function DataroomNav({
dataroomId?: string;
viewerId?: string;
conversationsEnabled?: boolean;
+ enableIndexFile?: boolean;
+ isEmbedded?: boolean;
+ viewerEmail?: string;
}) {
const [loading, setLoading] = useState<boolean>(false);
const [showConversations, setShowConversations] = useState<boolean>(false);
@@ -165,7 +172,17 @@ export default function DataroomNav({
</Tooltip>
</TooltipProvider>
)}
-
+ {enableIndexFile && (
+ <IndexFileDialog
+ linkId={linkId!}
+ viewId={viewId!}
+ disabled={isPreview}
+ dataroomId={dataroomId!}
+ isEmbedded={isEmbedded}
+ viewerEmail={viewerEmail}
+ viewerId={viewerId}
+ />
+ )}
{allowDownload ? (
<Button
onClick={downloadDataroom}
@@ -218,4 +235,4 @@ export default function DataroomNav({
) : null}
</nav>
);
-}
+};
\ No newline at end of file
diff --git a/components/view/viewer/dataroom-viewer.tsx b/components/view/viewer/dataroom-viewer.tsx
index 6d334b5c..fc344e01 100644
--- a/components/view/viewer/dataroom-viewer.tsx
+++ b/components/view/viewer/dataroom-viewer.tsx
@@ -85,6 +85,9 @@ export default function DataroomViewer({
accessControls,
viewerId,
viewData,
+ enableIndexFile,
+ isEmbedded,
+ viewerEmail,
}: {
brand: Partial<DataroomBrand>;
viewId?: string;
@@ -97,6 +100,9 @@ export default function DataroomViewer({
accessControls: ViewerGroupAccessControls[];
viewerId?: string;
viewData: DEFAULT_DATAROOM_VIEW_TYPE;
+ enableIndexFile?: boolean;
+ isEmbedded?: boolean;
+ viewerEmail?: string;
}) {
const { documents, folders } = dataroom as {
documents: DataroomDocument[];
@@ -182,6 +188,9 @@ export default function DataroomViewer({
dataroomId={dataroom?.id}
viewerId={viewerId}
conversationsEnabled={viewData.conversationsEnabled}
+ enableIndexFile={enableIndexFile}
+ isEmbedded={isEmbedded}
+ viewerEmail={viewerEmail}
/>
<div
style={{ height: "calc(100vh - 64px)" }}
diff --git a/lib/types.ts b/lib/types.ts
index d59fef27..c7f47cd5 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -148,6 +148,7 @@ export interface LinkWithDataroom extends Link {
};
agreement: Agreement | null;
customFields: CustomField[];
+ enableIndexFile: boolean;
}
export interface Geo {
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 82e3d253..74ce850f 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -40,6 +40,7 @@ export default async function handle(
enableScreenshotProtection: true,
password: true,
isArchived: true,
+ enableIndexFile: true,
enableCustomMetatag: true,
metaTitle: true,
metaDescription: true,
@@ -158,6 +159,7 @@ export default async function handle(
password,
expiresAt,
teamId,
+ enableIndexFile,
...linkDomainData
} = req.body;
@@ -270,6 +272,7 @@ export default async function handle(
domainId: domainObj?.id || null,
domainSlug: domain || null,
slug: slug || null,
+ enableIndexFile: enableIndexFile,
enableNotification: linkData.enableNotification,
enableFeedback: linkData.enableFeedback,
enableScreenshotProtection: linkData.enableScreenshotProtection,
@@ -401,6 +404,6 @@ export default async function handle(
}
// We only allow GET and PUT requests
- res.setHeader("Allow", ["GET", "PUT"]);
+ res.setHeader("Allow", ["GET", "PUT", "DELETE"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index b6a09215..629fd148 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -37,6 +37,7 @@ export default async function handler(
password,
expiresAt,
teamId,
+ enableIndexFile,
...linkDomainData
} = req.body;
@@ -148,6 +149,7 @@ export default async function handler(
denyList: linkData.denyList,
enableConversation: linkData.enableConversation,
audienceType: linkData.audienceType,
+ enableIndexFile: enableIndexFile,
groupId:
linkData.audienceType === LinkAudienceType.GROUP
? linkData.groupId
diff --git a/prisma/migrations/20250425000000_add_enable_index_file/migration.sql b/prisma/migrations/20250425000000_add_enable_index_file/migration.sql
new file mode 100644
index 00000000..4c060fbb
--- /dev/null
+++ b/prisma/migrations/20250425000000_add_enable_index_file/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Link" ADD COLUMN "enableIndexFile" BOOLEAN DEFAULT false;
\ No newline at end of file
diff --git a/prisma/schema/link.prisma b/prisma/schema/link.prisma
index e5468d90..56e9f6e6 100644
--- a/prisma/schema/link.prisma
+++ b/prisma/schema/link.prisma
@@ -65,6 +65,7 @@ model Link {
enableUpload Boolean? @default(false) // Optional give user a option to enable the upload document function
isFileRequestOnly Boolean? @default(false) // Optional give user a option to enable the file request only
uploadFolderId String? // This can be nullable, indicating upload to root folder, either document folder or dataroom folder
+ enableIndexFile Boolean? @default(false)
uploadedDocuments DocumentUpload[]