Skip to content

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

feat: add links table

Marc Seitzea0affea40c4
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
new file mode 100644
index 00000000..00aedf2c
--- /dev/null
+++ b/components/links/links-table.tsx
@@ -0,0 +1,146 @@
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@/components/ui/table";
+import {
+ DropdownMenu,
+ DropdownMenuCheckboxItem,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu";
+import { Button } from "@/components/ui/button";
+
+import { useDocumentLinks } from "@/lib/swr/use-document";
+import toast from "react-hot-toast";
+import Notification from "../Notification";
+import BarChart from "../shared/icons/bar-chart";
+import { nFormatter, timeAgo } from "@/lib/utils";
+import MoreHorizontal from "../shared/icons/more-horizontal";
+import { Skeleton } from "../ui/skeleton";
+
+
+export default function LinksTable() {
+ const { links } = useDocumentLinks();
+
+ const handleCopyToClipboard = (id: string) => {
+ navigator.clipboard
+ .writeText(`${process.env.NEXT_PUBLIC_BASE_URL}/view/${id}`)
+ .catch((error) => {
+ console.log("Failed to copy text to clipboard", error);
+ });
+
+ toast.custom((t) => (
+ <Notification
+ visible={t.visible}
+ closeToast={() => toast.dismiss(t.id)}
+ message={``}
+ />
+ ));
+ };
+
+ return (
+ <div className="w-full sm:p-4">
+ <div><h2 className="p-4">All links</h2></div>
+ <div className="rounded-md sm:border">
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead className="font-medium">Name</TableHead>
+ <TableHead className="font-medium w-[250px]">Link</TableHead>
+ <TableHead className="font-medium">Views</TableHead>
+ <TableHead className="font-medium">Last Viewed</TableHead>
+ <TableHead className="font-medium text-right"></TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {links ? (
+ links.map((link) => (
+ <TableRow key={link.id} className="group/row">
+ <TableCell>{link.name || "No link name"}</TableCell>
+ <TableCell className="min-w-[260px] sm:min-w-[450px]">
+ <div className="group/cell flex items-center gap-x-4 rounded-md bg-gray-700 px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-100 hover:bg-gray-200 transition-all">
+ <div className="whitespace-nowrap hidden sm:flex text-sm text-gray-300 group-hover/cell:hidden">{`https://papermark.io/view/${link.id}`}</div>
+ <div className="flex sm:hidden whitespace-nowrap text-sm text-gray-300 group-hover/cell:hidden">{`${link.id}`}</div>
+ <button
+ className="whitespace-nowrap text-sm text-center text-black hidden group-hover/cell:block w-full"
+ onClick={() => handleCopyToClipboard(link.id)}
+ title="Copy to clipboard"
+ >
+ Copy to Clipboard
+ </button>
+ </div>
+ </TableCell>
+ <TableCell>
+ <div className="flex items-center space-x-1">
+ <BarChart className="h-4 w-4 text-gray-400" />
+ <p className="whitespace-nowrap text-sm text-gray-400">
+ {nFormatter(link._count.views)}
+ <span className="ml-1 hidden sm:inline-block">
+ views
+ </span>
+ </p>
+ </div>
+ </TableCell>
+ <TableCell className="text-sm text-gray-400">
+ {link.views[0] ? (
+ <time
+ dateTime={new Date(
+ link.views[0].viewedAt
+ ).toISOString()}
+ >
+ {timeAgo(link.views[0].viewedAt)}
+ </time>
+ ) : (
+ "-"
+ )}
+ </TableCell>
+ <TableCell className="text-right">
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant="ghost" className="h-8 w-8 p-0">
+ <span className="sr-only">Open menu</span>
+ <MoreHorizontal className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuLabel>Actions</DropdownMenuLabel>
+ <DropdownMenuItem>Edit Link</DropdownMenuItem>
+ <DropdownMenuItem>Make copy</DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem className="text-red-500 focus:text-red-200 focus:bg-red-900">
+ Delete
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ ))
+ ) : (
+ <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>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/components/shared/icons/more-horizontal.tsx b/components/shared/icons/more-horizontal.tsx
new file mode 100644
index 00000000..16391088
--- /dev/null
+++ b/components/shared/icons/more-horizontal.tsx
@@ -0,0 +1,20 @@
+export default function MoreHorizontal({ className }: { className?: string }) {
+ return (
+ <svg
+ width="14"
+ height="14"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ shapeRendering="geometricPrecision"
+ className={className}
+ >
+ <circle cx="12" cy="12" r="1" />
+ <circle cx="19" cy="12" r="1" />
+ <circle cx="5" cy="12" r="1" />
+ </svg>
+ );
+}
\ No newline at end of file
diff --git a/components/ui/skeleton.tsx b/components/ui/skeleton.tsx
new file mode 100644
index 00000000..01b8b6d4
--- /dev/null
+++ b/components/ui/skeleton.tsx
@@ -0,0 +1,15 @@
+import { cn } from "@/lib/utils"
+
+function Skeleton({
+ className,
+ ...props
+}: React.HTMLAttributes<HTMLDivElement>) {
+ return (
+ <div
+ className={cn("animate-pulse rounded-md bg-muted", className)}
+ {...props}
+ />
+ )
+}
+
+export { Skeleton }
diff --git a/pages/documents/[id].tsx b/pages/documents/[id].tsx
index 9a90a6b5..fecfb78a 100644
--- a/pages/documents/[id].tsx
+++ b/pages/documents/[id].tsx
@@ -1,12 +1,12 @@
import { getExtension } from "@/lib/utils";
import { useDocument } from "@/lib/swr/use-document";
import ErrorPage from "next/error";
-import LinksContainer from "@/components/links/links-container";
import StatsCard from "@/components/documents/stats-card";
import StatsChart from "@/components/documents/stats-chart";
import AppLayout from "@/components/layouts/app";
import LinkSheet from "@/components/links/link-sheet";
import Image from "next/image"
+import LinksTable from "@/components/links/links-table";
export default function DocumentPage() {
const { document, error } = useDocument();
@@ -38,14 +38,14 @@ export default function DocumentPage() {
</h2>
</div>
</div>
- <LinkSheet>
- <button
- type="button"
- className="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-gray-950 bg-gray-300 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
- >
- Create Link
- </button>
- </LinkSheet>
+ <LinkSheet>
+ <button
+ type="button"
+ className="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-gray-950 bg-gray-300 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
+ >
+ Create Link
+ </button>
+ </LinkSheet>
</div>
{/* Stats */}
{document.numPages !== null && (
@@ -56,7 +56,7 @@ export default function DocumentPage() {
)}
<StatsCard />
{/* Links */}
- <LinksContainer />
+ <LinksTable />
</>
) : (
<div>Loading...</div>