Skip to content

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

feat: add link controls button indicator

Marc Seitzc0908af78bbe
diff --git a/components/links/link-active-controls.tsx b/components/links/link-active-controls.tsx
new file mode 100644
index 00000000..0cc8ff4d
--- /dev/null
+++ b/components/links/link-active-controls.tsx
@@ -0,0 +1,119 @@
+import { LinkWithViews } from "@/lib/types";
+
+import { Button } from "@/components/ui/button";
+
+type LinkSetting = {
+ key: keyof LinkWithViews;
+ label: string;
+ isActive: (link: LinkWithViews) => boolean;
+};
+
+const LINK_SETTINGS: LinkSetting[] = [
+ {
+ key: "emailProtected",
+ label: "Require email to view",
+ isActive: (link) => !!link.emailProtected,
+ },
+ {
+ key: "enableNotification",
+ label: "Receive email notification",
+ isActive: (link) => !!link.enableNotification,
+ },
+ {
+ key: "enableConversation",
+ label: "Show visitor statistics",
+ isActive: (link) => !!link.enableConversation,
+ },
+ {
+ key: "password",
+ label: "Password protection",
+ isActive: (link) => !!link.password,
+ },
+ {
+ key: "enableScreenshotProtection",
+ label: "Screenshot protection",
+ isActive: (link) => !!link.enableScreenshotProtection,
+ },
+ {
+ key: "enableWatermark",
+ label: "Watermark enabled",
+ isActive: (link) => !!link.enableWatermark,
+ },
+ {
+ key: "enableFeedback",
+ label: "Collect feedback",
+ isActive: (link) => !!link.enableFeedback,
+ },
+ {
+ key: "allowDownload",
+ label: "Allow downloads",
+ isActive: (link) => !!link.allowDownload,
+ },
+ {
+ key: "enableQuestion",
+ label: "Custom question",
+ isActive: (link) => !!link.enableQuestion,
+ },
+ {
+ key: "enableAgreement",
+ label: "Requires agreement",
+ isActive: (link) => !!link.enableAgreement,
+ },
+ {
+ key: "enableUpload",
+ label: "Allow uploads",
+ isActive: (link) => !!link.enableUpload,
+ },
+];
+
+// Helper function to count active settings for a link
+export function countActiveSettings(link: LinkWithViews): number {
+ return LINK_SETTINGS.filter((setting) => setting.isActive(link)).length;
+}
+
+interface LinkActiveControlsProps {
+ link: LinkWithViews;
+ onEditClick?: (e: React.MouseEvent) => void;
+}
+
+export default function LinkActiveControls({
+ link,
+ onEditClick,
+}: LinkActiveControlsProps) {
+ const activeSettings = LINK_SETTINGS.filter((setting) =>
+ setting.isActive(link),
+ );
+
+ return (
+ <div className="p-3">
+ <div className="mb-2 text-sm font-medium">Active Link Controls</div>
+ <ul className="space-y-1 text-sm">
+ {activeSettings.length > 0 ? (
+ activeSettings.map((setting) => (
+ <li
+ key={setting.key.toString()}
+ className="flex items-center gap-2 text-gray-900"
+ >
+ <span className="inline-block h-2 w-2 rounded-full bg-green-400" />
+ {setting.label}
+ </li>
+ ))
+ ) : (
+ <li className="text-gray-400">No active settings</li>
+ )}
+ </ul>
+ {onEditClick && (
+ <div className="mt-2">
+ <Button
+ className="h-7 w-full focus-visible:ring-0 focus-visible:ring-offset-0"
+ variant="outline"
+ size="sm"
+ onClick={onEditClick}
+ >
+ Configure link
+ </Button>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 2ff9cb89..772591d2 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -1,7 +1,6 @@
-import { useSearchParams } from "next/navigation";
import { useRouter } from "next/router";
-import { useMemo, useState } from "react";
+import { useMemo, useRef, useState } from "react";
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
@@ -24,6 +23,7 @@ import { usePlan } from "@/lib/swr/use-billing";
import useLimits from "@/lib/swr/use-limits";
import { LinkWithViews, WatermarkConfig } from "@/lib/types";
import { cn, copyToClipboard, fetcher, nFormatter, timeAgo } from "@/lib/utils";
+import { useMediaQuery } from "@/lib/utils/use-media-query";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import { Button } from "@/components/ui/button";
@@ -40,6 +40,11 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
import {
Table,
TableBody,
@@ -56,13 +61,15 @@ import MoreHorizontal from "../shared/icons/more-horizontal";
import { Badge } from "../ui/badge";
import { ButtonTooltip } from "../ui/tooltip";
import EmbedCodeModal from "./embed-code-modal";
+import LinkActiveControls, {
+ countActiveSettings,
+} from "./link-active-controls";
import LinkSheet, {
DEFAULT_LINK_PROPS,
type DEFAULT_LINK_TYPE,
} from "./link-sheet";
import { TagColumn } from "./link-sheet/tags/tag-details";
import LinksVisitors from "./links-visitors";
-import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
export default function LinksTable({
targetType,
@@ -90,6 +97,8 @@ export default function LinksTable({
groupId?: string;
};
+ const { isMobile } = useMediaQuery();
+
let processedLinks = useMemo(() => {
if (!links?.length) return [];
@@ -387,7 +396,13 @@ export default function LinksTable({
.map((link) => (
<Collapsible key={link.id} asChild>
<>
- <TableRow key={link.id} className="group/row">
+ <TableRow
+ key={link.id}
+ className={cn(
+ "group/row",
+ popoverOpen === link.id && "bg-gray-100",
+ )}
+ >
<TableCell className="w-[250px] truncate font-medium">
<div className="flex items-center gap-x-2">
{link.groupId ? (
@@ -426,6 +441,8 @@ export default function LinksTable({
link.domainId && isFree
? "bg-destructive hover:bg-red-700 hover:dark:bg-red-200"
: "bg-secondary hover:bg-emerald-700 hover:dark:bg-emerald-200",
+ popoverOpen === link.id &&
+ "ring-1 ring-gray-400 dark:ring-gray-100",
)}
>
{/* Progress bar */}
@@ -482,71 +499,94 @@ export default function LinksTable({
onClick={() => handlePreviewLink(link)}
>
<span className="sr-only">Preview link</span>
- <EyeIcon className="h-5 w-5 text-gray-400 group-hover:text-gray-500" />
+ <EyeIcon className="text-gray-400 group-hover:text-gray-500" />
</Button>
</ButtonTooltip>
- <Popover open={popoverOpen === link.id} onOpenChange={() => {}}>
- <PopoverTrigger asChild>
+ {isMobile ? (
+ <ButtonTooltip content="Edit link">
<Button
- variant="outline"
- className="flex items-center gap-1 h-7 py-0.5"
+ variant={"link"}
+ size={"icon"}
+ className="group h-7 w-8"
onClick={() => handleEditLink(link)}
- title="Edit link"
- onMouseDown={e => e.preventDefault()}
+ >
+ <span className="sr-only">Edit link</span>
+ <Settings2Icon className="text-gray-400 group-hover:text-gray-500" />
+ </Button>
+ </ButtonTooltip>
+ ) : (
+ <Popover
+ open={popoverOpen === link.id}
+ onOpenChange={() => {}}
+ >
+ <PopoverTrigger asChild>
+ <Button
+ variant="link"
+ className={cn(
+ "h-7 font-normal hover:no-underline focus-visible:ring-0 focus-visible:ring-offset-0",
+ popoverOpen === link.id
+ ? "text-foreground"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ size="sm"
+ onClick={(e) => {
+ e.preventDefault();
+ handleEditLink(link);
+ }}
+ onMouseDown={(e) => e.preventDefault()}
+ onMouseEnter={() => {
+ hoverTimeout.current = setTimeout(
+ () => setPopoverOpen(link.id),
+ 250,
+ );
+ }}
+ onMouseLeave={() => {
+ if (hoverTimeout.current)
+ clearTimeout(hoverTimeout.current);
+
+ // Add delay before closing to prevent flickering
+ hoverTimeout.current = setTimeout(
+ () => setPopoverOpen(null),
+ 100,
+ );
+ }}
+ >
+ <Settings2Icon strokeWidth={1.75} />
+ <span className="whitespace-nowrap">
+ {countActiveSettings(link)} options
+ </span>
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ side="top"
+ align="start"
+ className="w-56 p-0"
onMouseEnter={() => {
- hoverTimeout.current = setTimeout(() => setPopoverOpen(link.id), 250);
+ if (hoverTimeout.current)
+ clearTimeout(hoverTimeout.current);
+ setPopoverOpen(link.id);
}}
onMouseLeave={() => {
- if (hoverTimeout.current) clearTimeout(hoverTimeout.current);
- setPopoverOpen(null);
+ if (hoverTimeout.current)
+ clearTimeout(hoverTimeout.current);
+
+ // Add delay before closing to prevent flickering
+ hoverTimeout.current = setTimeout(
+ () => setPopoverOpen(null),
+ 100,
+ );
}}
>
- <Settings2Icon className="h-3 w-3 text-gray-400 hover:text-gray-500" />
- <span className="font-semibold text-xs whitespace-nowrap text-gray-400 hover:text-gray-500">Edit link</span>
- </Button>
- </PopoverTrigger>
- <PopoverContent
- side="bottom"
- align="start"
- className="w-56 p-0"
- onMouseEnter={() => {
- if (hoverTimeout.current) clearTimeout(hoverTimeout.current);
- setPopoverOpen(link.id);
- }}
- onMouseLeave={() => {
- if (hoverTimeout.current) clearTimeout(hoverTimeout.current);
- setPopoverOpen(null);
- }}
- >
- <div className="p-3">
- <div className="font-semibold mb-2 text-sm">Active Link Settings</div>
- <ul className="space-y-1 text-sm">
- {link.emailProtected && (
- <li className="flex items-center gap-2 text-gray-900">
- <span className="inline-block w-2 h-2 rounded-full bg-green-400" />
- Require email to view
- </li>
- )}
- {link.enableNotification && (
- <li className="flex items-center gap-2 text-gray-900">
- <span className="inline-block w-2 h-2 rounded-full bg-green-400" />
- Receive email notification
- </li>
- )}
- {link.enableConversation && (
- <li className="flex items-center gap-2 text-gray-900">
- <span className="inline-block w-2 h-2 rounded-full bg-green-400" />
- Show visitor statistics
- </li>
- )}
- {/* Add more settings as needed */}
- {!(link.emailProtected || link.enableNotification || link.enableConversation) && (
- <li className="text-gray-400">No active settings</li>
- )}
- </ul>
- </div>
- </PopoverContent>
- </Popover>
+ <LinkActiveControls
+ link={link}
+ onEditClick={(e) => {
+ e.preventDefault();
+ handleEditLink(link);
+ }}
+ />
+ </PopoverContent>
+ </Popover>
+ )}
</TableCell>
{hasAnyTags ? (
<TableCell className="w-[250px] 2xl:w-auto">
@@ -851,4 +891,4 @@ export default function LinksTable({
</div>
</>
);
-}
\ No newline at end of file
+}