mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
Papermark dual-licenses: AGPL-3.0 for the tree, a separate commercial
licence for ee/. We hold the first and not the second, so none of the
second may live here.
ee/ was already absent from main, but it was never deleted. 98f0da7fa
("ci: amd64-only build") renamed 150 files out of ee/ byte-identical
into features/, lib/billing/legacy/ (ee/stripe), lib/billing/limits/
(ee/limits), and flattened app/(ee)/ into app/ — putting commercially
licensed code under our AGPL root LICENSE. A rename is not a deletion.
Every path that commit moved is now gone, edited-since or not.
Deleted, with their routes and UI entry points: features/ai and
app/api/ai, features/workflows and app/api/{workflows,workflow-entry},
features/conversations and the Q&A/FAQ surface, features/security/sso
with app/api/auth/saml + app/api/scim + lib/jackson.ts (we use Hanzo
IAM OIDC natively), features/dataroom-invitations, features/templates,
features/access-notifications, features/conversions, features/
permissions. Five of these were gated by lib/featureFlags, which reads
@vercel/edge-config and returns false for every flag when EDGE_CONFIG
is unset — every non-Vercel deployment we run. Those flags are gone too.
Deleted the commercial gating outright rather than reimplementing it:
lib/billing/legacy (ee/stripe) and lib/billing/limits (ee/limits), the
upgrade modals and banners, UpgradeButton, FeaturePreview, PlanBadge,
the trial and blocking modals, /settings/upgrade, /settings/billing and
the billing checkout/seat/pause/cancel API. usePlan() no longer returns
capability booleans — the plan tag describes provisioning, it is not a
permission — and useLimits() is gone with every quota check it fed.
Subscription pause went the same way. Also dropped the npm dependencies
that existed only for the removed features (@boxyhq/saml-jackson, the
@ai-sdk packages, openai, streamdown, use-stick-to-bottom,
@trigger.dev/python) and the Jackson-specific next.config webpack shims.
Rewritten as original Hanzo code where a capability was load-bearing:
- lib/utils/get-file-size-limits.ts — one UPLOAD_LIMITS set plus
getFileSizeLimit(contentType), env-overridable. Operational limits,
not commercial ones, so the tus and browser-upload paths still refuse
oversized files without consulting a plan matrix.
- components/links/link-sheet/permissions-sheet.tsx — a flat, depth
annotated item list with view/download switches over the same
/permission-groups API. Two states, not three. ItemPermission now has
a single definition in lib/types.ts.
- app/api/links/[id]/upload/route.ts — visitor uploads, built around one
authorize() helper shared by GET and POST, and a notification debounce
keyed per (link, viewer) instead of listing and cancelling runs.
There is now exactly one link sheet: the ee DataroomLinkSheet duplicated
the AGPL LinkSheet, which already handled DATAROOM_LINK. Replaced
upstream's Omit<LinkType, "WORKFLOW_LINK"> — Omit on a string union
yields an object type and never narrowed anything — with a real union.
Verified: the S3/tus upload+download harness passes 13/13 against MinIO
after the deletions, and tsc goes from 257 pre-existing errors on
origin/main to 192 with zero files worse than baseline.
Reasoning recorded in LLM.md. LICENSE untouched.
Co-authored-by: Hanzo Dev <[email protected]>
522 lines
22 KiB
TypeScript
522 lines
22 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import { useTeam } from "@/context/team-context";
|
|
import { DocumentVersion } from "@prisma/client";
|
|
import {
|
|
ArchiveIcon,
|
|
ArchiveRestoreIcon,
|
|
BadgeCheckIcon,
|
|
BadgeInfoIcon,
|
|
DownloadCloudIcon,
|
|
FileBadgeIcon,
|
|
FileDigitIcon,
|
|
MoreHorizontalIcon,
|
|
ServerIcon,
|
|
ThumbsDownIcon,
|
|
ThumbsUpIcon,
|
|
} from "lucide-react";
|
|
import { toast } from "sonner";
|
|
import { mutate } from "swr";
|
|
|
|
import { useDocumentVisits } from "@/lib/swr/use-document";
|
|
import { durationFormat, timeAgo } from "@/lib/utils";
|
|
|
|
import {
|
|
Collapsible,
|
|
CollapsibleContent,
|
|
CollapsibleTrigger,
|
|
} from "@/components/ui/collapsible";
|
|
import { Gauge } from "@/components/ui/gauge";
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
|
import {
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from "@/components/ui/table";
|
|
import { TimestampTooltip } from "@/components/ui/timestamp-tooltip";
|
|
import { BadgeTooltip } from "@/components/ui/tooltip";
|
|
|
|
import { Badge } from "@/components/ui/badge";
|
|
|
|
import { Pagination } from "../documents/pagination";
|
|
import { Button } from "../ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "../ui/dropdown-menu";
|
|
import { VisitorAvatar } from "./visitor-avatar";
|
|
import VisitorChart from "./visitor-chart";
|
|
import VisitorClicks from "./visitor-clicks";
|
|
import VisitorCustomFields from "./visitor-custom-fields";
|
|
import VisitorUserAgent from "./visitor-useragent";
|
|
import VisitorVideoChart from "./visitor-video-chart";
|
|
|
|
export default function VisitorsTable({
|
|
primaryVersion,
|
|
isVideo = false,
|
|
}: {
|
|
primaryVersion: DocumentVersion;
|
|
isVideo?: boolean;
|
|
}) {
|
|
const teamInfo = useTeam();
|
|
const teamId = teamInfo?.currentTeam?.id;
|
|
const [currentPage, setCurrentPage] = useState<number>(1);
|
|
const [pageSize, setPageSize] = useState<number>(10);
|
|
|
|
const { views, mutate: mutateViews } = useDocumentVisits(
|
|
currentPage,
|
|
pageSize,
|
|
);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
|
|
const handlePageSizeChange = (newSize: number) => {
|
|
setPageSize(newSize);
|
|
setCurrentPage(1);
|
|
};
|
|
|
|
const handleArchiveView = async (
|
|
viewId: string,
|
|
targetId: string,
|
|
isArchived: boolean,
|
|
) => {
|
|
setIsLoading(true);
|
|
|
|
const response = await fetch(
|
|
`/api/teams/${teamId}/views/${viewId}/archive`,
|
|
{
|
|
method: "PUT",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
isArchived: !isArchived,
|
|
}),
|
|
},
|
|
);
|
|
|
|
if (!response.ok) {
|
|
toast.error("Failed to archive view");
|
|
return;
|
|
}
|
|
|
|
// mutate the views on the current page
|
|
mutateViews();
|
|
// mutate the stats
|
|
mutate(
|
|
`/api/teams/${teamId}/documents/${encodeURIComponent(targetId)}/stats`,
|
|
);
|
|
|
|
toast.success(
|
|
!isArchived
|
|
? "View successfully archived"
|
|
: "View successfully unarchived",
|
|
);
|
|
setIsLoading(false);
|
|
};
|
|
|
|
return (
|
|
<div className="w-full">
|
|
<div className="mb-2 flex items-center gap-2 md:mb-4">
|
|
<h2>All visitors</h2>
|
|
{views && views.totalViews > 0 && (
|
|
<Badge variant="outline" className="text-muted-foreground">
|
|
{views.totalViews}
|
|
</Badge>
|
|
)}
|
|
</div>
|
|
<div className="rounded-md border">
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow className="*:whitespace-nowrap *:font-medium hover:bg-transparent">
|
|
<TableHead>Name</TableHead>
|
|
<TableHead>View Duration</TableHead>
|
|
<TableHead>View Completion</TableHead>
|
|
<TableHead>Last Viewed</TableHead>
|
|
<TableHead className="text-center sm:text-right"></TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{views?.viewsWithDuration.length === 0 && (
|
|
<TableRow>
|
|
<TableCell colSpan={5}>
|
|
<div className="flex h-40 w-full items-center justify-center">
|
|
<p>No views yet. Try sharing a link.</p>
|
|
</div>
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
{views?.viewsWithDuration ? (
|
|
views.viewsWithDuration.map((view) => {
|
|
if (view.isArchived) {
|
|
return (
|
|
<TableRow
|
|
key={view.id}
|
|
className="group/row opacity-50 grayscale"
|
|
>
|
|
{/* Name */}
|
|
<TableCell>
|
|
<div className="flex items-center overflow-visible sm:space-x-3">
|
|
<VisitorAvatar
|
|
viewerEmail={view.viewerEmail}
|
|
isArchived
|
|
/>
|
|
<div className="min-w-0 flex-1">
|
|
<div className="focus:outline-none">
|
|
<p className="flex items-center gap-x-2 overflow-visible text-sm font-medium text-gray-800 dark:text-gray-200">
|
|
{view.viewerEmail ? (
|
|
<>{view.viewerName || view.viewerEmail}</>
|
|
) : (
|
|
"Anonymous"
|
|
)}
|
|
</p>
|
|
{view.viewerName && view.viewerEmail && (
|
|
<p className="text-xs text-muted-foreground/60">
|
|
{view.viewerEmail}
|
|
</p>
|
|
)}
|
|
<p className="text-xs text-muted-foreground/60 sm:text-sm">
|
|
{view.link && view.link.name
|
|
? view.link.name
|
|
: view.linkId}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</TableCell>
|
|
{/* Duration */}
|
|
<TableCell className="">
|
|
<div className="text-sm text-muted-foreground">
|
|
{durationFormat(view.totalDuration)}
|
|
</div>
|
|
</TableCell>
|
|
{/* Completion */}
|
|
<TableCell className="flex justify-start">
|
|
<div className="text-sm text-muted-foreground">
|
|
<Gauge
|
|
value={view.completionRate}
|
|
size={"small"}
|
|
showValue={true}
|
|
/>
|
|
</div>
|
|
</TableCell>
|
|
{/* Last Viewed */}
|
|
<TableCell className="text-sm text-muted-foreground">
|
|
<TimestampTooltip
|
|
timestamp={view.viewedAt}
|
|
side="right"
|
|
rows={["local", "utc", "unix"]}
|
|
>
|
|
<time
|
|
className="select-none"
|
|
dateTime={new Date(view.viewedAt).toISOString()}
|
|
>
|
|
{timeAgo(view.viewedAt)}
|
|
</time>
|
|
</TimestampTooltip>
|
|
</TableCell>
|
|
|
|
{/* Actions */}
|
|
<TableCell className="text-center sm:text-right">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
}}
|
|
>
|
|
<span className="sr-only">Open menu</span>
|
|
<MoreHorizontalIcon className="h-4 w-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="text-destructive focus:bg-destructive focus:text-destructive-foreground"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
handleArchiveView(
|
|
view.id,
|
|
view.documentId ?? "",
|
|
view.isArchived,
|
|
);
|
|
}}
|
|
disabled={isLoading}
|
|
>
|
|
<ArchiveRestoreIcon className="mr-2 h-4 w-4" />
|
|
Restore
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</TableCell>
|
|
</TableRow>
|
|
);
|
|
}
|
|
return (
|
|
<Collapsible key={view.id} asChild>
|
|
<>
|
|
<CollapsibleTrigger asChild>
|
|
<TableRow key={view.id} className="group/row">
|
|
{/* Name */}
|
|
<TableCell>
|
|
<div className="flex items-center overflow-visible sm:space-x-3">
|
|
<VisitorAvatar viewerEmail={view.viewerEmail} />
|
|
<div className="min-w-0 flex-1">
|
|
<div className="focus:outline-none">
|
|
<p className="flex items-center gap-x-2 overflow-visible text-sm font-medium text-gray-800 dark:text-gray-200">
|
|
{view.viewerEmail ? (
|
|
<>
|
|
{view.viewerName || view.viewerEmail}{" "}
|
|
{view.verified && (
|
|
<BadgeTooltip
|
|
content="Verified visitor"
|
|
key={`verified-${view.id}`}
|
|
>
|
|
<BadgeCheckIcon className="h-4 w-4 text-emerald-500 hover:text-emerald-600" />
|
|
</BadgeTooltip>
|
|
)}
|
|
{view.internal && (
|
|
<BadgeTooltip
|
|
content="Internal visitor"
|
|
key={`internal-${view.id}`}
|
|
>
|
|
<BadgeInfoIcon className="h-4 w-4 text-blue-500 hover:text-blue-600" />
|
|
</BadgeTooltip>
|
|
)}
|
|
{view.agreementResponse && (
|
|
<BadgeTooltip
|
|
content={`Agreed to ${view.agreementResponse.agreement.name}`}
|
|
key={`agreement-${view.id}`}
|
|
>
|
|
<FileBadgeIcon className="h-4 w-4 text-emerald-500 hover:text-emerald-600" />
|
|
</BadgeTooltip>
|
|
)}
|
|
{view.downloadedAt && (
|
|
<BadgeTooltip
|
|
content={`Downloaded ${timeAgo(view.downloadedAt)}`}
|
|
key={`download-${view.id}`}
|
|
>
|
|
<DownloadCloudIcon className="h-4 w-4 text-cyan-500 hover:text-cyan-600" />
|
|
</BadgeTooltip>
|
|
)}
|
|
{view.dataroomId && (
|
|
<BadgeTooltip
|
|
content={`Dataroom Visitor`}
|
|
key={`dataroom-${view.id}`}
|
|
>
|
|
<ServerIcon className="h-4 w-4 text-[#fb7a00] hover:text-[#fb7a00]/90" />
|
|
</BadgeTooltip>
|
|
)}
|
|
{view.feedbackResponse && (
|
|
<BadgeTooltip
|
|
content={`${view.feedbackResponse.data.question}: ${view.feedbackResponse.data.answer}`}
|
|
key={`feedback-${view.id}`}
|
|
>
|
|
{view.feedbackResponse.data
|
|
.answer === "yes" ? (
|
|
<ThumbsUpIcon className="h-4 w-4 text-gray-500 hover:text-gray-600" />
|
|
) : (
|
|
<ThumbsDownIcon className="h-4 w-4 text-gray-500 hover:text-gray-600" />
|
|
)}
|
|
</BadgeTooltip>
|
|
)}
|
|
</>
|
|
) : (
|
|
"Anonymous"
|
|
)}
|
|
</p>
|
|
{view.viewerName && view.viewerEmail && (
|
|
<p className="text-xs text-muted-foreground/60">
|
|
{view.viewerEmail}
|
|
</p>
|
|
)}
|
|
<p className="text-xs text-muted-foreground/60 sm:text-sm">
|
|
{view.link && view.link.name
|
|
? view.link.name
|
|
: view.linkId}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</TableCell>
|
|
{/* Duration */}
|
|
<TableCell className="">
|
|
<div className="text-sm text-muted-foreground">
|
|
{durationFormat(view.totalDuration)}
|
|
</div>
|
|
</TableCell>
|
|
{/* Completion */}
|
|
<TableCell className="flex justify-start">
|
|
<div className="text-sm text-muted-foreground">
|
|
<Gauge
|
|
value={view.completionRate}
|
|
size={"small"}
|
|
showValue={true}
|
|
/>
|
|
</div>
|
|
</TableCell>
|
|
{/* Last Viewed */}
|
|
<TableCell className="text-sm text-muted-foreground">
|
|
<TimestampTooltip
|
|
timestamp={view.viewedAt}
|
|
side="right"
|
|
rows={["local", "utc", "unix"]}
|
|
>
|
|
<time
|
|
className="select-none"
|
|
dateTime={new Date(view.viewedAt).toISOString()}
|
|
>
|
|
{timeAgo(view.viewedAt)}
|
|
</time>
|
|
</TimestampTooltip>
|
|
</TableCell>
|
|
|
|
{/* Actions */}
|
|
<TableCell className="text-center sm:text-right">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
}}
|
|
>
|
|
<span className="sr-only">Open menu</span>
|
|
<MoreHorizontalIcon className="h-4 w-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="text-destructive focus:bg-destructive focus:text-destructive-foreground"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
handleArchiveView(
|
|
view.id,
|
|
view.documentId ?? "",
|
|
view.isArchived,
|
|
);
|
|
}}
|
|
disabled={isLoading}
|
|
>
|
|
<ArchiveIcon className="mr-2 h-4 w-4" />
|
|
Archive
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</TableCell>
|
|
</TableRow>
|
|
</CollapsibleTrigger>
|
|
|
|
<CollapsibleContent asChild>
|
|
<>
|
|
<TableRow className="hover:bg-transparent">
|
|
<TableCell colSpan={5}>
|
|
<VisitorCustomFields
|
|
viewId={view.id}
|
|
teamId={view.teamId!}
|
|
documentId={view.documentId!}
|
|
/>
|
|
<VisitorUserAgent viewId={view.id} />
|
|
|
|
<div className="pb-0.5 pl-0.5 md:pb-1 md:pl-1">
|
|
<div className="flex items-center gap-x-1 px-1">
|
|
<FileDigitIcon className="size-4" /> Document
|
|
Version {view.versionNumber}
|
|
</div>
|
|
</div>
|
|
|
|
{isVideo ? (
|
|
<VisitorVideoChart
|
|
documentId={view.documentId!}
|
|
viewId={view.id}
|
|
teamId={view.teamId!}
|
|
/>
|
|
) : (
|
|
<VisitorChart
|
|
documentId={view.documentId!}
|
|
viewId={view.id}
|
|
totalPages={view.versionNumPages}
|
|
versionNumber={view.versionNumber}
|
|
downloadType={view.downloadType}
|
|
downloadMetadata={
|
|
view.downloadMetadata as any
|
|
}
|
|
/>
|
|
)}
|
|
{primaryVersion.type === "pdf" ||
|
|
primaryVersion.type === "link" ? (
|
|
<VisitorClicks
|
|
teamId={view.teamId!}
|
|
documentId={view.documentId!}
|
|
viewId={view.id}
|
|
/>
|
|
) : null}
|
|
</TableCell>
|
|
</TableRow>
|
|
</>
|
|
</CollapsibleContent>
|
|
</>
|
|
</Collapsible>
|
|
);
|
|
})
|
|
) : (
|
|
<TableRow>
|
|
<TableCell className="min-w-[100px]">
|
|
<Skeleton className="h-6 w-full" />
|
|
</TableCell>
|
|
<TableCell className="min-w-[450px]">
|
|
<Skeleton className="h-6 w-full" />
|
|
</TableCell>
|
|
<TableCell>
|
|
<Skeleton className="h-6 w-24" />
|
|
</TableCell>
|
|
<TableCell>
|
|
<Skeleton className="h-6 w-24" />
|
|
</TableCell>
|
|
</TableRow>
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
<Pagination
|
|
itemName="visits"
|
|
currentPage={currentPage}
|
|
pageSize={pageSize}
|
|
totalItems={views?.totalViews || 0}
|
|
totalPages={
|
|
views?.totalViews ? Math.ceil(views.totalViews / pageSize) : 0
|
|
}
|
|
onPageChange={setCurrentPage}
|
|
onPageSizeChange={handlePageSizeChange}
|
|
totalShownItems={
|
|
views?.totalViews
|
|
? Math.min(
|
|
pageSize,
|
|
views.totalViews - (currentPage - 1) * pageSize,
|
|
)
|
|
: 0
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|