Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

table view for change group permission from document card

Ashish Viradiyad82995c001ba
diff --git a/components/datarooms/dataroom-document-card.tsx b/components/datarooms/dataroom-document-card.tsx
index f0c8cb3e..fabdb546 100644
--- a/components/datarooms/dataroom-document-card.tsx
+++ b/components/datarooms/dataroom-document-card.tsx
@@ -8,6 +8,7 @@ import { TeamContextType } from "@/context/team-context";
import {
ArchiveXIcon,
BetweenHorizontalStartIcon,
+ FileSlidersIcon,
FolderInputIcon,
MoreVertical,
} from "lucide-react";
@@ -15,6 +16,11 @@ import { useTheme } from "next-themes";
import { toast } from "sonner";
import { mutate } from "swr";
+import { type DataroomFolderDocument } from "@/lib/swr/use-dataroom";
+import { type DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
+import { cn, nFormatter, timeAgo } from "@/lib/utils";
+import { fileIcon } from "@/lib/utils/get-file-icon";
+
import BarChart from "@/components/shared/icons/bar-chart";
import { Button } from "@/components/ui/button";
import {
@@ -26,13 +32,9 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
-import { type DataroomFolderDocument } from "@/lib/swr/use-dataroom";
-import { type DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";
-import { cn, nFormatter, timeAgo } from "@/lib/utils";
-import { fileIcon } from "@/lib/utils/get-file-icon";
-
import { AddToDataroomModal } from "../documents/add-document-to-dataroom-modal";
import FileProcessStatusBar from "../documents/file-process-status-bar";
+import { SetGroupPermissionsModal } from "./groups/set-group-permissions-modal";
import { MoveToDataroomFolderModal } from "./move-dataroom-folder-modal";
type DocumentsCardProps = {
@@ -51,6 +53,8 @@ export default function DataroomDocumentCard({
isSelected,
isHovered,
}: DocumentsCardProps) {
+ const [groupPermissionOpen, setGroupPermissionOpen] =
+ useState<boolean>(false);
const { theme, systemTheme } = useTheme();
const isLight =
theme === "light" || (theme === "system" && systemTheme === "light");
@@ -264,6 +268,15 @@ export default function DataroomDocumentCard({
<BetweenHorizontalStartIcon className="mr-2 h-4 w-4" />
Copy to other dataroom
</DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ setGroupPermissionOpen(true);
+ }}
+ >
+ <FileSlidersIcon className="mr-2 h-4 w-4" />
+ Set Permission
+ </DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
@@ -322,6 +335,16 @@ export default function DataroomDocumentCard({
folderIds={[]}
/>
) : null}
+ {groupPermissionOpen ? (
+ <SetGroupPermissionsModal
+ fileName={dataroomDocument.document.name}
+ open={groupPermissionOpen}
+ setOpen={setGroupPermissionOpen}
+ dataroomId={dataroomId}
+ documentId={dataroomDocument.id}
+ dataroomDocumentId={dataroomDocument.id}
+ />
+ ) : null}
</>
);
-}
+}
\ No newline at end of file
diff --git a/components/datarooms/groups/set-group-permissions-modal.tsx b/components/datarooms/groups/set-group-permissions-modal.tsx
new file mode 100644
index 00000000..fac96b41
--- /dev/null
+++ b/components/datarooms/groups/set-group-permissions-modal.tsx
@@ -0,0 +1,341 @@
+import { useEffect, useState } from "react";
+
+import { useTeam } from "@/context/team-context";
+import { ItemType } from "@prisma/client";
+import {
+ ArrowDownToLineIcon,
+ EyeIcon,
+ EyeOffIcon,
+ Loader2,
+} from "lucide-react";
+import { toast } from "sonner";
+import { mutate } from "swr";
+
+import useDataroomGroups from "@/lib/swr/use-dataroom-groups";
+import { cn } from "@/lib/utils";
+
+import CloudDownloadOff from "@/components/shared/icons/cloud-download-off";
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/components/ui/dialog";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
+
+type GroupPermissions = Record<string, { view: boolean; download: boolean }>;
+
+export function SetGroupPermissionsModal({
+ open,
+ setOpen,
+ dataroomId,
+ documentId,
+ dataroomDocumentId,
+ onComplete,
+ fileName,
+ isAutoOpen,
+}: {
+ open: boolean;
+ setOpen: (open: boolean) => void;
+ dataroomId: string;
+ documentId: string;
+ dataroomDocumentId: string;
+ onComplete?: () => void;
+ fileName: string;
+ isAutoOpen?: boolean;
+}) {
+ const teamInfo = useTeam();
+ const teamId = teamInfo?.currentTeam?.id;
+ const { viewerGroups, loading: viewerGroupsLoading } = useDataroomGroups({
+ documentId,
+ });
+ const [loading, setLoading] = useState(false);
+ const [selectedGroups, setSelectedGroups] = useState<GroupPermissions>({});
+
+ useEffect(() => {
+ if (viewerGroups) {
+ const initialGroups = viewerGroups.reduce<GroupPermissions>(
+ (acc, group) => ({
+ ...acc,
+ [group.id]: {
+ view: group.accessControls?.[0]?.canView ?? false,
+ download: group.accessControls?.[0]?.canDownload ?? false,
+ },
+ }),
+ {},
+ );
+ setSelectedGroups(initialGroups);
+ }
+ }, [viewerGroups]);
+
+ const handleSubmit = async (event: React.FormEvent) => {
+ event.preventDefault();
+ setLoading(true);
+
+ try {
+ await Promise.all(
+ Object.entries(selectedGroups).map(([groupId, permissions]) => {
+ return fetch(
+ `/api/teams/${teamId}/datarooms/${dataroomId}/groups/${groupId}/permissions`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ dataroomId,
+ groupId,
+ permissions: {
+ [dataroomDocumentId]: {
+ itemType: ItemType.DATAROOM_DOCUMENT,
+ view: permissions.view,
+ download: permissions.download,
+ },
+ },
+ }),
+ },
+ );
+ }),
+ );
+
+ toast.success("Group permissions updated successfully!");
+ onComplete?.();
+ setOpen(false);
+ mutate(
+ `/api/teams/${teamId}/datarooms/${dataroomId}/groups?documentId=${documentId}`,
+ );
+ } catch (error) {
+ console.error("Error updating group permissions:", error);
+ toast.error("Failed to update group permissions");
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const updatePermissions = (groupId: string, newPermissions: string[]) => {
+ const hasView = newPermissions.includes("view");
+ const hasDownload = newPermissions.includes("download");
+
+ const prevPermissions = selectedGroups[groupId] || {
+ view: false,
+ download: false,
+ };
+
+ if (
+ hasDownload &&
+ !hasView &&
+ !prevPermissions.view &&
+ !prevPermissions.download
+ ) {
+ newPermissions = ["view", "download"];
+ } else if (hasDownload && !hasView) {
+ newPermissions = [];
+ }
+
+ setSelectedGroups((prev) => ({
+ ...prev,
+ [groupId]: {
+ view: newPermissions.includes("view"),
+ download: newPermissions.includes("download"),
+ },
+ }));
+ };
+
+ if (isAutoOpen && !viewerGroups) {
+ onComplete?.();
+ setOpen(false);
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={setOpen}>
+ <DialogContent className="sm:max-w-[600px]">
+ <DialogHeader className="w-[90%]">
+ <DialogTitle>Set Group Permissions for "{fileName}"</DialogTitle>
+ <DialogDescription>
+ Choose which groups can access this document and their permissions.
+ </DialogDescription>
+ </DialogHeader>
+ <form onSubmit={handleSubmit}>
+ <div className="rounded-md border">
+ <div className="max-h-[400px] overflow-y-auto">
+ <Table>
+ <TableHeader className="sticky top-0 z-10 bg-secondary">
+ <TableRow>
+ <TableHead className="w-[60%]">Group</TableHead>
+ <TableHead className="w-[20%] text-center">View</TableHead>
+ <TableHead className="w-[20%] text-center">
+ Download
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody className="relative">
+ {viewerGroupsLoading ? (
+ <TableRow>
+ <TableCell colSpan={3} className="w-full text-center">
+ <Loader2 className="m-auto h-5 w-5 animate-spin" />
+ </TableCell>
+ </TableRow>
+ ) : viewerGroups && viewerGroups.length > 0 ? (
+ viewerGroups?.map((group) => (
+ <TableRow key={group.id}>
+ <TableCell>
+ <div>
+ <p className="font-medium">{group.name}</p>
+ <p className="text-sm text-muted-foreground">
+ {group._count.members} members
+ </p>
+ </div>
+ </TableCell>
+ <TableCell className="text-center">
+ <ToggleGroup
+ type="multiple"
+ value={Object.entries(
+ selectedGroups[group.id] || {},
+ )
+ .filter(([key, value]) => key === "view" && value)
+ .map(([key, _]) => key)}
+ onValueChange={(value) => {
+ const currentPermissions = Object.entries(
+ selectedGroups[group.id] || {},
+ )
+ .filter(([_, val]) => val)
+ .map(([key, _]) => key);
+
+ // Remove view if it's in the current permissions but not in the new value
+ if (
+ currentPermissions.includes("view") &&
+ !value.includes("view")
+ ) {
+ const newPerms = currentPermissions.filter(
+ (p) => p !== "view" && p !== "download",
+ );
+ updatePermissions(group.id, newPerms);
+ } else {
+ // Add view if it's not in the current permissions but in the new value
+ if (
+ !currentPermissions.includes("view") &&
+ value.includes("view")
+ ) {
+ const newPerms = [
+ ...currentPermissions,
+ "view",
+ ];
+ updatePermissions(group.id, newPerms);
+ }
+ }
+ }}
+ className="justify-center"
+ >
+ <ToggleGroupItem
+ value="view"
+ aria-label="Toggle view"
+ size="sm"
+ className={cn(
+ "px-3 py-1 text-muted-foreground hover:ring-1 hover:ring-gray-400 data-[state=on]:bg-foreground data-[state=on]:text-background",
+ selectedGroups[group.id]?.view
+ ? "data-[state=on]:bg-foreground data-[state=on]:text-background"
+ : "",
+ )}
+ >
+ {selectedGroups[group.id]?.view ? (
+ <EyeIcon className="h-5 w-5" />
+ ) : (
+ <EyeOffIcon className="h-5 w-5" />
+ )}
+ </ToggleGroupItem>
+ </ToggleGroup>
+ </TableCell>
+ <TableCell className="text-center">
+ <ToggleGroup
+ type="multiple"
+ value={Object.entries(
+ selectedGroups[group.id] || {},
+ )
+ .filter(
+ ([key, value]) => key === "download" && value,
+ )
+ .map(([key, _]) => key)}
+ onValueChange={(value) => {
+ const currentPermissions = Object.entries(
+ selectedGroups[group.id] || {},
+ )
+ .filter(([_, val]) => val)
+ .map(([key, _]) => key);
+
+ // If trying to add download, ensure view is also added
+ if (
+ value.includes("download") &&
+ !currentPermissions.includes("view")
+ ) {
+ const newPerms = [
+ ...currentPermissions,
+ "view",
+ "download",
+ ];
+ updatePermissions(group.id, newPerms);
+ } else {
+ // Otherwise just update with the new value
+ const newPerms = currentPermissions.filter(
+ (p) => p !== "download",
+ );
+ if (value.includes("download")) {
+ newPerms.push("download");
+ }
+ updatePermissions(group.id, newPerms);
+ }
+ }}
+ className="justify-center"
+ >
+ <ToggleGroupItem
+ value="download"
+ aria-label="Toggle download"
+ size="sm"
+ className={cn(
+ "px-3 py-1 text-muted-foreground hover:ring-1 hover:ring-gray-400 data-[state=on]:bg-foreground data-[state=on]:text-background",
+ selectedGroups[group.id]?.download
+ ? "data-[state=on]:bg-foreground data-[state=on]:text-background"
+ : "",
+ )}
+ >
+ {selectedGroups[group.id]?.download ? (
+ <ArrowDownToLineIcon className="h-5 w-5" />
+ ) : (
+ <CloudDownloadOff className="h-5 w-5" />
+ )}
+ </ToggleGroupItem>
+ </ToggleGroup>
+ </TableCell>
+ </TableRow>
+ ))
+ ) : (
+ <TableRow>
+ <TableCell colSpan={3} className="w-full text-center">
+ No groups found
+ </TableCell>
+ </TableRow>
+ )}
+ </TableBody>
+ </Table>
+ </div>
+ </div>
+ <DialogFooter className="mt-6">
+ <Button type="submit" loading={loading}>
+ Save permissions
+ </Button>
+ </DialogFooter>
+ </form>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsx
index e30c3c7b..94974cfa 100644
--- a/components/documents/add-document-modal.tsx
+++ b/components/documents/add-document-modal.tsx
@@ -10,6 +10,17 @@ import { parsePageId } from "notion-utils";
import { toast } from "sonner";
import { mutate } from "swr";
+import { useAnalytics } from "@/lib/analytics";
+import {
+ DocumentData,
+ createDocument,
+ createNewDocumentVersion,
+} from "@/lib/documents/create-document";
+import { putFile } from "@/lib/files/put-file";
+import { usePlan } from "@/lib/swr/use-billing";
+import useLimits from "@/lib/swr/use-limits";
+import { getSupportedContentType } from "@/lib/utils/get-content-type";
+
import DocumentUpload from "@/components/document-upload";
import { Button } from "@/components/ui/button";
import {
@@ -29,18 +40,14 @@ import {
import { Label } from "@/components/ui/label";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
-import { useAnalytics } from "@/lib/analytics";
-import {
- DocumentData,
- createDocument,
- createNewDocumentVersion,
-} from "@/lib/documents/create-document";
-import { putFile } from "@/lib/files/put-file";
-import { usePlan } from "@/lib/swr/use-billing";
-import useLimits from "@/lib/swr/use-limits";
-import { getSupportedContentType } from "@/lib/utils/get-content-type";
-
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
+import { SetGroupPermissionsModal } from "../datarooms/groups/set-group-permissions-modal";
+
+interface DataroomDocument {
+ id: string;
+ documentId: string;
+ dataroomId: string;
+}
export function AddDocumentModal({
newVersion,
@@ -64,6 +71,12 @@ export function AddDocumentModal({
const [isOpen, setIsOpen] = useState<boolean | undefined>(undefined);
const [currentFile, setCurrentFile] = useState<File | null>(null);
const [notionLink, setNotionLink] = useState<string | null>(null);
+ const [showGroupPermissions, setShowGroupPermissions] = useState(false);
+ const [addedDocumentId, setAddedDocumentId] = useState<string | null>(null);
+ const [addedDataroomDocumentId, setAddedDataroomDocumentId] = useState<
+ string | null
+ >(null);
+ const [fileName, setFileName] = useState<string | null>(null);
const teamInfo = useTeam();
const { canAddDocuments } = useLimits();
const { plan, trial } = usePlan();
@@ -79,6 +92,53 @@ export function AddDocumentModal({
/** current folder name */
const currentFolderPath = router.query.name as string[] | undefined;
+ const addDocumentToDataroom = async ({
+ documentId,
+ folderPathName,
+ }: {
+ documentId: string;
+ folderPathName?: string;
+ }): Promise<Response | undefined> => {
+ try {
+ const response = await fetch(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ documentId: documentId,
+ folderPathName: folderPathName,
+ }),
+ },
+ );
+
+ if (!response.ok) {
+ const { message } = await response.json();
+ toast.error(message);
+ return undefined;
+ }
+
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
+ );
+ mutate(
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/folders/documents/${folderPathName}`,
+ );
+
+ toast.success("Document added to dataroom successfully! 🎉");
+ return response;
+ } catch (error) {
+ toast.error("Error adding document to dataroom.");
+ console.error(
+ "An error occurred while adding document to the dataroom: ",
+ error,
+ );
+ return undefined;
+ }
+ };
+
const handleFileUpload = async (
event: FormEvent<HTMLFormElement>,
): Promise<void> => {
@@ -160,11 +220,20 @@ export function AddDocumentModal({
const document = await response.json();
if (isDataroom && dataroomId) {
- await addDocumentToDataroom({
+ const dataroomResponse = await addDocumentToDataroom({
documentId: document.id,
folderPathName: currentFolderPath?.join("/"),
});
+ if (dataroomResponse?.ok) {
+ const dataroomDocument =
+ (await dataroomResponse.json()) as DataroomDocument;
+ setAddedDocumentId(document.id);
+ setAddedDataroomDocumentId(dataroomDocument.id);
+ setShowGroupPermissions(true);
+ setFileName(document.name);
+ }
+
plausible("documentUploaded");
analytics.capture("Document Added", {
documentId: document.id,
@@ -236,51 +305,6 @@ export function AddDocumentModal({
}
};
- const addDocumentToDataroom = async ({
- documentId,
- folderPathName,
- }: {
- documentId: string;
- folderPathName?: string;
- }) => {
- try {
- const response = await fetch(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- documentId: documentId,
- folderPathName: folderPathName,
- }),
- },
- );
-
- if (!response.ok) {
- const { message } = await response.json();
- toast.error(message);
- return;
- }
-
- mutate(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/documents`,
- );
- mutate(
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${dataroomId}/folders/documents/${folderPathName}`,
- );
-
- toast.success("Document added to dataroom successfully! 🎉");
- } catch (error) {
- toast.error("Error adding document to dataroom.");
- console.error(
- "An error occurred while adding document to the dataroom: ",
- error,
- );
- }
- };
-
const createNotionFileName = () => {
// Extract Notion file name from the URL
const urlSegments = (notionLink as string).split("/")[3];
@@ -341,11 +365,20 @@ export function AddDocumentModal({
const document = await response.json();
if (isDataroom && dataroomId) {
- await addDocumentToDataroom({
+ const dataroomResponse = await addDocumentToDataroom({
documentId: document.id,
folderPathName: currentFolderPath?.join("/"),
});
+ if (dataroomResponse?.ok) {
+ const dataroomDocument =
+ (await dataroomResponse.json()) as DataroomDocument;
+ setAddedDocumentId(document.id);
+ setAddedDataroomDocumentId(dataroomDocument.id);
+ setShowGroupPermissions(true);
+ setFileName(document.name);
+ }
+
plausible("documentUploaded");
plausible("notionDocumentUploaded");
analytics.capture("Document Added", {
@@ -434,154 +467,175 @@ export function AddDocumentModal({
}
return (
- <Dialog open={isOpen} onOpenChange={clearModelStates}>
- <DialogTrigger asChild>{children}</DialogTrigger>
- <DialogContent
- className="border-none bg-transparent text-foreground shadow-none"
- isDocumentDialog
- >
- <DialogTitle className="sr-only">Add Document</DialogTitle>
- <DialogDescription className="sr-only">
- An overlayed modal that can be clicked to upload a document
- </DialogDescription>
- <Tabs defaultValue="document">
- {!newVersion ? (
- <TabsList className="grid w-full grid-cols-2">
- <TabsTrigger value="document">Document</TabsTrigger>
- <TabsTrigger value="notion">Notion Page</TabsTrigger>
- </TabsList>
- ) : (
- <TabsList className="grid w-full grid-cols-1">
- <TabsTrigger value="document">Document</TabsTrigger>
- </TabsList>
- )}
- <TabsContent value="document">
- <Card>
- <CardHeader className="space-y-3">
- <CardTitle>
- {newVersion ? `Upload a new version` : `Share a document`}
- </CardTitle>
- <CardDescription>
- {newVersion ? (
- `After you upload a new version, the existing links will remain the unchanged.`
- ) : (
- <span>
- After you upload the document, create a shareable link.{" "}
- {isFreePlan && !isTrial ? (
- <>
- Upload larger files and more{" "}
- <Link
- href="https://www.papermark.com/help/article/document-types"
- target="_blank"
- className="underline underline-offset-4 transition-all hover:text-muted-foreground/80 hover:dark:text-muted-foreground/80"
- >
- file types
- </Link>{" "}
- with a higher plan.
- </>
- ) : null}
- </span>
- )}
- </CardDescription>
- </CardHeader>
- <CardContent className="space-y-2">
- <form
- encType="multipart/form-data"
- onSubmit={handleFileUpload}
- className="flex flex-col space-y-4"
- >
- <div className="space-y-1">
- <div className="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
- <DocumentUpload
- currentFile={currentFile}
- setCurrentFile={setCurrentFile}
- />
- </div>
- </div>
-
- {!newVersion ? (
- <div className="flex justify-center">
- <button
- type="button"
- className="text-sm text-muted-foreground underline-offset-4 transition-all hover:text-gray-800 hover:underline hover:dark:text-muted-foreground/80"
- onClick={(e) => {
- e.stopPropagation();
- document
- .getElementById("upload-multi-files-zone")
- ?.click();
- clearModelStates();
- }}
- >
- Want to upload multiple files?
- </button>
- </div>
- ) : null}
-
- <div className="flex justify-center">
- <Button
- type="submit"
- className="w-full lg:w-1/2"
- disabled={uploading || !currentFile}
- loading={uploading}
- >
- {uploading ? "Uploading..." : "Upload Document"}
- </Button>
- </div>
- </form>
- </CardContent>
- </Card>
- </TabsContent>
- {!newVersion && (
- <TabsContent value="notion">
+ <>
+ <Dialog open={isOpen} onOpenChange={clearModelStates}>
+ <DialogTrigger asChild>{children}</DialogTrigger>
+ <DialogContent
+ className="border-none bg-transparent text-foreground shadow-none"
+ isDocumentDialog
+ >
+ <DialogTitle className="sr-only">Add Document</DialogTitle>
+ <DialogDescription className="sr-only">
+ An overlayed modal that can be clicked to upload a document
+ </DialogDescription>
+ <Tabs defaultValue="document">
+ {!newVersion ? (
+ <TabsList className="grid w-full grid-cols-2">
+ <TabsTrigger value="document">Document</TabsTrigger>
+ <TabsTrigger value="notion">Notion Page</TabsTrigger>
+ </TabsList>
+ ) : (
+ <TabsList className="grid w-full grid-cols-1">
+ <TabsTrigger value="document">Document</TabsTrigger>
+ </TabsList>
+ )}
+ <TabsContent value="document">
<Card>
<CardHeader className="space-y-3">
- <CardTitle>Share a Notion Page</CardTitle>
+ <CardTitle>
+ {newVersion ? `Upload a new version` : `Share a document`}
+ </CardTitle>
<CardDescription>
- After you submit the Notion link, a shareable link will be
- generated and copied to your clipboard. Just like with a PDF
- document.
+ {newVersion ? (
+ `After you upload a new version, the existing links will remain the unchanged.`
+ ) : (
+ <span>
+ After you upload the document, create a shareable link.{" "}
+ {isFreePlan && !isTrial ? (
+ <>
+ Upload larger files and more{" "}
+ <Link
+ href="https://www.papermark.com/help/article/document-types"
+ target="_blank"
+ className="underline underline-offset-4 transition-all hover:text-muted-foreground/80 hover:dark:text-muted-foreground/80"
+ >
+ file types
+ </Link>{" "}
+ with a higher plan.
+ </>
+ ) : null}
+ </span>
+ )}
</CardDescription>
</CardHeader>
<CardContent className="space-y-2">
<form
encType="multipart/form-data"
- onSubmit={handleNotionUpload}
- className="flex flex-col"
+ onSubmit={handleFileUpload}
+ className="flex flex-col space-y-4"
>
- <div className="space-y-1 pb-8">
- <Label htmlFor="notion-link">Notion Page Link</Label>
- <div className="mt-2">
- <input
- type="text"
- name="notion-link"
- id="notion-link"
- placeholder="notion.site/..."
- className="flex w-full rounded-md border-0 bg-background py-1.5 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
- value={notionLink || ""}
- onChange={(e) => setNotionLink(e.target.value)}
+ <div className="space-y-1">
+ <div className="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
+ <DocumentUpload
+ currentFile={currentFile}
+ setCurrentFile={setCurrentFile}
/>
</div>
- <small className="text-xs text-muted-foreground">
- Your Notion page needs to be shared publicly.
- </small>
</div>
+
+ {!newVersion ? (
+ <div className="flex justify-center">
+ <button
+ type="button"
+ className="text-sm text-muted-foreground underline-offset-4 transition-all hover:text-gray-800 hover:underline hover:dark:text-muted-foreground/80"
+ onClick={(e) => {
+ e.stopPropagation();
+ document
+ .getElementById("upload-multi-files-zone")
+ ?.click();
+ clearModelStates();
+ }}
+ >
+ Want to upload multiple files?
+ </button>
+ </div>
+ ) : null}
+
<div className="flex justify-center">
<Button
type="submit"
className="w-full lg:w-1/2"
- disabled={uploading || !notionLink}
+ disabled={uploading || !currentFile}
loading={uploading}
>
- {uploading ? "Saving..." : "Save Notion Link"}
+ {uploading ? "Uploading..." : "Upload Document"}
</Button>
</div>
</form>
</CardContent>
</Card>
</TabsContent>
- )}
- </Tabs>
- </DialogContent>
- </Dialog>
+ {!newVersion && (
+ <TabsContent value="notion">
+ <Card>
+ <CardHeader className="space-y-3">
+ <CardTitle>Share a Notion Page</CardTitle>
+ <CardDescription>
+ After you submit the Notion link, a shareable link will be
+ generated and copied to your clipboard. Just like with a
+ PDF document.
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-2">
+ <form
+ encType="multipart/form-data"
+ onSubmit={handleNotionUpload}
+ className="flex flex-col"
+ >
+ <div className="space-y-1 pb-8">
+ <Label htmlFor="notion-link">Notion Page Link</Label>
+ <div className="mt-2">
+ <input
+ type="text"
+ name="notion-link"
+ id="notion-link"
+ placeholder="notion.site/..."
+ className="flex w-full rounded-md border-0 bg-background py-1.5 text-foreground shadow-sm ring-1 ring-inset ring-input placeholder:text-muted-foreground focus:ring-2 focus:ring-inset focus:ring-gray-400 sm:text-sm sm:leading-6"
+ value={notionLink || ""}
+ onChange={(e) => setNotionLink(e.target.value)}
+ />
+ </div>
+ <small className="text-xs text-muted-foreground">
+ Your Notion page needs to be shared publicly.
+ </small>
+ </div>
+ <div className="flex justify-center">
+ <Button
+ type="submit"
+ className="w-full lg:w-1/2"
+ disabled={uploading || !notionLink}
+ loading={uploading}
+ >
+ {uploading ? "Saving..." : "Save Notion Link"}
+ </Button>
+ </div>
+ </form>
+ </CardContent>
+ </Card>
+ </TabsContent>
+ )}
+ </Tabs>
+ </DialogContent>
+ </Dialog>
+
+ {showGroupPermissions &&
+ addedDocumentId &&
+ addedDataroomDocumentId &&
+ dataroomId && (
+ <SetGroupPermissionsModal
+ fileName={fileName || ""}
+ open={showGroupPermissions}
+ setOpen={setShowGroupPermissions}
+ dataroomId={dataroomId}
+ documentId={addedDocumentId}
+ dataroomDocumentId={addedDataroomDocumentId}
+ onComplete={() => {
+ setShowGroupPermissions(false);
+ setAddDocumentModalOpen?.(false);
+ }}
+ isAutoOpen
+ />
+ )}
+ </>
);
-}
+}
\ No newline at end of file
diff --git a/components/ui/table.tsx b/components/ui/table.tsx
index 71b086a0..77f524c2 100644
--- a/components/ui/table.tsx
+++ b/components/ui/table.tsx
@@ -1,18 +1,22 @@
import * as React from "react";
+
+
import { cn } from "@/lib/utils";
+
+
+
+
const Table = React.forwardRef<
HTMLTableElement,
React.HTMLAttributes<HTMLTableElement>
>(({ className, ...props }, ref) => (
- <div className="w-full overflow-auto">
- <table
- ref={ref}
- className={cn("w-full caption-bottom text-sm", className)}
- {...props}
- />
- </div>
+ <table
+ ref={ref}
+ className={cn("w-full caption-bottom text-sm", className)}
+ {...props}
+ />
));
Table.displayName = "Table";
@@ -111,4 +115,4 @@ export {
TableRow,
TableCell,
TableCaption,
-};
+};
\ No newline at end of file
diff --git a/lib/swr/use-dataroom-groups.ts b/lib/swr/use-dataroom-groups.ts
index 6aaddd16..09c1abab 100644
--- a/lib/swr/use-dataroom-groups.ts
+++ b/lib/swr/use-dataroom-groups.ts
@@ -14,7 +14,7 @@ import { fetcher } from "@/lib/utils";
import { LinkWithViews } from "../types";
-export default function useDataroomGroups() {
+export default function useDataroomGroups({ documentId }: { documentId?: string } = {}) {
const teamInfo = useTeam();
const router = useRouter();
@@ -24,6 +24,7 @@ export default function useDataroomGroups() {
};
type ViewerGroupWithCount = ViewerGroup & {
+ accessControls: ViewerGroupAccessControls[];
_count: {
members: number;
views: number;
@@ -38,7 +39,8 @@ export default function useDataroomGroups() {
teamInfo?.currentTeam?.id &&
id &&
isDataroom &&
- `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${id}/groups`,
+ `/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${id}/groups${documentId ? `?documentId=${documentId}` : ""
+ }`,
fetcher,
{ dedupingInterval: 30000 },
);
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
index 90c3ba4f..ac3f9fa8 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
@@ -7,13 +7,14 @@ import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { log } from "@/lib/utils";
+import { ItemType } from "@prisma/client";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "GET") {
- // GET /api/teams/:teamId/datarooms/:id/groups
+ // GET /api/teams/:teamId/datarooms/:id/groups?documentId=:documentId
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
@@ -23,6 +24,7 @@ export default async function handle(
teamId: string;
id: string;
};
+ const documentId = req.query?.documentId as string;
const userId = (session.user as CustomUser).id;
try {
@@ -58,6 +60,21 @@ export default async function handle(
createdAt: "desc",
},
include: {
+ ...(documentId ? {
+ accessControls: {
+ where: {
+ itemId: documentId,
+ itemType: ItemType.DATAROOM_DOCUMENT,
+ },
+ select: {
+ id: true,
+ canView: true,
+ canDownload: true,
+ itemId: true,
+ },
+ },
+ }
+ : {}),
_count: {
select: {
members: true,