Skip to content

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

feat: add group link

Marc Seitz299976f37a92
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 2a112b39..d139f18f 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -3,7 +3,9 @@ import { useRouter } from "next/router";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import { useTeam } from "@/context/team-context";
-import { LinkType } from "@prisma/client";
+import { LinkAudienceType, LinkType } from "@prisma/client";
+import { PlusIcon, RefreshCwIcon } from "lucide-react";
+import { Link } from "mupdf";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -11,6 +13,13 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ScrollArea } from "@/components/ui/scroll-area";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import {
Sheet,
@@ -19,9 +28,12 @@ import {
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
+import { ButtonTooltip } from "@/components/ui/tooltip";
import { useAnalytics } from "@/lib/analytics";
import { usePlan } from "@/lib/swr/use-billing";
+import useDataroomGroups from "@/lib/swr/use-dataroom-groups";
import { useDomains } from "@/lib/swr/use-domains";
import { LinkWithViews, WatermarkConfig } from "@/lib/types";
import { convertDataUrlToFile, uploadImage } from "@/lib/utils";
@@ -56,6 +68,8 @@ export const DEFAULT_LINK_PROPS = (linkType: LinkType) => ({
showBanner: linkType === LinkType.DOCUMENT_LINK ? true : false,
enableWatermark: false,
watermarkConfig: null,
+ audienceType: LinkAudienceType.GENERAL,
+ groupId: null,
});
export type DEFAULT_LINK_TYPE = {
@@ -85,6 +99,8 @@ export type DEFAULT_LINK_TYPE = {
showBanner: boolean;
enableWatermark: boolean;
watermarkConfig: WatermarkConfig | null;
+ audienceType: LinkAudienceType;
+ groupId: string | null;
};
export default function LinkSheet({
@@ -101,6 +117,11 @@ export default function LinkSheet({
existingLinks?: LinkWithViews[];
}) {
const { domains } = useDomains();
+ const {
+ viewerGroups,
+ loading: isLoadingGroups,
+ mutate: mutateGroups,
+ } = useDataroomGroups();
const teamInfo = useTeam();
const { plan } = usePlan();
const analytics = useAnalytics();
@@ -211,7 +232,9 @@ export default function LinkSheet({
<SheetContent className="flex w-[90%] flex-col justify-between border-l border-gray-200 bg-background px-4 text-foreground dark:border-gray-800 dark:bg-gray-900 sm:w-[600px] sm:max-w-2xl md:px-5">
<SheetHeader className="text-start">
<SheetTitle>
- {currentLink ? "Edit link" : "Create a new link"}
+ {currentLink
+ ? `Edit ${currentLink.audienceType === LinkAudienceType.GROUP ? "group" : "general"} link`
+ : "Create a new link"}
</SheetTitle>
</SheetHeader>
@@ -220,49 +243,184 @@ export default function LinkSheet({
<div className="h-0 flex-1">
<div className="flex flex-1 flex-col justify-between">
<div className="divide-y divide-gray-200">
- <div className="space-y-6 pb-5 pt-2">
- <div className="space-y-2">
- <Label htmlFor="link-name">Link Name</Label>
- <div className="mt-2">
- <Input
- type="text"
- name="link-name"
- id="link-name"
- placeholder="Recipient's Organization"
- value={data.name || ""}
- className="focus:ring-inset"
- onChange={(e) =>
- setData({ ...data, name: e.target.value })
- }
+ <Tabs
+ value={data.audienceType}
+ onValueChange={(value) =>
+ setData({
+ ...data,
+ audienceType: value as LinkAudienceType,
+ })
+ }
+ >
+ {!!!currentLink ? (
+ <TabsList className="grid w-full grid-cols-2">
+ <TabsTrigger value={LinkAudienceType.GENERAL}>
+ General
+ </TabsTrigger>
+ <TabsTrigger value={LinkAudienceType.GROUP}>
+ Group
+ </TabsTrigger>
+ </TabsList>
+ ) : null}
+
+ <TabsContent value={LinkAudienceType.GENERAL}>
+ {/* GENERAL LINK */}
+ <div className="space-y-6 pb-5 pt-2">
+ <div className="space-y-2">
+ <Label htmlFor="link-name">Link Name</Label>
+
+ <Input
+ type="text"
+ name="link-name"
+ id="link-name"
+ placeholder="Recipient's Organization"
+ value={data.name || ""}
+ className="focus:ring-inset"
+ onChange={(e) =>
+ setData({ ...data, name: e.target.value })
+ }
+ />
+ </div>
+
+ <div className="space-y-2">
+ <DomainSection
+ {...{ data, setData, domains }}
+ plan={plan}
+ linkType={linkType}
+ editLink={!!currentLink}
+ />
+ </div>
+
+ <div className="relative flex items-center">
+ <Separator className="absolute bg-muted-foreground" />
+ <div className="relative mx-auto">
+ <span className="bg-background px-2 text-sm text-muted-foreground dark:bg-gray-900">
+ Link Options
+ </span>
+ </div>
+ </div>
+
+ <LinkOptions
+ data={data}
+ setData={setData}
+ linkType={linkType}
+ editLink={!!currentLink}
/>
</div>
- </div>
-
- <div className="space-y-2">
- <DomainSection
- {...{ data, setData, domains }}
- plan={plan}
- linkType={linkType}
- editLink={!!currentLink}
- />
- </div>
-
- <div className="relative flex items-center">
- <Separator className="absolute bg-muted-foreground" />
- <div className="relative mx-auto">
- <span className="bg-background px-2 text-sm text-muted-foreground dark:bg-gray-900">
- Link Options
- </span>
+ </TabsContent>
+
+ <TabsContent value={LinkAudienceType.GROUP}>
+ {/* GROUP LINK */}
+ <div className="space-y-6 pb-5 pt-2">
+ <div className="space-y-2">
+ <div className="flex w-full items-center justify-between">
+ <Label htmlFor="group-id">Group </Label>
+ <ButtonTooltip content="Refresh groups">
+ <Button
+ size="icon"
+ variant="ghost"
+ className="h-6"
+ onClick={async (e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ await mutateGroups();
+ }}
+ >
+ <RefreshCwIcon className="h-4 w-4" />
+ </Button>
+ </ButtonTooltip>
+ </div>
+ <Select
+ onValueChange={(value) => {
+ if (value === "add_group") {
+ // Open the group sheet
+ console.log("add_group redirect");
+ return;
+ }
+
+ setData({ ...data, groupId: value });
+ }}
+ defaultValue={data.groupId ?? undefined}
+ >
+ <SelectTrigger className="focus:ring-offset-3 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-gray-400 sm:text-sm sm:leading-6">
+ <SelectValue placeholder="Select an group" />
+ </SelectTrigger>
+ <SelectContent>
+ {isLoadingGroups ? (
+ <SelectItem value="loading" disabled>
+ Loading groups...
+ </SelectItem>
+ ) : viewerGroups && viewerGroups.length > 0 ? (
+ viewerGroups.map(({ id, name, _count }) => (
+ <SelectItem key={id} value={id}>
+ {name}{" "}
+ <span className="text-muted-foreground">
+ ({_count.members} members)
+ </span>
+ </SelectItem>
+ ))
+ ) : (
+ <SelectItem value="no-groups" disabled>
+ No groups available
+ </SelectItem>
+ )}
+ </SelectContent>
+ </Select>
+ </div>
+
+ <div className="space-y-2">
+ <Label htmlFor="link-name">Link Name</Label>
+
+ <Input
+ type="text"
+ name="link-name"
+ id="link-name"
+ placeholder={
+ viewerGroups?.find(
+ (group) => group.id === data.groupId,
+ )?.name
+ ? `${
+ viewerGroups?.find(
+ (group) => group.id === data.groupId,
+ )?.name
+ } Link`
+ : "Group Link"
+ }
+ value={data.name || ""}
+ className="focus:ring-inset"
+ onChange={(e) =>
+ setData({ ...data, name: e.target.value })
+ }
+ />
+ </div>
+
+ <div className="space-y-2">
+ <DomainSection
+ {...{ data, setData, domains }}
+ plan={plan}
+ linkType={linkType}
+ editLink={!!currentLink}
+ />
+ </div>
+
+ <div className="relative flex items-center">
+ <Separator className="absolute bg-muted-foreground" />
+ <div className="relative mx-auto">
+ <span className="bg-background px-2 text-sm text-muted-foreground dark:bg-gray-900">
+ Link Options
+ </span>
+ </div>
+ </div>
+
+ <LinkOptions
+ data={data}
+ setData={setData}
+ linkType={linkType}
+ editLink={!!currentLink}
+ />
</div>
- </div>
-
- <LinkOptions
- data={data}
- setData={setData}
- linkType={linkType}
- editLink={!!currentLink}
- />
- </div>
+ </TabsContent>
+ </Tabs>
</div>
</div>
</div>
diff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsx
index 8f5ccde3..36ecbea4 100644
--- a/components/links/link-sheet/link-options.tsx
+++ b/components/links/link-sheet/link-options.tsx
@@ -1,6 +1,6 @@
import { useState } from "react";
-import { LinkType } from "@prisma/client";
+import { LinkAudienceType, LinkType } from "@prisma/client";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import { DEFAULT_LINK_TYPE } from "@/components/links/link-sheet";
@@ -93,26 +93,30 @@ export const LinkOptions = ({
isAllowed={isTrial || isPro || isBusiness || isDatarooms}
handleUpgradeStateChange={handleUpgradeStateChange}
/>
- <AllowListSection
- {...{ data, setData }}
- isAllowed={
- isTrial ||
- (isPro && allowAdvancedLinkControls) ||
- isBusiness ||
- isDatarooms
- }
- handleUpgradeStateChange={handleUpgradeStateChange}
- />
- <DenyListSection
- {...{ data, setData }}
- isAllowed={
- isTrial ||
- (isPro && allowAdvancedLinkControls) ||
- isBusiness ||
- isDatarooms
- }
- handleUpgradeStateChange={handleUpgradeStateChange}
- />
+ {data.audienceType === LinkAudienceType.GENERAL ? (
+ <AllowListSection
+ {...{ data, setData }}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ ) : null}
+ {data.audienceType === LinkAudienceType.GENERAL ? (
+ <DenyListSection
+ {...{ data, setData }}
+ isAllowed={
+ isTrial ||
+ (isPro && allowAdvancedLinkControls) ||
+ isBusiness ||
+ isDatarooms
+ }
+ handleUpgradeStateChange={handleUpgradeStateChange}
+ />
+ ) : null}
<PasswordSection {...{ data, setData }} />
<ScreenshotProtectionSection
{...{ data, setData }}
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index e768b969..e36a4ac8 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -3,8 +3,8 @@ import { useRouter } from "next/router";
import { useState } from "react";
import { useTeam } from "@/context/team-context";
-import { DocumentVersion } from "@prisma/client";
-import { EyeIcon, Settings2Icon } from "lucide-react";
+import { DocumentVersion, LinkAudienceType } from "@prisma/client";
+import { EyeIcon, GlobeIcon, Settings2Icon, UsersIcon } from "lucide-react";
import { toast } from "sonner";
import { mutate } from "swr";
@@ -41,6 +41,7 @@ import BarChart from "../shared/icons/bar-chart";
import ChevronDown from "../shared/icons/chevron-down";
import MoreHorizontal from "../shared/icons/more-horizontal";
import { BadgeTooltip, ButtonTooltip } from "../ui/tooltip";
+import { LinkBadge } from "./link-badge";
import LinkSheet, {
DEFAULT_LINK_PROPS,
type DEFAULT_LINK_TYPE,
@@ -104,6 +105,8 @@ export default function LinksTable({
showBanner: link.showBanner ?? false,
enableWatermark: link.enableWatermark ?? false,
watermarkConfig: link.watermarkConfig as WatermarkConfig | null,
+ audienceType: link.audienceType,
+ groupId: link.groupId,
});
//wait for dropdown to close before opening the link sheet
setTimeout(() => {
@@ -242,8 +245,9 @@ export default function LinksTable({
<Collapsible key={link.id} asChild>
<>
<TableRow key={link.id} className="group/row">
- <TableCell className="w-[220px] truncate font-medium">
- {link.name || `Link #${link.id.slice(-5)}`}{" "}
+ <TableCell className="w-[250px] truncate font-medium">
+ {link.name || `Link #${link.id.slice(-5)}`}
+
{link.domainId && hasFreePlan ? (
<span className="ml-2 rounded-full bg-destructive px-2.5 py-0.5 text-xs text-foreground ring-1 ring-destructive">
Inactive
diff --git a/lib/swr/use-dataroom-groups.ts b/lib/swr/use-dataroom-groups.ts
index 48241399..323ecb56 100644
--- a/lib/swr/use-dataroom-groups.ts
+++ b/lib/swr/use-dataroom-groups.ts
@@ -18,21 +18,29 @@ export default function useDataroomGroups() {
id: string;
};
- const { data: viewerGroups, error } = useSWR<ViewerGroup[]>(
+ type ViewerGroupWithCount = ViewerGroup & {
+ _count: {
+ members: number;
+ };
+ };
+
+ const {
+ data: viewerGroups,
+ error,
+ mutate,
+ } = useSWR<ViewerGroupWithCount[]>(
teamInfo?.currentTeam?.id &&
id &&
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/${id}/groups`,
fetcher,
- {
- revalidateOnFocus: false,
- dedupingInterval: 30000,
- },
+ { dedupingInterval: 30000 },
);
return {
viewerGroups,
loading: !viewerGroups && !error,
error,
+ mutate,
};
}
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index dfd40c4b..8473055e 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -1,5 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
+import { LinkAudienceType } from "@prisma/client";
import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
@@ -145,6 +146,11 @@ export default async function handler(
metaImage: linkData.metaImage || null,
allowList: linkData.allowList,
denyList: linkData.denyList,
+ audienceType: linkData.audienceType,
+ groupId:
+ linkData.audienceType === LinkAudienceType.GROUP
+ ? linkData.groupId
+ : null,
...(linkData.enableQuestion && {
enableQuestion: linkData.enableQuestion,
feedback: {
@@ -174,6 +180,8 @@ export default async function handler(
views: [],
};
+ console.log("linkWithView", linkWithView);
+
if (!linkWithView) {
return res.status(404).json({ error: "Link not found" });
}
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
index 81e04f41..eb5402a4 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/groups/index.ts
@@ -57,6 +57,13 @@ export default async function handle(
orderBy: {
createdAt: "desc",
},
+ include: {
+ _count: {
+ select: {
+ members: true,
+ },
+ },
+ },
},
},
});