Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add visitor groups UI and link integration
Cursor Agent79ff5e4906ca
diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.tsindex e2200ea5..a05c6797 100644--- a/app/api/views-dataroom/route.ts+++ b/app/api/views-dataroom/route.ts@@ -149,6 +149,15 @@ export async function POST(request: NextRequest) {name: true,},},+ visitorGroups: {+ select: {+ visitorGroup: {+ select: {+ emails: true,+ },+ },+ },+ },},});@@ -314,10 +323,18 @@ export async function POST(request: NextRequest) {return NextResponse.json({ message: "Access denied" }, { status: 403 });}+ // Build combined allow list from individual emails + visitor groups+ const visitorGroupEmails =+ link.visitorGroups?.flatMap((vg) => vg.visitorGroup.emails) || [];+ const combinedAllowList = [+ ...(link.allowList || []),+ ...visitorGroupEmails,+ ];+// Check if email is allowed to visit the link- if (link.allowList && link.allowList.length > 0) {+ if (combinedAllowList.length > 0) {// Determine if the email or its domain is allowed- const isAllowed = link.allowList.some((allowed) =>+ const isAllowed = combinedAllowList.some((allowed) =>isEmailMatched(email, allowed),);diff --git a/app/api/views/route.ts b/app/api/views/route.tsindex 80ad1a95..75427660 100644--- a/app/api/views/route.ts+++ b/app/api/views/route.ts@@ -123,6 +123,15 @@ export async function POST(request: NextRequest) {agentsEnabled: true,},},+ visitorGroups: {+ select: {+ visitorGroup: {+ select: {+ emails: true,+ },+ },+ },+ },},});@@ -246,10 +255,18 @@ export async function POST(request: NextRequest) {return NextResponse.json({ message: "Access denied" }, { status: 403 });}+ // Build combined allow list from individual emails + visitor groups+ const visitorGroupEmails =+ link.visitorGroups?.flatMap((vg) => vg.visitorGroup.emails) || [];+ const combinedAllowList = [+ ...(link.allowList || []),+ ...visitorGroupEmails,+ ];+// Check if email is allowed to visit the link- if (link.allowList && link.allowList.length > 0) {+ if (combinedAllowList.length > 0) {// Determine if the email or its domain is allowed- const isAllowed = link.allowList.some((allowed) =>+ const isAllowed = combinedAllowList.some((allowed) =>isEmailMatched(email, allowed),);diff --git a/components/links/link-sheet/allow-list-section.tsx b/components/links/link-sheet/allow-list-section.tsxindex 7549096b..e16e8540 100644--- a/components/links/link-sheet/allow-list-section.tsx+++ b/components/links/link-sheet/allow-list-section.tsx@@ -1,11 +1,20 @@import { useEffect, useState } from "react";import { LinkPreset } from "@prisma/client";+import { CheckIcon, UsersIcon, XIcon } from "lucide-react";import { motion } from "motion/react";import { FADE_IN_ANIMATION_SETTINGS } from "@/lib/constants";+import useVisitorGroups from "@/lib/swr/use-visitor-groups";import { sanitizeList } from "@/lib/utils";+import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import {+ Popover,+ PopoverContent,+ PopoverTrigger,+} from "@/components/ui/popover";import { Textarea } from "@/components/ui/textarea";import { DEFAULT_LINK_TYPE } from ".";@@ -30,11 +39,14 @@ export default function AllowListSection({}: LinkUpgradeOptions) => void;presets: LinkPreset | null;}) {- const { emailProtected, allowList } = data;+ const { emailProtected, allowList, visitorGroupIds } = data;+ const { visitorGroups } = useVisitorGroups();// Initialize enabled state based on whether allowList is not null and not empty+ // or if visitor groups are selectedconst [enabled, setEnabled] = useState<boolean>(- !!allowList && allowList.length > 0,+ (!!allowList && allowList.length > 0) ||+ (!!visitorGroupIds && visitorGroupIds.length > 0),);const [allowListInput, setAllowListInput] = useState<string>(allowList?.join("\n") || "",@@ -47,6 +59,8 @@ export default function AllowListSection({setData((prevData) => ({...prevData,allowList: emailProtected && enabled ? newAllowList : [],+ visitorGroupIds:+ emailProtected && enabled ? prevData.visitorGroupIds : [],}));}, [allowListInput, emailProtected, enabled, setData]);@@ -72,6 +86,7 @@ export default function AllowListSection({setData((prevData) => ({...prevData,allowList: [],+ visitorGroupIds: [],}));}};@@ -82,13 +97,35 @@ export default function AllowListSection({setAllowListInput(event.target.value);};+ const toggleVisitorGroup = (groupId: string) => {+ setData((prevData) => {+ const currentIds = prevData.visitorGroupIds || [];+ const newIds = currentIds.includes(groupId)+ ? currentIds.filter((id) => id !== groupId)+ : [...currentIds, groupId];+ return { ...prevData, visitorGroupIds: newIds };+ });+ };++ const removeVisitorGroup = (groupId: string) => {+ setData((prevData) => ({+ ...prevData,+ visitorGroupIds: (prevData.visitorGroupIds || []).filter(+ (id) => id !== groupId,+ ),+ }));+ };++ const selectedGroups =+ visitorGroups?.filter((g) => visitorGroupIds?.includes(g.id)) || [];+return (<div className="pb-5"><div className="flex flex-col space-y-4"><LinkItemtitle="Allow specified viewers"link="https://www.papermark.com/help/article/allow-list"- tooltipContent="Restrict access to a selected group of viewers. Enter allowed emails or domains."+ tooltipContent="Restrict access to a selected group of viewers. Enter allowed emails or domains, or select visitor groups."enabled={enabled}isAllowed={isAllowed}action={handleEnableAllowList}@@ -105,9 +142,108 @@ export default function AllowListSection({{enabled && (<motion.div- className="mt-1 block w-full"+ className="mt-1 block w-full space-y-3"{...FADE_IN_ANIMATION_SETTINGS}>+ {/* Visitor Groups Selector */}+ {visitorGroups && visitorGroups.length > 0 && (+ <div>+ <div className="mb-1.5 flex items-center gap-1.5">+ <UsersIcon className="h-3.5 w-3.5 text-muted-foreground" />+ <span className="text-xs font-medium text-muted-foreground">+ Visitor Groups+ </span>+ </div>++ {/* Selected groups as badges */}+ {selectedGroups.length > 0 && (+ <div className="mb-2 flex flex-wrap gap-1.5">+ {selectedGroups.map((group) => (+ <Badge+ key={group.id}+ variant="secondary"+ className="gap-1 pr-1"+ >+ {group.name}+ <span className="text-muted-foreground">+ ({group.emails.length})+ </span>+ <button+ type="button"+ onClick={() => removeVisitorGroup(group.id)}+ className="ml-0.5 rounded-full p-0.5 hover:bg-muted"+ >+ <XIcon className="h-3 w-3" />+ </button>+ </Badge>+ ))}+ </div>+ )}++ <Popover>+ <PopoverTrigger asChild>+ <Button+ type="button"+ variant="outline"+ size="sm"+ className="w-full justify-start text-muted-foreground"+ >+ <UsersIcon className="mr-2 h-3.5 w-3.5" />+ {selectedGroups.length > 0+ ? `${selectedGroups.length} group${selectedGroups.length > 1 ? "s" : ""} selected`+ : "Select visitor groups..."}+ </Button>+ </PopoverTrigger>+ <PopoverContent className="w-72 p-1" align="start">+ <div className="max-h-60 overflow-y-auto">+ {visitorGroups.map((group) => {+ const isSelected = visitorGroupIds?.includes(group.id);+ return (+ <button+ key={group.id}+ type="button"+ className="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-muted"+ onClick={() => toggleVisitorGroup(group.id)}+ >+ <div+ className={`flex h-4 w-4 items-center justify-center rounded-sm border ${+ isSelected+ ? "border-primary bg-primary text-primary-foreground"+ : "border-muted-foreground/30"+ }`}+ >+ {isSelected && (+ <CheckIcon className="h-3 w-3" />+ )}+ </div>+ <div className="min-w-0 flex-1">+ <div className="truncate font-medium">+ {group.name}+ </div>+ <div className="text-xs text-muted-foreground">+ {group.emails.length}{" "}+ {group.emails.length === 1+ ? "entry"+ : "entries"}+ </div>+ </div>+ </button>+ );+ })}+ </div>+ </PopoverContent>+ </Popover>++ <div className="my-2 flex items-center gap-2">+ <div className="h-px flex-1 bg-border" />+ <span className="text-xs text-muted-foreground">+ plus individual emails+ </span>+ <div className="h-px flex-1 bg-border" />+ </div>+ </div>+ )}+<TextareaclassName="focus:ring-inset"rows={5}diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex c671f9e6..7d7dd239 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -66,6 +66,7 @@ export const DEFAULT_LINK_PROPS = (allowDownload: false,allowList: [],denyList: [],+ visitorGroupIds: [],enableNotification: true,enableFeedback: false,enableScreenshotProtection: false,@@ -110,6 +111,7 @@ export type DEFAULT_LINK_TYPE = {allowDownload: boolean;allowList: string[];denyList: string[];+ visitorGroupIds: string[];enableNotification: boolean;enableFeedback: boolean;enableScreenshotProtection: boolean;diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex e744a842..04fc588e 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -369,6 +369,10 @@ export default function LinksTable({allowDownload: link.allowDownload ? link.allowDownload : false,allowList: link.allowList,denyList: link.denyList,+ visitorGroupIds:+ link.visitorGroups?.map(+ (vg: { visitorGroupId: string }) => vg.visitorGroupId,+ ) || [],enableNotification: link.enableNotification? link.enableNotification: false,diff --git a/components/visitors/visitor-group-modal.tsx b/components/visitors/visitor-group-modal.tsxnew file mode 100644index 00000000..4bbc25c0--- /dev/null+++ b/components/visitors/visitor-group-modal.tsx@@ -0,0 +1,153 @@+import { useEffect, useState } from "react";++import { useTeam } from "@/context/team-context";+import { toast } from "sonner";+import { mutate } from "swr";++import { sanitizeList } from "@/lib/utils";++import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from "@/components/ui/dialog";+import { Input } from "@/components/ui/input";+import { Label } from "@/components/ui/label";+import { Textarea } from "@/components/ui/textarea";++import { VisitorGroupWithCount } from "@/lib/swr/use-visitor-groups";++export function VisitorGroupModal({+ open,+ setOpen,+ existingGroup,+}: {+ open: boolean;+ setOpen: React.Dispatch<React.SetStateAction<boolean>>;+ existingGroup?: VisitorGroupWithCount | null;+}) {+ const [groupName, setGroupName] = useState<string>("");+ const [emailsInput, setEmailsInput] = useState<string>("");+ const [loading, setLoading] = useState<boolean>(false);++ const teamInfo = useTeam();++ useEffect(() => {+ if (existingGroup) {+ setGroupName(existingGroup.name);+ setEmailsInput(existingGroup.emails.join("\n"));+ } else {+ setGroupName("");+ setEmailsInput("");+ }+ }, [existingGroup, open]);++ const handleSubmit = async (event: React.FormEvent) => {+ event.preventDefault();+ event.stopPropagation();++ if (!groupName || groupName.trim().length < 2) {+ toast.error("Please provide a group name with at least 2 characters.");+ return;+ }++ setLoading(true);++ const emails = sanitizeList(emailsInput);++ try {+ const url = existingGroup+ ? `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups/${existingGroup.id}`+ : `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups`;++ const response = await fetch(url, {+ method: existingGroup ? "PUT" : "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ name: groupName.trim(), emails }),+ });++ if (!response.ok) {+ const data = await response.json();+ toast.error(data.error || "Failed to save visitor group.");+ setLoading(false);+ return;+ }++ toast.success(+ existingGroup+ ? "Visitor group updated successfully!"+ : "Visitor group created successfully!",+ );++ mutate(+ `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups`,+ );+ } catch (error) {+ toast.error("Error saving visitor group. Please try again.");+ } finally {+ setLoading(false);+ setOpen(false);+ }+ };++ return (+ <Dialog open={open} onOpenChange={setOpen}>+ <DialogContent className="sm:max-w-[500px]">+ <DialogHeader className="text-start">+ <DialogTitle>+ {existingGroup ? "Edit Visitor Group" : "Create Visitor Group"}+ </DialogTitle>+ <DialogDescription>+ {existingGroup+ ? "Update the group name and email list. Changes will apply to all links using this group."+ : "Create a named group of emails and domains. You can then apply this group to document and data room links."}+ </DialogDescription>+ </DialogHeader>+ <form onSubmit={handleSubmit}>+ <div className="space-y-4">+ <div>+ <Label htmlFor="group-name" className="opacity-80">+ Group Name+ </Label>+ <Input+ id="group-name"+ placeholder="e.g., Series A Investors"+ className="mt-1 w-full"+ value={groupName}+ onChange={(e) => setGroupName(e.target.value)}+ />+ </div>+ <div>+ <Label htmlFor="group-emails" className="opacity-80">+ Emails & Domains+ </Label>+ <Textarea+ id="group-emails"+ className="mt-1 w-full focus:ring-inset"+ rows={6}+ placeholder={`Enter emails or domains, one per line, e.g.+ value={emailsInput}+ onChange={(e) => setEmailsInput(e.target.value)}+ />+ <p className="mt-1 text-xs text-muted-foreground">+ Use @domain.com to allow all emails from a domain.+ </p>+ </div>+ </div>+ <DialogFooter className="mt-4">+ <Button type="submit" loading={loading} className="h-9 w-full">+ {existingGroup ? "Update Group" : "Create Group"}+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>+ );+}diff --git a/components/visitors/visitor-groups-section.tsx b/components/visitors/visitor-groups-section.tsxnew file mode 100644index 00000000..89be392d--- /dev/null+++ b/components/visitors/visitor-groups-section.tsx@@ -0,0 +1,187 @@+import { useState } from "react";++import { useTeam } from "@/context/team-context";+import {+ MailIcon,+ MoreVerticalIcon,+ PencilIcon,+ PlusIcon,+ TrashIcon,+ UsersIcon,+} from "lucide-react";+import { toast } from "sonner";+import { mutate } from "swr";++import useVisitorGroups, {+ VisitorGroupWithCount,+} from "@/lib/swr/use-visitor-groups";++import { Badge } from "@/components/ui/badge";+import { Button } from "@/components/ui/button";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { Skeleton } from "@/components/ui/skeleton";++import { VisitorGroupModal } from "./visitor-group-modal";++export function VisitorGroupsSection() {+ const { visitorGroups, loading } = useVisitorGroups();+ const [modalOpen, setModalOpen] = useState(false);+ const [editingGroup, setEditingGroup] =+ useState<VisitorGroupWithCount | null>(null);+ const teamInfo = useTeam();++ const handleEdit = (group: VisitorGroupWithCount) => {+ setEditingGroup(group);+ setModalOpen(true);+ };++ const handleCreate = () => {+ setEditingGroup(null);+ setModalOpen(true);+ };++ const handleDelete = async (group: VisitorGroupWithCount) => {+ if (+ !confirm(+ `Are you sure you want to delete "${group.name}"? This cannot be undone.`,+ )+ ) {+ return;+ }++ try {+ const response = await fetch(+ `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups/${group.id}`,+ { method: "DELETE" },+ );++ if (!response.ok) {+ const data = await response.json();+ toast.error(data.error || "Failed to delete visitor group.");+ return;+ }++ toast.success("Visitor group deleted successfully.");+ mutate(`/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups`);+ } catch (error) {+ toast.error("Error deleting visitor group. Please try again.");+ }+ };++ return (+ <div className="space-y-4">+ <div className="flex items-center justify-between">+ <div>+ <h3 className="text-lg font-semibold text-foreground">+ Visitor Groups+ </h3>+ <p className="text-sm text-muted-foreground">+ Create groups of emails and domains, then apply them to link allow+ lists.+ </p>+ </div>+ <Button onClick={handleCreate} size="sm" className="gap-1.5">+ <PlusIcon className="h-4 w-4" />+ Create Group+ </Button>+ </div>++ {loading ? (+ <div className="space-y-3">+ {[...Array(3)].map((_, i) => (+ <Skeleton key={i} className="h-20 w-full rounded-lg" />+ ))}+ </div>+ ) : !visitorGroups || visitorGroups.length === 0 ? (+ <div className="rounded-lg border border-dashed border-gray-300 p-8 text-center dark:border-gray-700">+ <UsersIcon className="mx-auto h-10 w-10 text-muted-foreground/50" />+ <h4 className="mt-2 text-sm font-medium text-foreground">+ No visitor groups yet+ </h4>+ <p className="mt-1 text-sm text-muted-foreground">+ Create your first visitor group to manage access across multiple+ links.+ </p>+ <Button+ onClick={handleCreate}+ variant="outline"+ size="sm"+ className="mt-4 gap-1.5"+ >+ <PlusIcon className="h-4 w-4" />+ Create Group+ </Button>+ </div>+ ) : (+ <div className="grid gap-3">+ {visitorGroups.map((group) => (+ <div+ key={group.id}+ className="flex items-center justify-between rounded-lg border border-gray-200 bg-white p-4 transition-colors hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-900 dark:hover:bg-gray-800/50"+ >+ <div className="min-w-0 flex-1">+ <div className="flex items-center gap-2">+ <UsersIcon className="h-4 w-4 text-muted-foreground" />+ <h4 className="truncate text-sm font-medium text-foreground">+ {group.name}+ </h4>+ </div>+ <div className="mt-1 flex flex-wrap items-center gap-2">+ <Badge variant="secondary" className="gap-1">+ <MailIcon className="h-3 w-3" />+ {group.emails.length}{" "}+ {group.emails.length === 1 ? "entry" : "entries"}+ </Badge>+ {group._count.links > 0 && (+ <Badge variant="outline" className="gap-1">+ {group._count.links}{" "}+ {group._count.links === 1 ? "link" : "links"}+ </Badge>+ )}+ {group.emails.length > 0 && (+ <span className="truncate text-xs text-muted-foreground">+ {group.emails.slice(0, 3).join(", ")}+ {group.emails.length > 3 &&+ ` +${group.emails.length - 3} more`}+ </span>+ )}+ </div>+ </div>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button variant="ghost" size="icon" className="h-8 w-8">+ <MoreVerticalIcon className="h-4 w-4" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem onClick={() => handleEdit(group)}>+ <PencilIcon className="mr-2 h-4 w-4" />+ Edit+ </DropdownMenuItem>+ <DropdownMenuItem+ onClick={() => handleDelete(group)}+ className="text-destructive focus:text-destructive"+ >+ <TrashIcon className="mr-2 h-4 w-4" />+ Delete+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ ))}+ </div>+ )}++ <VisitorGroupModal+ open={modalOpen}+ setOpen={setModalOpen}+ existingGroup={editingGroup}+ />+ </div>+ );+}diff --git a/lib/types.ts b/lib/types.tsindex abd56db5..8803e642 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -67,6 +67,7 @@ export interface LinkWithViews extends Link {customFields: CustomField[];tags: TagProps[];uploadFolderName: string | undefined;+ visitorGroups?: { visitorGroupId: string }[];}export interface LinkWithDocument extends Link {diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex 89100b1b..dc8dfb01 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -406,6 +406,11 @@ export default async function handle(},include: {customFields: true,+ visitorGroups: {+ select: {+ visitorGroupId: true,+ },+ },views: {orderBy: {viewedAt: "desc",@@ -416,6 +421,27 @@ export default async function handle(},},});++ // Update visitor groups (replace all)+ if (linkData.visitorGroupIds !== undefined) {+ // Delete existing visitor group associations+ await tx.linkVisitorGroup.deleteMany({+ where: { linkId: id },+ });++ // Create new associations+ if (linkData.visitorGroupIds?.length > 0) {+ await tx.linkVisitorGroup.createMany({+ data: linkData.visitorGroupIds.map(+ (visitorGroupId: string) => ({+ linkId: id,+ visitorGroupId,+ }),+ ),+ skipDuplicates: true,+ });+ }+ }if (linkData.tags?.length) {// Remove only tags that are not in the new listawait tx.tagItem.deleteMany({diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 73e751ee..3a1b0c2f 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -237,9 +237,26 @@ export default async function handler(},},}),+ // Connect visitor groups for allow-list+ ...(linkData.visitorGroupIds?.length > 0 && {+ visitorGroups: {+ createMany: {+ data: linkData.visitorGroupIds.map(+ (visitorGroupId: string) => ({+ visitorGroupId,+ }),+ ),+ },+ },+ }),},include: {customFields: true,+ visitorGroups: {+ select: {+ visitorGroupId: true,+ },+ },},});diff --git a/pages/api/teams/[teamId]/datarooms/[id]/links.ts b/pages/api/teams/[teamId]/datarooms/[id]/links.tsindex d098c9f2..48522e4f 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/links.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/links.ts@@ -64,6 +64,9 @@ export default async function handle(},},customFields: true,+ visitorGroups: {+ select: { visitorGroupId: true },+ },_count: {select: { views: { where: { viewType: "DATAROOM_VIEW" } } },},diff --git a/pages/api/teams/[teamId]/documents/[id]/links.ts b/pages/api/teams/[teamId]/documents/[id]/links.tsindex 77cb7a13..5aba8765 100644--- a/pages/api/teams/[teamId]/documents/[id]/links.ts+++ b/pages/api/teams/[teamId]/documents/[id]/links.ts@@ -85,6 +85,9 @@ export default async function handle(},orderBy: { orderIndex: "asc" },},+ visitorGroups: {+ select: { visitorGroupId: true },+ },_count: { select: { views: true } },},},diff --git a/pages/visitors/index.tsx b/pages/visitors/index.tsxindex 49e1a6d9..2e143b53 100644--- a/pages/visitors/index.tsx+++ b/pages/visitors/index.tsx@@ -1,7 +1,5 @@import { useRouter } from "next/router";--import { useEffect, useState } from "react";import { usePlan } from "@/lib/swr/use-billing";@@ -10,7 +8,9 @@ import useViewers from "@/lib/swr/use-viewers";import AppLayout from "@/components/layouts/app";import { SearchBoxPersisted } from "@/components/search-box";import { Separator } from "@/components/ui/separator";+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { ContactsTable } from "@/components/visitors/contacts-table";+import { VisitorGroupsSection } from "@/components/visitors/visitor-groups-section";export default function Visitors() {const router = useRouter();@@ -19,6 +19,9 @@ export default function Visitors() {const [pageSize, setPageSize] = useState(10);const [sortBy, setSortBy] = useState("lastViewed");const [sortOrder, setSortOrder] = useState("desc");+ const [activeTab, setActiveTab] = useState(+ (router.query.tab as string) || "visitors",+ );const { viewers, pagination, isValidating } = useViewers(currentPage,@@ -50,6 +53,21 @@ export default function Visitors() {if (isFree && !isTrial) router.push("/documents");}, [isTrial, isFree]);+ useEffect(() => {+ if (router.query.tab) {+ setActiveTab(router.query.tab as string);+ }+ }, [router.query.tab]);++ const handleTabChange = (value: string) => {+ setActiveTab(value);+ router.push(+ { pathname: router.pathname, query: { ...router.query, tab: value } },+ undefined,+ { shallow: true },+ );+ };+return (<AppLayout><div className="p-4 pb-0 sm:m-4 sm:py-4">@@ -59,33 +77,46 @@ export default function Visitors() {All visitors</h2><p className="text-xs text-muted-foreground sm:text-sm">- See all your visitors in one place.+ See all your visitors and manage visitor groups.</p></div></section>- <div className="mb-2 flex justify-end gap-x-2">- <div className="relative w-full sm:max-w-xs">- <SearchBoxPersisted- loading={isValidating}- placeholder="Search visitors..."- inputClassName="h-10"- />- </div>- </div>-- <Separator className="bg-gray-200 dark:bg-gray-800" />- </div>-- <div className="relative p-4 pt-0 sm:mx-4 sm:mt-4">- <ContactsTable- viewers={viewers}- pagination={pagination}- sorting={{ sortBy, sortOrder }}- onPageChange={handlePageChange}- onPageSizeChange={handlePageSizeChange}- onSortChange={handleSortChange}- />+ <Tabs value={activeTab} onValueChange={handleTabChange}>+ <TabsList className="mb-4">+ <TabsTrigger value="visitors">Visitors</TabsTrigger>+ <TabsTrigger value="groups">Visitor Groups</TabsTrigger>+ </TabsList>++ <TabsContent value="visitors">+ <div className="mb-2 flex justify-end gap-x-2">+ <div className="relative w-full sm:max-w-xs">+ <SearchBoxPersisted+ loading={isValidating}+ placeholder="Search visitors..."+ inputClassName="h-10"+ />+ </div>+ </div>++ <Separator className="bg-gray-200 dark:bg-gray-800" />++ <div className="relative pt-4">+ <ContactsTable+ viewers={viewers}+ pagination={pagination}+ sorting={{ sortBy, sortOrder }}+ onPageChange={handlePageChange}+ onPageSizeChange={handlePageSizeChange}+ onSortChange={handleSortChange}+ />+ </div>+ </TabsContent>++ <TabsContent value="groups">+ <VisitorGroupsSection />+ </TabsContent>+ </Tabs></div></AppLayout>);