Skip to content

Commit aee3d68

Browse files
committed
feat: add folderId to incoming webhooks for documents
1 parent 010a1a3 commit aee3d68

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

components/documents/folder-card.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { useEffect, useRef, useState } from "react";
55
import { TeamContextType } from "@/context/team-context";
66
import {
77
BetweenHorizontalStartIcon,
8+
ClipboardCopyIcon,
9+
CopyIcon,
810
FolderIcon,
911
FolderInputIcon,
1012
FolderPenIcon,
@@ -15,6 +17,10 @@ import {
1517
import { toast } from "sonner";
1618
import { mutate } from "swr";
1719

20+
import { DataroomFolderWithCount } from "@/lib/swr/use-dataroom";
21+
import { FolderWithCount } from "@/lib/swr/use-documents";
22+
import { timeAgo } from "@/lib/utils";
23+
1824
import { Button } from "@/components/ui/button";
1925
import {
2026
DropdownMenu,
@@ -25,10 +31,6 @@ import {
2531
DropdownMenuTrigger,
2632
} from "@/components/ui/dropdown-menu";
2733

28-
import { DataroomFolderWithCount } from "@/lib/swr/use-dataroom";
29-
import { FolderWithCount } from "@/lib/swr/use-documents";
30-
import { timeAgo } from "@/lib/utils";
31-
3234
import { MoveToDataroomFolderModal } from "../datarooms/move-dataroom-folder-modal";
3335
import { EditFolderModal } from "../folders/edit-folder-modal";
3436
import { AddFolderToDataroomModal } from "./add-folder-to-dataroom-modal";
@@ -244,7 +246,7 @@ export default function FolderCard({
244246
<MoreVertical className="h-4 w-4" />
245247
</Button>
246248
</DropdownMenuTrigger>
247-
<DropdownMenuContent align="end" ref={dropdownRef}>
249+
<DropdownMenuContent align="end" ref={dropdownRef} className="w-64">
248250
<DropdownMenuLabel>Actions</DropdownMenuLabel>
249251
<DropdownMenuItem
250252
onClick={(e) => {
@@ -286,6 +288,23 @@ export default function FolderCard({
286288
? "Copy folder to other dataroom"
287289
: "Add folder to dataroom"}
288290
</DropdownMenuItem>
291+
<DropdownMenuItem
292+
onClick={(e) => {
293+
e.preventDefault();
294+
e.stopPropagation();
295+
navigator.clipboard.writeText(folder.id);
296+
toast.success("Folder ID copied to clipboard");
297+
}}
298+
className="group/folderid"
299+
>
300+
<CopyIcon className="mr-2 h-4 w-4" />
301+
<span className="inline group-hover/folderid:hidden">
302+
Copy Folder ID
303+
</span>
304+
<span className="hidden group-hover/folderid:inline group-hover/folderid:cursor-copy">
305+
{folder.id}
306+
</span>
307+
</DropdownMenuItem>
289308
<DropdownMenuSeparator />
290309

291310
<DropdownMenuItem

pages/api/webhooks/services/[...path]/index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const DocumentCreateSchema = BaseSchema.extend({
5757
name: z.string(),
5858
contentType: z.string(),
5959
dataroomId: z.string().optional(),
60+
folderId: z.string().nullable().optional(),
6061
createLink: z.boolean().optional().default(false),
6162
link: LinkSchema.optional(),
6263
});
@@ -224,7 +225,8 @@ async function handleDocumentCreate(
224225
token: string,
225226
res: NextApiResponse,
226227
) {
227-
const { fileUrl, name, contentType, dataroomId, createLink, link } = data;
228+
const { fileUrl, name, contentType, dataroomId, createLink, link, folderId } =
229+
data;
228230

229231
// Check if the content type is supported
230232
const supportedContentType = getSupportedContentType(contentType);
@@ -330,6 +332,27 @@ async function handleDocumentCreate(
330332
const document = await documentCreationResponse.json();
331333
let newLink: any;
332334

335+
// If the document is added to a folder, update the folderId
336+
if (folderId) {
337+
const folder = await prisma.folder.findUnique({
338+
where: { id: folderId, teamId: teamId },
339+
select: {
340+
id: true,
341+
},
342+
});
343+
344+
if (!folder) {
345+
return res.status(400).json({ error: "Invalid folder ID" });
346+
}
347+
348+
await prisma.document.update({
349+
where: { id: document.id, teamId: teamId },
350+
data: {
351+
folderId: folder.id,
352+
},
353+
});
354+
}
355+
333356
// If we need to customize the link, update it after creation
334357
if (createLink && document.links && document.links.length > 0 && link) {
335358
const linkId = document.links[0].id;

0 commit comments

Comments
 (0)