Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add folderId to incoming webhooks for documents
Marc Seitzaee3d68c7472
diff --git a/components/documents/folder-card.tsx b/components/documents/folder-card.tsxindex 1be474d6..5488ecb2 100644--- a/components/documents/folder-card.tsx+++ b/components/documents/folder-card.tsx@@ -5,6 +5,8 @@ import { useEffect, useRef, useState } from "react";import { TeamContextType } from "@/context/team-context";import {BetweenHorizontalStartIcon,+ ClipboardCopyIcon,+ CopyIcon,FolderIcon,FolderInputIcon,FolderPenIcon,@@ -15,6 +17,10 @@ import {import { toast } from "sonner";import { mutate } from "swr";+import { DataroomFolderWithCount } from "@/lib/swr/use-dataroom";+import { FolderWithCount } from "@/lib/swr/use-documents";+import { timeAgo } from "@/lib/utils";+import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -25,10 +31,6 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";-import { DataroomFolderWithCount } from "@/lib/swr/use-dataroom";-import { FolderWithCount } from "@/lib/swr/use-documents";-import { timeAgo } from "@/lib/utils";-import { MoveToDataroomFolderModal } from "../datarooms/move-dataroom-folder-modal";import { EditFolderModal } from "../folders/edit-folder-modal";import { AddFolderToDataroomModal } from "./add-folder-to-dataroom-modal";@@ -244,7 +246,7 @@ export default function FolderCard({<MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>- <DropdownMenuContent align="end" ref={dropdownRef}>+ <DropdownMenuContent align="end" ref={dropdownRef} className="w-64"><DropdownMenuLabel>Actions</DropdownMenuLabel><DropdownMenuItemonClick={(e) => {@@ -286,6 +288,23 @@ export default function FolderCard({? "Copy folder to other dataroom": "Add folder to dataroom"}</DropdownMenuItem>+ <DropdownMenuItem+ onClick={(e) => {+ e.preventDefault();+ e.stopPropagation();+ navigator.clipboard.writeText(folder.id);+ toast.success("Folder ID copied to clipboard");+ }}+ className="group/folderid"+ >+ <CopyIcon className="mr-2 h-4 w-4" />+ <span className="inline group-hover/folderid:hidden">+ Copy Folder ID+ </span>+ <span className="hidden group-hover/folderid:inline group-hover/folderid:cursor-copy">+ {folder.id}+ </span>+ </DropdownMenuItem><DropdownMenuSeparator /><DropdownMenuItemdiff --git a/pages/api/webhooks/services/[...path]/index.ts b/pages/api/webhooks/services/[...path]/index.tsindex 4cc4d25b..170df98b 100644--- a/pages/api/webhooks/services/[...path]/index.ts+++ b/pages/api/webhooks/services/[...path]/index.ts@@ -57,6 +57,7 @@ const DocumentCreateSchema = BaseSchema.extend({name: z.string(),contentType: z.string(),dataroomId: z.string().optional(),+ folderId: z.string().nullable().optional(),createLink: z.boolean().optional().default(false),link: LinkSchema.optional(),});@@ -224,7 +225,8 @@ async function handleDocumentCreate(token: string,res: NextApiResponse,) {- const { fileUrl, name, contentType, dataroomId, createLink, link } = data;+ const { fileUrl, name, contentType, dataroomId, createLink, link, folderId } =+ data;// Check if the content type is supportedconst supportedContentType = getSupportedContentType(contentType);@@ -330,6 +332,27 @@ async function handleDocumentCreate(const document = await documentCreationResponse.json();let newLink: any;+ // If the document is added to a folder, update the folderId+ if (folderId) {+ const folder = await prisma.folder.findUnique({+ where: { id: folderId, teamId: teamId },+ select: {+ id: true,+ },+ });++ if (!folder) {+ return res.status(400).json({ error: "Invalid folder ID" });+ }++ await prisma.document.update({+ where: { id: document.id, teamId: teamId },+ data: {+ folderId: folder.id,+ },+ });+ }+// If we need to customize the link, update it after creationif (createLink && document.links && document.links.length > 0 && link) {const linkId = document.links[0].id;