Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve token dashboard

Steven Teyd1e47554a755
diff --git a/apps/web/app/api/tokens/[id]/route.ts b/apps/web/app/api/tokens/[id]/route.ts
index 750bd19426..1926a6de68 100644
--- a/apps/web/app/api/tokens/[id]/route.ts
+++ b/apps/web/app/api/tokens/[id]/route.ts
@@ -25,14 +25,7 @@ export const GET = withWorkspace(
lastUsed: true,
createdAt: true,
updatedAt: true,
- user: {
- select: {
- id: true,
- name: true,
- image: true,
- isMachine: true,
- },
- },
+ user: true,
},
});
diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.ts
index 6890fa207a..8481e30a50 100644
--- a/apps/web/app/api/tokens/route.ts
+++ b/apps/web/app/api/tokens/route.ts
@@ -44,14 +44,7 @@ export const GET = withWorkspace(
lastUsed: true,
createdAt: true,
updatedAt: true,
- user: {
- select: {
- id: true,
- name: true,
- image: true,
- isMachine: true,
- },
- },
+ user: true,
},
orderBy: [{ lastUsed: "desc" }, { createdAt: "desc" }],
take: 100,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tokens/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tokens/page.tsx
index 3cdd8b5dce..9333de9909 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tokens/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tokens/page.tsx
@@ -11,7 +11,7 @@ import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { Delete } from "@/ui/shared/icons";
-import { UserAvatar } from "@/ui/users/user-avatar";
+import { UserAvatarWithTooltip } from "@/ui/links/link-title-column";
import {
Button,
buttonVariants,
@@ -22,7 +22,7 @@ import {
Popover,
StatusBadge,
Table,
- Tooltip,
+ TimestampTooltip,
usePagination,
useTable,
} from "@dub/ui";
@@ -118,21 +118,23 @@ export default function TokensPage() {
cell: ({ row }) => {
return (
<div className="flex items-center gap-2">
- <Tooltip content={row.original.user.name}>
- <div>
- <UserAvatar
- user={row.original.user}
- className="size-5 rounded-full"
- />
- </div>
- </Tooltip>
- <p>
- {new Date(row.original.createdAt).toLocaleDateString("en-us", {
- month: "short",
- day: "numeric",
- year: "numeric",
- })}
- </p>
+ <UserAvatarWithTooltip user={row.original.user} />
+ <TimestampTooltip
+ timestamp={row.original.createdAt}
+ rows={["local", "utc", "unix"]}
+ delayDuration={150}
+ >
+ <p>
+ {new Date(row.original.createdAt).toLocaleDateString(
+ "en-us",
+ {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ },
+ )}
+ </p>
+ </TimestampTooltip>
</div>
);
},
@@ -161,7 +163,15 @@ export default function TokensPage() {
id: "lastUsed",
header: "Last used",
accessorKey: "lastUsed",
- cell: ({ row }) => timeAgo(row.original.lastUsed),
+ cell: ({ row }) => (
+ <TimestampTooltip
+ timestamp={row.original.lastUsed}
+ rows={["local", "utc", "unix"]}
+ delayDuration={150}
+ >
+ <span>{timeAgo(row.original.lastUsed)}</span>
+ </TimestampTooltip>
+ ),
},
// Menu
diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx
deleted file mode 100644
index 469e803dee..0000000000
--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page-client.tsx
+++ /dev/null
@@ -1,134 +0,0 @@
-"use client";
-
-import { TokenProps } from "@/lib/types";
-import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
-import { Callout } from "@/ui/shared/callout";
-import { TokenAvatar } from "@/ui/token-avatar";
-import { IconMenu, LoadingSpinner, Popover } from "@dub/ui";
-import { fetcher, timeAgo } from "@dub/utils";
-import { FolderOpen, MoreVertical, Trash } from "lucide-react";
-import { useState } from "react";
-import useSWR from "swr";
-
-export default function TokensPageClient() {
- const { data: tokens, isLoading } = useSWR<TokenProps[]>(
- "/api/user/tokens",
- fetcher,
- );
-
- return (
- <>
- <Callout variant="warn" size={2}>
- User API Keys have been replaced by Workspace API Keys. We recommend
- creating a new{" "}
- <a
- href="https://dub.co/docs/api-reference/tokens"
- target="_blank"
- className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
- >
- Workspace API Key
- </a>{" "}
- for more granular control over your resources such as Links, Tags,
- Domains, Analytics, etc.{" "}
- <a
- href="https://dub.co/blog/workspace-api-keys"
- target="_blank"
- className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
- >
- Read the announcement.
- </a>
- </Callout>
-
- <div className="mt-6 rounded-lg border border-neutral-200 bg-white">
- {isLoading || !tokens ? (
- <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
- <LoadingSpinner className="h-6 w-6 text-neutral-500" />
- <p className="text-sm text-neutral-500">Fetching API keys...</p>
- </div>
- ) : tokens.length > 0 ? (
- <div>
- <div className="grid grid-cols-5 border-b border-neutral-200 px-5 py-2 text-sm font-medium text-neutral-500 sm:px-10">
- <div className="col-span-3">Name</div>
- <div>Key</div>
- <div className="text-center">Last used</div>
- </div>
- <div className="divide-y divide-neutral-200">
- {tokens.map((token) => (
- <TokenRow key={token.id} {...token} />
- ))}
- </div>
- </div>
- ) : (
- <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
- <FolderOpen className="h-6 w-6 text-neutral-500" />
- <p className="text-sm text-neutral-500">
- No API keys found. Create one above.
- </p>
- </div>
- )}
- </div>
- </>
- );
-}
-
-const TokenRow = (token: TokenProps) => {
- const [openPopover, setOpenPopover] = useState(false);
-
- const { DeleteTokenModal, setShowDeleteTokenModal } = useDeleteTokenModal({
- token,
- });
-
- return (
- <>
- <DeleteTokenModal />
- <div className="relative grid grid-cols-5 items-center px-5 py-3 sm:px-10">
- <div className="col-span-3 flex items-center space-x-3">
- <TokenAvatar id={token.id} />
- <div className="flex flex-col space-y-px">
- <p className="font-semibold text-neutral-700">{token.name}</p>
- <p className="text-sm text-neutral-500" suppressHydrationWarning>
- Created {timeAgo(token.createdAt, { withAgo: true })}
- </p>
- </div>
- </div>
- <div className="font-mono text-sm">{token.partialKey}</div>
- <div
- className="text-center text-sm text-neutral-500"
- suppressHydrationWarning
- >
- {timeAgo(token.lastUsed)}
- </div>
- <Popover
- content={
- <div className="grid w-full gap-1 p-2 sm:w-48">
- <button
- onClick={() => {
- setOpenPopover(false);
- setShowDeleteTokenModal(true);
- }}
- className="rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
- >
- <IconMenu
- text="Delete API Key"
- icon={<Trash className="h-4 w-4" />}
- />
- </button>
- </div>
- }
- align="end"
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
- <button
- onClick={() => {
- setOpenPopover(!openPopover);
- }}
- className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-neutral-100 active:bg-neutral-200"
- >
- <MoreVertical className="h-5 w-5 text-neutral-500" />
- </button>
- </Popover>
- </div>
- </>
- );
-};
diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
index f3935e4300..692a251af4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/account/settings/tokens/page.tsx
@@ -1,8 +1,23 @@
+"use client";
+
+import { TokenProps } from "@/lib/types";
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
-import TokensPageClient from "./page-client";
+import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
+import { Callout } from "@/ui/shared/callout";
+import { TokenAvatar } from "@/ui/token-avatar";
+import { IconMenu, LoadingSpinner, Popover } from "@dub/ui";
+import { fetcher, timeAgo } from "@dub/utils";
+import { FolderOpen, MoreVertical, Trash } from "lucide-react";
+import { useState } from "react";
+import useSWR from "swr";
export default function TokensPage() {
+ const { data: tokens, isLoading } = useSWR<TokenProps[]>(
+ "/api/user/tokens",
+ fetcher,
+ );
+
return (
<PageContent
title="API Keys"
@@ -13,8 +28,118 @@ export default function TokensPage() {
}}
>
<PageWidthWrapper>
- <TokensPageClient />
+ <Callout variant="warn" size={2}>
+ User API Keys have been replaced by Workspace API Keys. We recommend
+ creating a new{" "}
+ <a
+ href="https://dub.co/docs/api-reference/tokens"
+ target="_blank"
+ className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
+ >
+ Workspace API Key
+ </a>{" "}
+ for more granular control over your resources such as Links, Tags,
+ Domains, Analytics, etc.{" "}
+ <a
+ href="https://dub.co/blog/workspace-api-keys"
+ target="_blank"
+ className="font-medium underline underline-offset-2 transition-colors hover:text-neutral-800"
+ >
+ Read the announcement.
+ </a>
+ </Callout>
+
+ <div className="mt-6 rounded-lg border border-neutral-200 bg-white">
+ {isLoading || !tokens ? (
+ <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
+ <LoadingSpinner className="h-6 w-6 text-neutral-500" />
+ <p className="text-sm text-neutral-500">Fetching API keys...</p>
+ </div>
+ ) : tokens.length > 0 ? (
+ <div>
+ <div className="grid grid-cols-5 border-b border-neutral-200 px-5 py-2 text-sm font-medium text-neutral-500 sm:px-10">
+ <div className="col-span-3">Name</div>
+ <div>Key</div>
+ <div className="text-center">Last used</div>
+ </div>
+ <div className="divide-y divide-neutral-200">
+ {tokens.map((token) => (
+ <TokenRow key={token.id} {...token} />
+ ))}
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
+ <FolderOpen className="h-6 w-6 text-neutral-500" />
+ <p className="text-sm text-neutral-500">
+ No API keys found. Create one above.
+ </p>
+ </div>
+ )}
+ </div>
</PageWidthWrapper>
</PageContent>
);
}
+
+const TokenRow = (token: TokenProps) => {
+ const [openPopover, setOpenPopover] = useState(false);
+
+ const { DeleteTokenModal, setShowDeleteTokenModal } = useDeleteTokenModal({
+ token,
+ });
+
+ return (
+ <>
+ <DeleteTokenModal />
+ <div className="relative grid grid-cols-5 items-center px-5 py-3 sm:px-10">
+ <div className="col-span-3 flex items-center space-x-3">
+ <TokenAvatar id={token.id} />
+ <div className="flex flex-col space-y-px">
+ <p className="font-semibold text-neutral-700">{token.name}</p>
+ <p className="text-sm text-neutral-500" suppressHydrationWarning>
+ Created {timeAgo(token.createdAt, { withAgo: true })}
+ </p>
+ </div>
+ </div>
+ <div className="font-mono text-sm">{token.partialKey}</div>
+ <div
+ className="text-center text-sm text-neutral-500"
+ suppressHydrationWarning
+ >
+ {timeAgo(token.lastUsed)}
+ </div>
+ <Popover
+ content={
+ <div className="grid w-full gap-1 p-2 sm:w-48">
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ setShowDeleteTokenModal(true);
+ }}
+ className="rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
+ >
+ <IconMenu
+ text="Delete API Key"
+ icon={<Trash className="h-4 w-4" />}
+ />
+ </button>
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <button
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-neutral-100 active:bg-neutral-200"
+ >
+ <MoreVertical className="h-5 w-5 text-neutral-500" />
+ </button>
+ </Popover>
+ </div>
+ </>
+ );
+};
diff --git a/apps/web/lib/zod/schemas/token.ts b/apps/web/lib/zod/schemas/token.ts
index 08964a93bf..52a7f45756 100644
--- a/apps/web/lib/zod/schemas/token.ts
+++ b/apps/web/lib/zod/schemas/token.ts
@@ -40,6 +40,7 @@ export const tokenSchema = z.object({
user: z.object({
id: z.string(),
name: z.string().nullable(),
+ email: z.string().nullable(),
image: z.string().nullable(),
isMachine: z.boolean(),
}),
diff --git a/apps/web/ui/links/link-title-column.tsx b/apps/web/ui/links/link-title-column.tsx
index 857cb8f2e8..6302686728 100644
--- a/apps/web/ui/links/link-title-column.tsx
+++ b/apps/web/ui/links/link-title-column.tsx
@@ -4,7 +4,6 @@ import useCurrentFolderId from "@/lib/swr/use-current-folder-id";
import useDomain from "@/lib/swr/use-domain";
import useFolder from "@/lib/swr/use-folder";
import useWorkspace from "@/lib/swr/use-workspace";
-import { UserProps } from "@/lib/types";
import { UserAvatar } from "@/ui/users/user-avatar";
import {
ArrowTurnRight2,
@@ -414,7 +413,16 @@ const Details = memo(
},
);
-export function UserAvatarWithTooltip({ user }: { user: UserProps }) {
+export function UserAvatarWithTooltip({
+ user,
+}: {
+ user: {
+ id?: string;
+ name?: string | null;
+ email?: string | null;
+ image?: string | null;
+ };
+}) {
const { slug } = useParams();
return (
<Tooltip