Skip to content

Commit ddd4e3e

Browse files
authored
Merge pull request #519 from mfts/feat/bulk
feat: add bulk upload to dataroom documents
2 parents decb839 + 91020b0 commit ddd4e3e

File tree

4 files changed

+92
-160
lines changed

4 files changed

+92
-160
lines changed

components/documents/documents-list.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import { Skeleton } from "@/components/ui/skeleton";
77
import { UploadNotificationDrawer } from "@/components/upload-notification";
88
import UploadZone from "@/components/upload-zone";
99

10+
import {
11+
DataroomFolderDocument,
12+
DataroomFolderWithCount,
13+
} from "@/lib/swr/use-dataroom";
1014
import { FolderWithCount } from "@/lib/swr/use-documents";
1115
import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
1216

17+
import DataroomDocumentCard from "../datarooms/dataroom-document-card";
1318
import DocumentCard from "./document-card";
1419
import { EmptyDocuments } from "./empty-document";
1520
import FolderCard from "./folder-card";
@@ -19,11 +24,16 @@ export function DocumentsList({
1924
documents,
2025
teamInfo,
2126
folderPathName,
27+
dataroomId,
2228
}: {
23-
folders: FolderWithCount[] | undefined;
24-
documents: DocumentWithLinksAndLinkCountAndViewCount[] | undefined;
29+
folders: FolderWithCount[] | DataroomFolderWithCount[] | undefined;
30+
documents:
31+
| DocumentWithLinksAndLinkCountAndViewCount[]
32+
| DataroomFolderDocument[]
33+
| undefined;
2534
teamInfo: TeamContextType | null;
2635
folderPathName?: string[];
36+
dataroomId?: string;
2737
}) {
2838
const [uploads, setUploads] = useState<
2939
{ fileName: string; progress: number; documentId?: string }[]
@@ -55,6 +65,7 @@ export function DocumentsList({
5565
}}
5666
setUploads={setUploads}
5767
setRejectedFiles={setRejectedFiles}
68+
dataroomId={dataroomId}
5869
>
5970
<ScrollArea
6071
className="-m-2 h-[calc(100dvh-205px)] *:p-2"
@@ -70,6 +81,8 @@ export function DocumentsList({
7081
key={folder.id}
7182
folder={folder}
7283
teamInfo={teamInfo}
84+
isDataroom={dataroomId ? true : false}
85+
dataroomId={dataroomId}
7386
/>
7487
);
7588
})
@@ -95,13 +108,25 @@ export function DocumentsList({
95108
<ul role="list" className="space-y-4">
96109
{documents
97110
? documents.map((document) => {
98-
return (
99-
<DocumentCard
100-
key={document.id}
101-
document={document}
102-
teamInfo={teamInfo}
103-
/>
104-
);
111+
if (dataroomId) {
112+
return (
113+
<DataroomDocumentCard
114+
key={document.id}
115+
document={document as DataroomFolderDocument}
116+
teamInfo={teamInfo}
117+
/>
118+
);
119+
} else {
120+
return (
121+
<DocumentCard
122+
key={document.id}
123+
document={
124+
document as DocumentWithLinksAndLinkCountAndViewCount
125+
}
126+
teamInfo={teamInfo}
127+
/>
128+
);
129+
}
105130
})
106131
: Array.from({ length: 3 }).map((_, i) => (
107132
<li

components/upload-zone.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default function UploadZone({
6868
folderPathName,
6969
setUploads,
7070
setRejectedFiles,
71+
dataroomId,
7172
}: {
7273
children: React.ReactNode;
7374
onUploadStart: (
@@ -88,6 +89,7 @@ export default function UploadZone({
8889
React.SetStateAction<{ fileName: string; message: string }[]>
8990
>;
9091
folderPathName?: string;
92+
dataroomId?: string;
9193
}) {
9294
const analytics = useAnalytics();
9395
const { plan, loading } = usePlan();
@@ -186,6 +188,46 @@ export default function UploadZone({
186188
);
187189

188190
const document = await response.json();
191+
192+
if (dataroomId) {
193+
try {
194+
const response = await fetch(
195+
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
196+
{
197+
method: "POST",
198+
headers: {
199+
"Content-Type": "application/json",
200+
},
201+
body: JSON.stringify({
202+
documentId: document.id,
203+
folderPathName: folderPathName,
204+
}),
205+
},
206+
);
207+
208+
if (!response.ok) {
209+
const { message } = await response.json();
210+
console.error(
211+
"An error occurred while adding document to the dataroom: ",
212+
message,
213+
);
214+
return;
215+
}
216+
217+
mutate(
218+
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
219+
);
220+
mutate(
221+
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/folders/documents/${folderPathName}`,
222+
);
223+
} catch (error) {
224+
console.error(
225+
"An error occurred while adding document to the dataroom: ",
226+
error,
227+
);
228+
}
229+
}
230+
189231
// update progress to 100%
190232
onUploadProgress(index, 100, document.id);
191233

@@ -197,6 +239,7 @@ export default function UploadZone({
197239
type: document.type,
198240
teamId: teamInfo?.currentTeam?.id,
199241
bulkupload: true,
242+
dataroomId: dataroomId,
200243
});
201244

202245
return document;

pages/datarooms/[id]/documents/[...name].tsx

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,21 @@ import { useTeam } from "@/context/team-context";
44
import { FileIcon, FolderIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
55

66
import { BreadcrumbComponent } from "@/components/datarooms/dataroom-breadcrumb";
7-
import DataroomDocumentCard from "@/components/datarooms/dataroom-document-card";
87
import { DataroomHeader } from "@/components/datarooms/dataroom-header";
98
import { SidebarFolderTree } from "@/components/datarooms/folders";
109
import { AddDocumentModal } from "@/components/documents/add-document-modal";
11-
import DocumentCard from "@/components/documents/document-card";
12-
import { EmptyDocuments } from "@/components/documents/empty-document";
13-
import FolderCard from "@/components/documents/folder-card";
10+
import { DocumentsList } from "@/components/documents/documents-list";
1411
import { AddFolderModal } from "@/components/folders/add-folder-modal";
1512
import AppLayout from "@/components/layouts/app";
1613
import { NavMenu } from "@/components/navigation-menu";
17-
import Folder from "@/components/shared/icons/folder";
1814
import { Button } from "@/components/ui/button";
1915
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
20-
import { Separator } from "@/components/ui/separator";
21-
import { Skeleton } from "@/components/ui/skeleton";
2216

2317
import {
2418
useDataroom,
2519
useDataroomFolderDocuments,
2620
useDataroomFolders,
2721
} from "@/lib/swr/use-dataroom";
28-
import useDocuments, { useRootFolders } from "@/lib/swr/use-documents";
2922

3023
export default function Documents() {
3124
const router = useRouter();
@@ -131,77 +124,16 @@ export default function Documents() {
131124
</p>
132125
) : null}
133126
</section>
134-
{/* Folders list */}
135-
<ul role="list" className="space-y-4">
136-
{folders
137-
? folders.map((folder) => {
138-
return (
139-
<FolderCard
140-
key={folder.id}
141-
folder={folder}
142-
teamInfo={teamInfo}
143-
isDataroom={true}
144-
dataroomId={dataroom?.id}
145-
/>
146-
);
147-
})
148-
: Array.from({ length: 3 }).map((_, i) => (
149-
<li
150-
key={i}
151-
className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 sm:px-6 lg:px-6"
152-
>
153-
<Skeleton key={i} className="h-9 w-9" />
154-
<div>
155-
<Skeleton key={i} className="h-4 w-32" />
156-
<Skeleton key={i + 1} className="mt-2 h-3 w-12" />
157-
</div>
158-
<Skeleton
159-
key={i + 1}
160-
className="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"
161-
/>
162-
</li>
163-
))}
164-
</ul>
165127

166-
{/* Documents list */}
167-
<ul role="list" className="space-y-4">
168-
{documents
169-
? documents.map((document) => {
170-
return (
171-
<DataroomDocumentCard
172-
key={document.id}
173-
document={document}
174-
teamInfo={teamInfo}
175-
/>
176-
);
177-
})
178-
: Array.from({ length: 3 }).map((_, i) => (
179-
<li
180-
key={i}
181-
className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 sm:px-6 lg:px-6"
182-
>
183-
<Skeleton key={i} className="h-9 w-9" />
184-
<div>
185-
<Skeleton key={i} className="h-4 w-32" />
186-
<Skeleton key={i + 1} className="mt-2 h-3 w-12" />
187-
</div>
188-
<Skeleton
189-
key={i + 1}
190-
className="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"
191-
/>
192-
</li>
193-
))}
194-
</ul>
128+
<DocumentsList
129+
documents={documents}
130+
folders={folders}
131+
teamInfo={teamInfo}
132+
folderPathName={name}
133+
dataroomId={dataroom?.id}
134+
/>
195135
</div>
196136
</div>
197-
198-
<div className="space-y-4">
199-
{documents && documents.length === 0 && (
200-
<div className="flex items-center justify-center">
201-
<EmptyDocuments />
202-
</div>
203-
)}
204-
</div>
205137
</div>
206138
</AppLayout>
207139
);

pages/datarooms/[id]/documents/index.tsx

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ import { useTeam } from "@/context/team-context";
22
import { FileIcon, FolderIcon, FolderPlusIcon, PlusIcon } from "lucide-react";
33

44
import { BreadcrumbComponent } from "@/components/datarooms/dataroom-breadcrumb";
5-
import DataroomDocumentCard from "@/components/datarooms/dataroom-document-card";
65
import { DataroomHeader } from "@/components/datarooms/dataroom-header";
76
import { SidebarFolderTree } from "@/components/datarooms/folders";
87
import { AddDocumentModal } from "@/components/documents/add-document-modal";
9-
import DocumentCard from "@/components/documents/document-card";
10-
import { EmptyDocuments } from "@/components/documents/empty-document";
11-
import FolderCard from "@/components/documents/folder-card";
8+
import { DocumentsList } from "@/components/documents/documents-list";
129
import { AddFolderModal } from "@/components/folders/add-folder-modal";
1310
import AppLayout from "@/components/layouts/app";
1411
import { NavMenu } from "@/components/navigation-menu";
15-
import Folder from "@/components/shared/icons/folder";
1612
import { Button } from "@/components/ui/button";
17-
import { Separator } from "@/components/ui/separator";
18-
import { Skeleton } from "@/components/ui/skeleton";
1913

2014
import {
2115
useDataroom,
@@ -120,77 +114,15 @@ export default function Documents() {
120114
</p>
121115
) : null}
122116
</section>
123-
{/* Folders list */}
124-
<ul role="list" className="space-y-4">
125-
{folders
126-
? folders.map((folder) => {
127-
return (
128-
<FolderCard
129-
key={folder.id}
130-
folder={folder}
131-
teamInfo={teamInfo}
132-
isDataroom={true}
133-
dataroomId={dataroom?.id}
134-
/>
135-
);
136-
})
137-
: Array.from({ length: 3 }).map((_, i) => (
138-
<li
139-
key={i}
140-
className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 sm:px-6 lg:px-6"
141-
>
142-
<Skeleton key={i} className="h-9 w-9" />
143-
<div>
144-
<Skeleton key={i} className="h-4 w-32" />
145-
<Skeleton key={i + 1} className="mt-2 h-3 w-12" />
146-
</div>
147-
<Skeleton
148-
key={i + 1}
149-
className="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"
150-
/>
151-
</li>
152-
))}
153-
</ul>
154117

155-
{/* Documents list */}
156-
<ul role="list" className="space-y-4">
157-
{documents
158-
? documents.map((document) => {
159-
return (
160-
<DataroomDocumentCard
161-
key={document.id}
162-
document={document}
163-
teamInfo={teamInfo}
164-
/>
165-
);
166-
})
167-
: Array.from({ length: 3 }).map((_, i) => (
168-
<li
169-
key={i}
170-
className="relative flex w-full items-center space-x-3 rounded-lg border px-4 py-5 sm:px-6 lg:px-6"
171-
>
172-
<Skeleton key={i} className="h-9 w-9" />
173-
<div>
174-
<Skeleton key={i} className="h-4 w-32" />
175-
<Skeleton key={i + 1} className="mt-2 h-3 w-12" />
176-
</div>
177-
<Skeleton
178-
key={i + 1}
179-
className="absolute right-5 top-[50%] h-5 w-20 -translate-y-[50%] transform"
180-
/>
181-
</li>
182-
))}
183-
</ul>
118+
<DocumentsList
119+
documents={documents}
120+
folders={folders}
121+
teamInfo={teamInfo}
122+
dataroomId={dataroom?.id}
123+
/>
184124
</div>
185125
</div>
186-
187-
<div className="space-y-4">
188-
{documents && documents.length === 0 && (
189-
<div className="flex items-center justify-center">
190-
<EmptyDocuments />
191-
</div>
192-
)}
193-
</div>
194126
</div>
195127
</AppLayout>
196128
);

0 commit comments

Comments
 (0)