Skip to content

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

feat: add upload to any dataroom folder

Marc Seitz18646193e712
diff --git a/app/api/links/[id]/upload/route.ts b/app/api/links/[id]/upload/route.ts
index a7b171f8..6f93e60a 100644
--- a/app/api/links/[id]/upload/route.ts
+++ b/app/api/links/[id]/upload/route.ts
@@ -12,9 +12,10 @@ export async function POST(
try {
const linkId = params.id;
const body = await request.json();
- const { documentData, dataroomId } = body as {
+ const { documentData, dataroomId, folderId } = body as {
documentData: DocumentData;
dataroomId: string;
+ folderId?: string;
};
if (!linkId || !documentData || !dataroomId) {
@@ -95,7 +96,10 @@ export async function POST(
});
// 2. Create the dataroom document
- let dataroomFolderId: string | null = null;
+ // If folderId is provided and link has no uploadFolderId, use folderId as the dataroomFolderId
+ // Otherwise, use the link's uploadFolderId
+ // or null if it doesn't exist
+ let dataroomFolderId: string | null = folderId ?? null;
if (link.uploadFolderId) {
const dataroomFolder = await prisma.dataroomFolder.findUnique({
where: {
diff --git a/components/links/link-sheet/upload-section/index.tsx b/components/links/link-sheet/upload-section/index.tsx
index b2e3982d..22dc92c6 100644
--- a/components/links/link-sheet/upload-section/index.tsx
+++ b/components/links/link-sheet/upload-section/index.tsx
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
-import { CircleHelpIcon, FolderIcon } from "lucide-react";
+import { CircleHelpIcon, CircleXIcon, FolderIcon, XIcon } from "lucide-react";
import { motion } from "motion/react";
import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";
@@ -37,7 +37,7 @@ function FolderSelectionModal({
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
dataroomId: string;
currentFolder: TSelectedFolder | null;
- handleSelectFolder: (selectedFolder: TSelectedFolder) => void;
+ handleSelectFolder: (selectedFolder: TSelectedFolder | null) => void;
}) {
const [selectedFolder, setSelectedFolder] = useState<TSelectedFolder | null>(
currentFolder,
@@ -57,9 +57,22 @@ function FolderSelectionModal({
<div className="flex w-full cursor-pointer rounded-md border border-input bg-white text-foreground placeholder-muted-foreground focus:border-muted-foreground focus:outline-none focus:ring-inset focus:ring-muted-foreground dark:border-gray-500 dark:bg-gray-800 focus:dark:bg-transparent sm:text-sm">
<div className="flex w-full items-center px-3 py-2">
{selectedFolder ? (
- <span className="flex items-center gap-1">
- <FolderIcon className="h-4 w-4" /> {selectedFolder.name}
- </span>
+ <div className="relative w-full">
+ <span className="flex items-center gap-1">
+ <FolderIcon className="mr-1 h-4 w-4" />{" "}
+ {selectedFolder.name}
+ </span>
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ setSelectedFolder(null);
+ handleSelectFolder(null);
+ }}
+ className="pointer-events-auto absolute inset-y-0 right-0 z-10 -mr-1 flex items-center rounded-md p-1 hover:bg-muted"
+ >
+ <XIcon className="h-4 w-4 text-muted-foreground" />
+ </button>
+ </div>
) : (
<span className="text-muted-foreground">
Optionally, select folder
@@ -166,16 +179,15 @@ export default function UploadSection({
});
};
- const handleSelectFolder = (selectedFolder: TSelectedFolder): void => {
+ const handleSelectFolder = (selectedFolder: TSelectedFolder | null): void => {
setSelectedFolder(selectedFolder);
setData({
...data,
uploadFolderId: selectedFolder?.id ?? null,
+ uploadFolderName: selectedFolder?.name || "Home",
});
};
- console.log("selectedFolder", selectedFolder);
-
return (
<div className="pb-5">
<LinkItem
@@ -215,12 +227,17 @@ export default function UploadSection({
<div className="space-y-4">
<Label
htmlFor="link-folder"
- className="flex items-center gap-2"
+ className="flex flex-col items-start gap-2"
>
- <span>Upload to specific folder</span>
- <BadgeTooltip content="This is the folder that will be used to store uploaded files. If you don't select a folder, the files will be stored in the All Documents.">
- <CircleHelpIcon className="h-4 w-4 shrink-0 text-muted-foreground hover:text-foreground" />
- </BadgeTooltip>
+ <div className="flex items-center gap-2">
+ <span>Upload to specific folder</span>
+ <BadgeTooltip content="This is the folder that will be used to store uploaded files. If you don't select a folder, the files will be uploaded to the folder the visitor chooses.">
+ <CircleHelpIcon className="h-4 w-4 shrink-0 text-muted-foreground hover:text-foreground" />
+ </BadgeTooltip>
+ </div>
+ <span className="text-sm text-muted-foreground">
+ Leave blank for visitor to choose folder
+ </span>
</Label>
<FolderSelectionModal
open={open}
diff --git a/components/view/dataroom/document-upload-modal.tsx b/components/view/dataroom/document-upload-modal.tsx
index 5171ef70..0b9e933c 100644
--- a/components/view/dataroom/document-upload-modal.tsx
+++ b/components/view/dataroom/document-upload-modal.tsx
@@ -17,10 +17,12 @@ export function DocumentUploadModal({
linkId,
dataroomId,
viewerId,
+ folderId,
}: {
linkId: string;
dataroomId: string;
viewerId: string;
+ folderId?: string;
}) {
const [isOpen, setIsOpen] = useState(false);
@@ -54,6 +56,7 @@ export function DocumentUploadModal({
dataroomId,
}}
teamId="visitor-upload"
+ folderId={folderId}
/>
</DialogContent>
</Dialog>
diff --git a/components/view/viewer/dataroom-viewer.tsx b/components/view/viewer/dataroom-viewer.tsx
index 6ee98ee5..f267c7f6 100644
--- a/components/view/viewer/dataroom-viewer.tsx
+++ b/components/view/viewer/dataroom-viewer.tsx
@@ -268,6 +268,7 @@ export default function DataroomViewer({
linkId={linkId}
dataroomId={dataroom?.id}
viewerId={viewerId}
+ folderId={folderId ?? undefined}
/>
)}
</div>
diff --git a/components/viewer-upload-component.tsx b/components/viewer-upload-component.tsx
index 36a5bdf5..35a5a32c 100644
--- a/components/viewer-upload-component.tsx
+++ b/components/viewer-upload-component.tsx
@@ -9,9 +9,11 @@ import ViewerUploadZone from "@/components/viewer-upload-zone";
export function ViewerUploadComponent({
viewerData,
teamId,
+ folderId,
}: {
viewerData: { id: string; linkId: string; dataroomId?: string };
teamId: string;
+ folderId?: string;
}) {
const [uploads, setUploads] = useState<
{ fileName: string; progress: number }[]
@@ -45,6 +47,7 @@ export function ViewerUploadComponent({
body: JSON.stringify({
documentData,
dataroomId: viewerData.dataroomId,
+ folderId: folderId,
}),
});