Skip to content

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

refactor: move download button to document page

Marc Seitz236d8543bab2
diff --git a/components/datarooms/actions/download-dataroom.tsx b/components/datarooms/actions/download-dataroom.tsx
new file mode 100644
index 00000000..fe8939a4
--- /dev/null
+++ b/components/datarooms/actions/download-dataroom.tsx
@@ -0,0 +1,62 @@
+import { useState } from "react";
+
+import { DownloadIcon } from "lucide-react";
+import { toast } from "sonner";
+
+import { Button } from "@/components/ui/button";
+import { ButtonTooltip } from "@/components/ui/tooltip";
+
+export default function DownloadDataroomButton({
+ teamId,
+ dataroomId,
+}: {
+ teamId: string;
+ dataroomId: string;
+}) {
+ const [isLoading, setIsLoading] = useState(false);
+
+ const downloadDataroom = async () => {
+ setIsLoading(true);
+ try {
+ toast.promise(
+ fetch(`/api/teams/${teamId}/datarooms/${dataroomId}/download/bulk`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }),
+ {
+ loading: "Downloading dataroom...",
+ success: async (response) => {
+ const { downloadUrl } = await response.json();
+ window.open(downloadUrl, "_blank");
+ return "Dataroom downloaded successfully.";
+ },
+ error: (error) => {
+ console.log(error);
+ return (
+ error.message || "An error occurred while downloading dataroom."
+ );
+ },
+ },
+ );
+ } catch (error) {
+ console.error(error);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+ return (
+ <ButtonTooltip content="Download Dataroom" sideOffset={4}>
+ <Button
+ onClick={downloadDataroom}
+ variant="outline"
+ className=""
+ size="sm"
+ loading={isLoading}
+ >
+ <DownloadIcon />
+ </Button>
+ </ButtonTooltip>
+ );
+}
diff --git a/components/datarooms/dataroom-header.tsx b/components/datarooms/dataroom-header.tsx
index 84b71d73..8d718f33 100644
--- a/components/datarooms/dataroom-header.tsx
+++ b/components/datarooms/dataroom-header.tsx
@@ -1,18 +1,10 @@
-import { useRouter } from "next/router";
-
import { useState } from "react";
-import { useTeam } from "@/context/team-context";
-import { DownloadIcon } from "lucide-react";
-import { toast } from "sonner";
-
import LinkSheet from "@/components/links/link-sheet";
import { Button } from "@/components/ui/button";
import { useDataroomLinks } from "@/lib/swr/use-dataroom";
-import { ButtonTooltip } from "../ui/tooltip";
-
export const DataroomHeader = ({
title,
description,
@@ -22,12 +14,8 @@ export const DataroomHeader = ({
description: string;
actions?: React.ReactNode[];
}) => {
- const router = useRouter();
- const dataroomId = router.query.id as string;
const [isLinkSheetOpen, setIsLinkSheetOpen] = useState<boolean>(false);
const { links } = useDataroomLinks();
- const [loading, setLoading] = useState<boolean>(false);
- const teamInfo = useTeam();
const actionRows: React.ReactNode[][] = [];
if (actions) {
@@ -36,41 +24,6 @@ export const DataroomHeader = ({
}
}
- const downloadDataroom = async () => {
- setLoading(true);
- try {
- toast.promise(
- fetch(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/download/bulk`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- ),
- {
- loading: "Downloading dataroom...",
- success: async (response) => {
- const { downloadUrl } = await response.json();
- window.open(downloadUrl, "_blank");
- return "Dataroom downloaded successfully.";
- },
- error: (error) => {
- console.log(error);
- return (
- error.message || "An error occurred while downloading dataroom."
- );
- },
- },
- );
- } catch (error) {
- console.error(error);
- } finally {
- setLoading(false);
- }
- };
-
return (
<section className="mb-4">
<div className="flex items-center justify-between">
@@ -79,17 +32,7 @@ export const DataroomHeader = ({
{title}
</h1>
</div>
- <div className="flex items-center gap-x-1">
- <ButtonTooltip content="Download Dataroom" sideOffset={4}>
- <Button
- onClick={downloadDataroom}
- className="m-1 bg-gray-900 text-white hover:bg-gray-900/80"
- size="icon"
- loading={loading}
- >
- <DownloadIcon className="h-5 w-5" />
- </Button>
- </ButtonTooltip>
+ <div>
<Button onClick={() => setIsLinkSheetOpen(true)} key={1}>
Share
</Button>
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/download/bulk.ts b/pages/api/teams/[teamId]/datarooms/[id]/download/bulk.ts
index ac95ecbd..6d962704 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/download/bulk.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/download/bulk.ts
@@ -2,13 +2,15 @@ import { NextApiRequest, NextApiResponse } from "next";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { InvocationType, InvokeCommand } from "@aws-sdk/client-lambda";
-import { ItemType, PrismaClient, ViewType } from "@prisma/client";
import { getServerSession } from "next-auth";
import { getLambdaClient } from "@/lib/files/aws-client";
+import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
-const prisma = new PrismaClient();
+export const config = {
+ maxDuration: 180,
+};
export default async function handler(
req: NextApiRequest,
diff --git a/pages/datarooms/[id]/documents/[...name].tsx b/pages/datarooms/[id]/documents/[...name].tsx
index 1ed68072..7071a263 100644
--- a/pages/datarooms/[id]/documents/[...name].tsx
+++ b/pages/datarooms/[id]/documents/[...name].tsx
@@ -5,6 +5,7 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { ArrowUpDownIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
+import DownloadDataroomButton from "@/components/datarooms/actions/download-dataroom";
import GenerateIndexButton from "@/components/datarooms/actions/generate-index-button";
import { BreadcrumbComponent } from "@/components/datarooms/dataroom-breadcrumb";
import { DataroomHeader } from "@/components/datarooms/dataroom-header";
@@ -48,11 +49,15 @@ export default function Documents() {
</header>
<div className="flex items-center justify-between gap-x-2">
- <div>
+ <div className="flex items-center gap-x-2">
<GenerateIndexButton
teamId={teamInfo?.currentTeam?.id!}
dataroomId={dataroom?.id!}
/>
+ <DownloadDataroomButton
+ teamId={teamInfo?.currentTeam?.id!}
+ dataroomId={dataroom?.id!}
+ />
</div>
<div className="flex items-center justify-end gap-x-2">
<AddDocumentModal
diff --git a/pages/datarooms/[id]/documents/index.tsx b/pages/datarooms/[id]/documents/index.tsx
index 94dcd936..94c6e86f 100644
--- a/pages/datarooms/[id]/documents/index.tsx
+++ b/pages/datarooms/[id]/documents/index.tsx
@@ -3,6 +3,7 @@ import { useState } from "react";
import { useTeam } from "@/context/team-context";
import { ArrowUpDownIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
+import DownloadDataroomButton from "@/components/datarooms/actions/download-dataroom";
import GenerateIndexButton from "@/components/datarooms/actions/generate-index-button";
import { DataroomHeader } from "@/components/datarooms/dataroom-header";
import { DataroomItemsList } from "@/components/datarooms/dataroom-items-list";
@@ -41,11 +42,15 @@ export default function Documents() {
</header>
<div className="flex items-center justify-between gap-x-2">
- <div>
+ <div className="flex items-center gap-x-2">
<GenerateIndexButton
teamId={teamInfo?.currentTeam?.id!}
dataroomId={dataroom?.id!}
/>
+ <DownloadDataroomButton
+ teamId={teamInfo?.currentTeam?.id!}
+ dataroomId={dataroom?.id!}
+ />
</div>
<div className="flex items-center justify-end gap-x-2">
<AddDocumentModal