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.

update UI

Steven Tey13da7a19b7cd
diff --git a/apps/web/app/api/tokens/route.ts b/apps/web/app/api/tokens/route.ts
index 171a23a67b..c28d8babbc 100644
--- a/apps/web/app/api/tokens/route.ts
+++ b/apps/web/app/api/tokens/route.ts
@@ -12,6 +12,40 @@ import { sendEmail } from "emails";
import APIKeyCreated from "emails/api-key-created";
import { NextResponse } from "next/server";
+// GET /api/tokens - get all tokens for a workspace
+export const GET = withWorkspace(
+ async ({ workspace }) => {
+ const tokens = await prisma.restrictedToken.findMany({
+ where: {
+ projectId: workspace.id,
+ },
+ select: {
+ id: true,
+ name: true,
+ partialKey: true,
+ scopes: true,
+ lastUsed: true,
+ createdAt: true,
+ updatedAt: true,
+ user: {
+ select: {
+ id: true,
+ name: true,
+ image: true,
+ isMachine: true,
+ },
+ },
+ },
+ orderBy: [{ lastUsed: "desc" }, { createdAt: "desc" }],
+ });
+
+ return NextResponse.json(tokenSchema.array().parse(tokens));
+ },
+ {
+ requiredPermissions: ["tokens.read"],
+ },
+);
+
// POST /api/tokens – create a new token for a workspace
export const POST = withWorkspace(
async ({ req, session, workspace }) => {
@@ -81,7 +115,6 @@ export const POST = withWorkspace(
userId: isMachine ? machineUser?.id! : session.user.id,
projectId: workspace.id,
rateLimit: getCurrentPlan(workspace.plan).limits.api,
- createdBy: session.user.id,
scopes:
scopes && scopes.length > 0 ? [...new Set(scopes)].join(" ") : null,
},
@@ -112,37 +145,3 @@ export const POST = withWorkspace(
requiredPermissions: ["tokens.write"],
},
);
-
-// GET /api/tokens - get all tokens for a workspace
-export const GET = withWorkspace(
- async ({ workspace }) => {
- const tokens = await prisma.restrictedToken.findMany({
- where: {
- projectId: workspace.id,
- },
- select: {
- id: true,
- name: true,
- partialKey: true,
- scopes: true,
- lastUsed: true,
- createdAt: true,
- updatedAt: true,
- user: {
- select: {
- id: true,
- name: true,
- image: true,
- isMachine: true,
- },
- },
- },
- orderBy: [{ lastUsed: "desc" }, { createdAt: "desc" }],
- });
-
- return NextResponse.json(tokenSchema.array().parse(tokens));
- },
- {
- requiredPermissions: ["tokens.read"],
- },
-);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
index 2f213201d7..71e7fbff4e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
@@ -8,8 +8,16 @@ import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
import EmptyState from "@/ui/shared/empty-state";
import { Delete } from "@/ui/shared/icons";
-import { Badge, Button, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";
+import {
+ Avatar,
+ Badge,
+ Button,
+ LoadingSpinner,
+ Popover,
+ TokenAvatar,
+} from "@dub/ui";
import { Key } from "@dub/ui/src/icons";
+import { Tooltip } from "@dub/ui/src/tooltip";
import { fetcher, timeAgo } from "@dub/utils";
import { Edit3, MoreVertical } from "lucide-react";
import { useState } from "react";
@@ -114,13 +122,40 @@ const TokenRow = (token: TokenProps) => {
<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-gray-700">{token.name}</p>
+ <div className="flex flex-col gap-y-px">
<div className="flex items-center gap-x-2">
+ <p className="font-semibold text-gray-700">{token.name}</p>
+ <Badge variant="neutral">{scopesToName(token.scopes).name}</Badge>
+ </div>
+ <div className="flex items-center gap-x-1">
+ <Tooltip
+ content={
+ <div className="w-full max-w-xs p-4">
+ <Avatar user={token.user} className="h-10 w-10" />
+ <div className="mt-2 flex items-center gap-x-1.5">
+ <p className="text-sm font-semibold text-gray-700">
+ {token.user.name || "Anonymous User"}
+ </p>
+ </div>
+ <p className="mt-1 text-xs text-gray-500">
+ Created{" "}
+ {new Date(token.createdAt).toLocaleDateString("en-us", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ })}
+ </p>
+ </div>
+ }
+ >
+ <div>
+ <Avatar user={token.user} className="h-4 w-4" />
+ </div>
+ </Tooltip>
+ <p>•</p>
<p className="text-sm text-gray-500" suppressHydrationWarning>
- Created {timeAgo(token.createdAt, { withAgo: true })}
+ {timeAgo(token.createdAt)}
</p>
- <Badge variant="neutral">{scopesToName(token.scopes).name}</Badge>
</div>
</div>
</div>
diff --git a/apps/web/lib/zod/schemas/token.ts b/apps/web/lib/zod/schemas/token.ts
index 288fcb8baa..1e93437ddf 100644
--- a/apps/web/lib/zod/schemas/token.ts
+++ b/apps/web/lib/zod/schemas/token.ts
@@ -36,6 +36,7 @@ export const tokenSchema = z.object({
user: z.object({
id: z.string(),
name: z.string().nullable(),
+ image: z.string().nullable(),
isMachine: z.boolean(),
}),
});
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 609b0fd8bb..9bb76fd438 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -102,14 +102,12 @@ model RestrictedToken {
updatedAt DateTime @updatedAt
userId String
projectId String
- createdBy String? // user who created the token
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@index([userId])
@@index([projectId])
- @@index([createdBy])
}
model Project {
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index 89ccd1b677..5989b3efe4 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -395,7 +395,7 @@ export default function LinkCard({
</BadgeTooltip>
)}
</div>
- <div className="flex max-w-fit items-center space-x-1">
+ <div className="flex max-w-fit items-center gap-x-1">
<Tooltip
content={
<div className="w-full p-4">