Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update folder documents in newPath when dragging docs
Marc Seitza67015eb25d3
diff --git a/components/datarooms/dataroom-items-list.tsx b/components/datarooms/dataroom-items-list.tsxindex e7bbb532..c9a79412 100644--- a/components/datarooms/dataroom-items-list.tsx+++ b/components/datarooms/dataroom-items-list.tsx@@ -194,10 +194,20 @@ export function DataroomItemsList({throw new Error("Failed to move document");}- const { updatedCount } = await response.json();+ const { updatedCount, newPath } = await response.json();// Update local data using SWR's mutatemutate(key);+ // update folder document counts in current path+ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/folders${folderPathName ? `/${folderPathName.join("/")}` : "?root=true"}`,+ );+ // update documents in new folder (or home)+ newPath &&+ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/folders/documents${newPath}`,+ );+toast.success(`${updatedCount} Document${updatedCount > 1 ? "s" : ""} moved successfully`,);diff --git a/components/datarooms/move-dataroom-folder-modal.tsx b/components/datarooms/move-dataroom-folder-modal.tsxindex 3e9dbef1..708c1689 100644--- a/components/datarooms/move-dataroom-folder-modal.tsx+++ b/components/datarooms/move-dataroom-folder-modal.tsx@@ -97,7 +97,7 @@ export function MoveToDataroomFolderModal({// update current foldermutate(key);- // update new folder (or home)+ // update documents in new folder (or home)mutate(`/api/teams/${teamId}/datarooms/${dataroomId}${newPath ? `/folders/documents${newPath}` : "/documents"}`,);diff --git a/pages/api/teams/[teamId]/datarooms/[id]/documents/move.ts b/pages/api/teams/[teamId]/datarooms/[id]/documents/move.tsindex b59ad770..a66294e2 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/documents/move.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/documents/move.ts@@ -58,6 +58,12 @@ export default async function handle(},});+ // Get new path for folder+ const folder = await prisma.dataroomFolder.findUnique({+ where: { id: folderId },+ select: { path: true },+ });+if (updatedDocuments.count === 0) {return res.status(404).end("No documents were updated");}@@ -67,6 +73,7 @@ export default async function handle(return res.status(200).json({message: "Document moved successfully",updatedCount: updatedDocuments.count,+ newPath: folder?.path,});} else {// We only allow PATCH requests