Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: improve group layout
Marc Seitzb9cc5194fd37
diff --git a/components/visitors/visitor-group-modal.tsx b/components/visitors/visitor-group-modal.tsxindex 4bbc25c0..01954769 100644--- a/components/visitors/visitor-group-modal.tsx+++ b/components/visitors/visitor-group-modal.tsx@@ -1,10 +1,18 @@import { useEffect, useState } from "react";+import Link from "next/link";import { useTeam } from "@/context/team-context";+import { LinkType } from "@prisma/client";+import {+ ExternalLinkIcon,+ FileTextIcon,+ FolderKanbanIcon,+} from "lucide-react";import { toast } from "sonner";import { mutate } from "swr";+import useSWR from "swr";-import { sanitizeList } from "@/lib/utils";+import { fetcher, sanitizeList } from "@/lib/utils";import { Button } from "@/components/ui/button";import {@@ -21,6 +29,23 @@ import { Textarea } from "@/components/ui/textarea";import { VisitorGroupWithCount } from "@/lib/swr/use-visitor-groups";+type VisitorGroupLink = {+ id: string;+ link: {+ id: string;+ name: string | null;+ linkType: LinkType;+ documentId: string | null;+ dataroomId: string | null;+ document: { id: string; name: string } | null;+ dataroom: { id: string; name: string } | null;+ };+};++type VisitorGroupDetail = VisitorGroupWithCount & {+ links: VisitorGroupLink[];+};+export function VisitorGroupModal({open,setOpen,@@ -35,6 +60,14 @@ export function VisitorGroupModal({const [loading, setLoading] = useState<boolean>(false);const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;+ const { data: existingGroupDetails, isLoading: loadingGroupDetails } =+ useSWR<VisitorGroupDetail>(+ open && existingGroup && teamId+ ? `/api/teams/${teamId}/visitor-groups/${existingGroup.id}`+ : null,+ fetcher,+ );useEffect(() => {if (existingGroup) {@@ -61,8 +94,8 @@ export function VisitorGroupModal({try {const url = existingGroup- ? `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups/${existingGroup.id}`- : `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups`;+ ? `/api/teams/${teamId}/visitor-groups/${existingGroup.id}`+ : `/api/teams/${teamId}/visitor-groups`;const response = await fetch(url, {method: existingGroup ? "PUT" : "POST",@@ -84,8 +117,11 @@ export function VisitorGroupModal({);mutate(- `/api/teams/${teamInfo?.currentTeam?.id}/visitor-groups`,+ `/api/teams/${teamId}/visitor-groups`,);+ if (existingGroup) {+ mutate(`/api/teams/${teamId}/visitor-groups/${existingGroup.id}`);+ }} catch (error) {toast.error("Error saving visitor group. Please try again.");} finally {@@ -140,6 +176,72 @@ [email protected]Use @domain.com to allow all emails from a domain.</p></div>++ {existingGroup && (+ <div>+ <p className="text-[11px] font-semibold uppercase tracking-widest text-muted-foreground">+ Linked Documents & Datarooms+ </p>+ {loadingGroupDetails ? (+ <p className="mt-1.5 text-xs text-muted-foreground">+ Loading...+ </p>+ ) : existingGroupDetails?.links?.length ? (+ <div className="mt-1.5 space-y-1">+ {existingGroupDetails.links.map((groupLink) => {+ const isDataroom =+ groupLink.link.linkType === "DATAROOM_LINK";+ const entity = isDataroom+ ? groupLink.link.dataroom+ : groupLink.link.document;+ const href = isDataroom+ ? groupLink.link.dataroomId+ ? `/datarooms/${groupLink.link.dataroomId}/documents`+ : null+ : groupLink.link.documentId+ ? `/documents/${groupLink.link.documentId}`+ : null;++ return (+ <div+ key={groupLink.id}+ className="flex items-center justify-between rounded-md border border-gray-200 px-2.5 py-1.5 dark:border-gray-800"+ >+ <div className="flex min-w-0 items-center gap-2">+ {isDataroom ? (+ <FolderKanbanIcon className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />+ ) : (+ <FileTextIcon className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />+ )}+ <span className="truncate text-xs font-medium text-foreground">+ {entity?.name ||+ (isDataroom+ ? "Untitled dataroom"+ : "Untitled document")}+ </span>+ <span className="shrink-0 text-[10px] text-muted-foreground">+ via {groupLink.link.name || "Untitled link"}+ </span>+ </div>+ {href && (+ <Link+ href={href}+ className="ml-2 shrink-0 text-muted-foreground transition-colors hover:text-foreground"+ >+ <ExternalLinkIcon className="h-3.5 w-3.5" />+ </Link>+ )}+ </div>+ );+ })}+ </div>+ ) : (+ <p className="mt-1.5 text-xs text-muted-foreground">+ Not linked to any documents or datarooms yet.+ </p>+ )}+ </div>+ )}</div><DialogFooter className="mt-4"><Button type="submit" loading={loading} className="h-9 w-full">diff --git a/components/visitors/visitor-groups-section.tsx b/components/visitors/visitor-groups-section.tsxindex 89be392d..4e031bc2 100644--- a/components/visitors/visitor-groups-section.tsx+++ b/components/visitors/visitor-groups-section.tsx@@ -1,7 +1,14 @@import { useState } from "react";+import Link from "next/link";import { useTeam } from "@/context/team-context";+import type { LinkType } from "@prisma/client";import {+ ChevronDownIcon,+ ExternalLinkIcon,+ FolderKanbanIcon,+ GlobeIcon,+ LinkIcon,MailIcon,MoreVerticalIcon,PencilIcon,@@ -11,12 +18,13 @@ import {} from "lucide-react";import { toast } from "sonner";import { mutate } from "swr";+import useSWR from "swr";import useVisitorGroups, {VisitorGroupWithCount,} from "@/lib/swr/use-visitor-groups";+import { cn, fetcher } from "@/lib/utils";-import { Badge } from "@/components/ui/badge";import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -28,12 +36,331 @@ import { Skeleton } from "@/components/ui/skeleton";import { VisitorGroupModal } from "./visitor-group-modal";+type VisitorGroupLink = {+ id: string;+ link: {+ id: string;+ name: string | null;+ linkType: LinkType;+ documentId: string | null;+ dataroomId: string | null;+ document: { id: string; name: string } | null;+ dataroom: { id: string; name: string } | null;+ };+};++type VisitorGroupDetail = VisitorGroupWithCount & {+ links: VisitorGroupLink[];+};++const splitMembers = (members: string[]) => {+ const domainMembers = members.filter((member) => member.startsWith("@"));+ const emailMembers = members.filter((member) => !member.startsWith("@"));+ return { emailMembers, domainMembers };+};++function VisitorGroupCard({+ group,+ teamId,+ onEdit,+ onDelete,+}: {+ group: VisitorGroupWithCount;+ teamId?: string;+ onEdit: (group: VisitorGroupWithCount) => void;+ onDelete: (group: VisitorGroupWithCount) => void;+}) {+ const [expanded, setExpanded] = useState(false);+ const [menuOpen, setMenuOpen] = useState(false);++ const { data: groupDetails, isLoading: loadingDetails } =+ useSWR<VisitorGroupDetail>(+ expanded && teamId+ ? `/api/teams/${teamId}/visitor-groups/${group.id}`+ : null,+ fetcher,+ );++ const members = groupDetails?.emails ?? group.emails ?? [];+ const memberCount = members.length;+ const linkCount = groupDetails?._count.links ?? group._count.links;+ const { emailMembers, domainMembers } = splitMembers(members);+ const previewMembers = members.slice(0, 5);+ const extraMembersCount = Math.max(+ members.length - previewMembers.length,+ 0,+ );++ const links = groupDetails?.links ?? [];+ const documentLinks = links.filter(+ (item) => item.link.linkType !== "DATAROOM_LINK",+ );+ const dataroomLinks = links.filter(+ (item) => item.link.linkType === "DATAROOM_LINK",+ );++ const hasLinkedItems =+ loadingDetails || documentLinks.length > 0 || dataroomLinks.length > 0;++ const toggle = () => setExpanded((prev) => !prev);++ return (+ <div+ className={cn(+ "overflow-hidden rounded-xl border border-gray-200 transition-colors dark:border-gray-800",+ expanded+ ? "bg-gray-50/80 dark:bg-gray-900/70"+ : "bg-white hover:bg-gray-50/50 dark:bg-gray-900 dark:hover:bg-gray-800/40",+ )}+ >+ {/* Clickable header */}+ <div+ role="button"+ tabIndex={0}+ onClick={toggle}+ onKeyDown={(event) => {+ if (event.key === "Enter" || event.key === " ") {+ event.preventDefault();+ toggle();+ }+ }}+ className="cursor-pointer px-4 pt-3.5 sm:px-5 sm:pt-4"+ >+ <div className="flex items-start justify-between gap-3">+ <div className="min-w-0 flex-1">+ <div className="flex min-w-0 items-center gap-2.5">+ <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-gray-200 bg-gradient-to-t from-gray-100 dark:border-gray-700 dark:from-gray-800">+ <UsersIcon className="h-3.5 w-3.5 text-foreground" />+ </div>+ <p className="truncate text-sm font-semibold text-foreground">+ {group.name}+ </p>+ </div>++ <div className="mt-2 flex items-center gap-1.5">+ <span className="inline-flex items-center gap-1 rounded-md bg-gray-100 px-2 py-0.5 text-xs font-medium text-muted-foreground dark:bg-gray-800">+ <UsersIcon className="h-3 w-3" />+ {memberCount} {memberCount === 1 ? "member" : "members"}+ </span>+ <span className="inline-flex items-center gap-1 rounded-md bg-gray-100 px-2 py-0.5 text-xs font-medium text-muted-foreground dark:bg-gray-800">+ <LinkIcon className="h-3 w-3" />+ {linkCount} {linkCount === 1 ? "link" : "links"}+ </span>+ </div>++ {!expanded && previewMembers.length > 0 && (+ <div className="mt-2 flex flex-wrap items-center gap-1.5">+ {previewMembers.map((member) => (+ <span+ key={`${group.id}-${member}`}+ className={cn(+ "inline-flex items-center rounded-md px-2 py-0.5 text-xs",+ member.startsWith("@")+ ? "bg-blue-50 text-blue-600 dark:bg-blue-900/30 dark:text-blue-300"+ : "bg-gray-100 text-foreground dark:bg-gray-800",+ )}+ >+ {member}+ </span>+ ))}+ {extraMembersCount > 0 && (+ <span className="text-xs text-muted-foreground">+ +{extraMembersCount} more+ </span>+ )}+ </div>+ )}+ </div>++ <DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>+ <DropdownMenuTrigger asChild>+ <Button+ variant="outline"+ className="h-7 w-7 border-gray-200 bg-transparent p-0 hover:bg-gray-100 dark:border-gray-700 dark:hover:bg-gray-800"+ onClick={(e) => e.stopPropagation()}+ >+ <MoreVerticalIcon className="h-3.5 w-3.5" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ onEdit(group);+ }}+ >+ <PencilIcon className="mr-2 h-4 w-4" />+ Edit+ </DropdownMenuItem>+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ onDelete(group);+ }}+ className="text-destructive focus:text-destructive"+ >+ <TrashIcon className="mr-2 h-4 w-4" />+ Delete+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </div>+ </div>++ {/* Expanded content */}+ {expanded && (+ <div className="px-4 pb-3 pt-3 sm:px-5 sm:pb-4">+ <div className="space-y-3">+ {emailMembers.length > 0 && (+ <div>+ <p className="text-[11px] font-semibold uppercase tracking-widest text-muted-foreground">+ Email Members ({emailMembers.length})+ </p>+ <div className="mt-1.5 space-y-0.5">+ {emailMembers.map((email) => (+ <div+ key={`${group.id}-email-${email}`}+ className="flex items-center gap-2 py-0.5 text-xs text-foreground"+ >+ <MailIcon className="h-3 w-3 text-muted-foreground" />+ <span>{email}</span>+ </div>+ ))}+ </div>+ </div>+ )}++ {domainMembers.length > 0 && (+ <div>+ <p className="text-[11px] font-semibold uppercase tracking-widest text-muted-foreground">+ Domain Access ({domainMembers.length})+ </p>+ <div className="mt-1.5 space-y-0.5">+ {domainMembers.map((domain) => (+ <div+ key={`${group.id}-domain-${domain}`}+ className="flex items-center gap-2 py-0.5 text-xs text-foreground"+ >+ <GlobeIcon className="h-3 w-3 text-muted-foreground" />+ <span>{domain}</span>+ </div>+ ))}+ </div>+ </div>+ )}++ {hasLinkedItems && (+ <div>+ <p className="text-[11px] font-semibold uppercase tracking-widest text-muted-foreground">+ Linked Documents (+ {documentLinks.length + dataroomLinks.length})+ </p>++ {loadingDetails ? (+ <p className="mt-1.5 text-xs text-muted-foreground">+ Loading...+ </p>+ ) : (+ <div className="mt-1.5 space-y-1">+ {documentLinks.map((groupLink) => {+ const documentId = groupLink.link.documentId;+ return (+ <div+ key={groupLink.id}+ className="flex items-center justify-between rounded-md border border-gray-200 bg-white px-2.5 py-1.5 dark:border-gray-700 dark:bg-gray-800/50"+ >+ <div className="flex min-w-0 items-center gap-2">+ <LinkIcon className="h-3 w-3 shrink-0 text-muted-foreground" />+ <span className="truncate text-xs font-medium text-foreground">+ {groupLink.link.document?.name ||+ "Untitled document"}+ </span>+ <span className="shrink-0 text-[10px] text-muted-foreground">+ via{" "}+ {groupLink.link.name || "Untitled link"}+ </span>+ </div>+ {documentId && (+ <Link+ href={`/documents/${documentId}`}+ onClick={(e) => e.stopPropagation()}+ className="ml-2 shrink-0 text-muted-foreground transition-colors hover:text-foreground"+ >+ <ExternalLinkIcon className="h-3 w-3" />+ </Link>+ )}+ </div>+ );+ })}+ {dataroomLinks.map((groupLink) => {+ const dataroomId = groupLink.link.dataroomId;+ return (+ <div+ key={groupLink.id}+ className="flex items-center justify-between rounded-md border border-gray-200 bg-white px-2.5 py-1.5 dark:border-gray-700 dark:bg-gray-800/50"+ >+ <div className="flex min-w-0 items-center gap-2">+ <FolderKanbanIcon className="h-3 w-3 shrink-0 text-muted-foreground" />+ <span className="truncate text-xs font-medium text-foreground">+ {groupLink.link.dataroom?.name ||+ "Untitled dataroom"}+ </span>+ <span className="shrink-0 text-[10px] text-muted-foreground">+ via{" "}+ {groupLink.link.name || "Untitled link"}+ </span>+ </div>+ {dataroomId && (+ <Link+ href={`/datarooms/${dataroomId}/permissions`}+ onClick={(e) => e.stopPropagation()}+ className="ml-2 shrink-0 text-muted-foreground transition-colors hover:text-foreground"+ >+ <ExternalLinkIcon className="h-3 w-3" />+ </Link>+ )}+ </div>+ );+ })}+ </div>+ )}+ </div>+ )}+ </div>+ </div>+ )}++ {/* Chevron toggle at center bottom */}+ <div+ role="button"+ tabIndex={0}+ onClick={toggle}+ onKeyDown={(event) => {+ if (event.key === "Enter" || event.key === " ") {+ event.preventDefault();+ toggle();+ }+ }}+ className="flex cursor-pointer justify-center py-1 transition-colors hover:bg-gray-100/60 dark:hover:bg-gray-800/40"+ >+ <ChevronDownIcon+ className={cn(+ "h-4 w-4 text-muted-foreground transition-transform",+ expanded && "rotate-180",+ )}+ />+ </div>+ </div>+ );+}+export function VisitorGroupsSection() {const { visitorGroups, loading } = useVisitorGroups();const [modalOpen, setModalOpen] = useState(false);const [editingGroup, setEditingGroup] =useState<VisitorGroupWithCount | null>(null);const teamInfo = useTeam();+ const teamId = teamInfo?.currentTeam?.id;const handleEdit = (group: VisitorGroupWithCount) => {setEditingGroup(group);@@ -120,59 +447,13 @@ export function VisitorGroupsSection() {) : (<div className="grid gap-3">{visitorGroups.map((group) => (- <div+ <VisitorGroupCardkey={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>+ group={group}+ teamId={teamId}+ onEdit={handleEdit}+ onDelete={handleDelete}+ />))}</div>)}diff --git a/pages/api/teams/[teamId]/visitor-groups/[groupId]/index.ts b/pages/api/teams/[teamId]/visitor-groups/[groupId]/index.tsindex eaa51c4b..055f2d3e 100644--- a/pages/api/teams/[teamId]/visitor-groups/[groupId]/index.ts+++ b/pages/api/teams/[teamId]/visitor-groups/[groupId]/index.ts@@ -46,6 +46,12 @@ export default async function handle(},include: {links: {+ where: {+ link: {+ deletedAt: null,+ isArchived: false,+ },+ },include: {link: {select: {@@ -56,6 +62,18 @@ export default async function handle(isArchived: true,documentId: true,dataroomId: true,+ document: {+ select: {+ id: true,+ name: true,+ },+ },+ dataroom: {+ select: {+ id: true,+ name: true,+ },+ },},},},