Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add folder name to links
Marc Seitz5c32d496134a
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex e427bf0c..91a9ce95 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -82,6 +82,7 @@ export const DEFAULT_LINK_PROPS = (enableUpload: false,isFileRequestOnly: false,uploadFolderId: null,+ uploadFolderName: "Home",});export type DEFAULT_LINK_TYPE = {@@ -119,6 +120,7 @@ export type DEFAULT_LINK_TYPE = {enableUpload: boolean;isFileRequestOnly: boolean;uploadFolderId: string | null;+ uploadFolderName: string;};export default function LinkSheet({diff --git a/components/links/link-sheet/upload-section/index.tsx b/components/links/link-sheet/upload-section/index.tsxindex f26e83ea..b2e3982d 100644--- a/components/links/link-sheet/upload-section/index.tsx+++ b/components/links/link-sheet/upload-section/index.tsx@@ -30,15 +30,17 @@ function FolderSelectionModal({open,setOpen,dataroomId,+ currentFolder,handleSelectFolder,}: {open: boolean;setOpen: React.Dispatch<React.SetStateAction<boolean>>;dataroomId: string;+ currentFolder: TSelectedFolder | null;handleSelectFolder: (selectedFolder: TSelectedFolder) => void;}) {const [selectedFolder, setSelectedFolder] = useState<TSelectedFolder | null>(- null,+ currentFolder,);const handleSubmit = async (event: any) => {@@ -129,16 +131,24 @@ export default function UploadSection({}: LinkUpgradeOptions) => void;targetId: string;}) {- const { enableUpload, isFileRequestOnly, uploadFolderId } = data;+ const { enableUpload, isFileRequestOnly, uploadFolderId, uploadFolderName } =+ data;const [enabled, setEnabled] = useState<boolean>(false);- const [selectedFolder, setSelectedFolder] = useState<TSelectedFolder>(null);-+ const [selectedFolder, setSelectedFolder] = useState<TSelectedFolder | null>(+ null,+ );const [open, setOpen] = useState<boolean>(false);useEffect(() => {setEnabled(enableUpload!);}, [enableUpload]);+ useEffect(() => {+ if (uploadFolderId) {+ setSelectedFolder({ id: uploadFolderId, name: uploadFolderName });+ }+ }, [uploadFolderId, uploadFolderName]);+const handleUpload = async () => {const updatedUpload = !enabled;@@ -164,6 +174,8 @@ export default function UploadSection({});};+ console.log("selectedFolder", selectedFolder);+return (<div className="pb-5"><LinkItem@@ -189,7 +201,7 @@ export default function UploadSection({><div className="flex w-full flex-col items-start gap-6 overflow-x-visible pb-4 pt-0"><div className="w-full space-y-4">- <div className="flex items-center space-x-2">+ {/* <div className="flex items-center space-x-2"><Switchid="file-request-mode"checked={isFileRequestOnly}@@ -198,14 +210,14 @@ export default function UploadSection({<Label htmlFor="file-request-mode">File request only mode</Label>- </div>+ </div> */}<div className="space-y-4"><LabelhtmlFor="link-folder"className="flex items-center gap-2">- <span>Folder for uploaded file</span>+ <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>@@ -214,6 +226,7 @@ export default function UploadSection({open={open}setOpen={setOpen}dataroomId={targetId}+ currentFolder={selectedFolder}handleSelectFolder={handleSelectFolder}/></div>diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 625a3557..92a21713 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -174,6 +174,7 @@ export default function LinksTable({enableUpload: link.enableUpload ?? false,isFileRequestOnly: link.isFileRequestOnly ?? false,uploadFolderId: link.uploadFolderId ?? null,+ uploadFolderName: link.uploadFolderName ?? "Home",});//wait for dropdown to close before opening the link sheetsetTimeout(() => {diff --git a/lib/types.ts b/lib/types.tsindex abc7c410..90a685a6 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -34,7 +34,7 @@ export interface DocumentWithLinksAndLinkCountAndViewCount extends Document {folder: {name: string;path: string;- }+ };folderList: string[];}@@ -54,6 +54,7 @@ export interface LinkWithViews extends Link {views: View[];feedback: { id: true; data: { question: string; type: string } } | null;customFields: CustomField[];+ uploadFolderName: string | undefined;}export interface LinkWithDocument extends Link {diff --git a/pages/api/teams/[teamId]/datarooms/[id]/links.ts b/pages/api/teams/[teamId]/datarooms/[id]/links.tsindex d8304812..bff6c7f1 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/links.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/links.ts@@ -1,11 +1,12 @@import { NextApiRequest, NextApiResponse } from "next";+import { Link } from "@prisma/client";import { getServerSession } from "next-auth/next";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";import { getTeamWithUsersAndDocument } from "@/lib/team/helper";-import { CustomUser } from "@/lib/types";+import { CustomUser, LinkWithViews } from "@/lib/types";import { decryptEncrpytedPassword, log } from "@/lib/utils";import { authOptions } from "../../../../auth/[...nextauth]";@@ -71,13 +72,27 @@ export default async function handle(});// Decrypt the password for each link- links.forEach((link) => {+ const extendedLinks: LinkWithViews[] = links as LinkWithViews[];++ for (const link of extendedLinks) {if (link.password !== null) {link.password = decryptEncrpytedPassword(link.password);}- });+ if (link.enableUpload && link.uploadFolderId !== null) {+ const folder = await prisma.dataroomFolder.findUnique({+ where: {+ id: link.uploadFolderId,+ },+ select: {+ name: true,+ },+ });+ link.uploadFolderName = folder?.name;+ }+ }- return res.status(200).json(links);+ // console.log("links", links);+ return res.status(200).json(extendedLinks);} catch (error) {log({message: `Failed to get links for dataroom: _${dataroomId}_. \n\n ${error} \n\n*Metadata*: \`{teamId: ${teamId}, userId: ${userId}}\``,