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.

Remove prefixWorkspaceId from recordLink, update admin (#3024)

Steven Teye47732f00d50
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx
index 11fa0863ad..f30a7f4077 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/user-info.tsx
@@ -1,5 +1,6 @@
"use client";
-import { Badge, Copy, Tick, useCopyToClipboard } from "@dub/ui";
+import { PartnerStatusBadges } from "@/ui/partners/partner-status-badges";
+import { Badge, Copy, StatusBadge, Tick, useCopyToClipboard } from "@dub/ui";
import { capitalize, nFormatter } from "@dub/utils";
import { toast } from "sonner";
@@ -15,22 +16,41 @@ export interface UserInfoProps {
totalClicks: number;
totalLinks: number;
}[];
+ programs: {
+ id: string;
+ name: string;
+ slug: string;
+ status: string;
+ totalClicks: number;
+ totalLeads: number;
+ totalConversions: number;
+ totalSaleAmount: number;
+ totalCommissions: number;
+ }[];
impersonateUrl: {
app: string;
partners: string;
};
}
-const items = [
+const workspaceItems = [
{ id: "clicks", label: "Clicks" },
{ id: "links", label: "Links" },
{ id: "totalClicks", label: "Total Clicks" },
{ id: "totalLinks", label: "Total Links" },
];
+const programItems = [
+ { id: "totalClicks", label: "Total Clicks" },
+ { id: "totalLeads", label: "Total Leads" },
+ { id: "totalConversions", label: "Total Conversions" },
+ { id: "totalSaleAmount", label: "Total Sales", isCurrency: true },
+ { id: "totalCommissions", label: "Total Commissions", isCurrency: true },
+];
+
export default function UserInfo({ data }: { data: UserInfoProps }) {
return (
- <div className="grid gap-2">
+ <div className="grid gap-4">
<LoginLinkCopyButton text={data.email} url={data.email} />
<LoginLinkCopyButton
text="app.dub.co login link"
@@ -40,39 +60,96 @@ export default function UserInfo({ data }: { data: UserInfoProps }) {
text="partners.dub.co login link"
url={data.impersonateUrl.partners}
/>
- <div className="grid grid-cols-2 gap-4">
- {data.workspaces.map((workspace) => (
- <div
- key={workspace.slug}
- className="flex flex-col space-y-2 rounded-lg border border-neutral-200 p-2"
- >
- <div className="flex items-center space-x-2">
- <p className="font-semibold">{workspace.name}</p>
- <Badge className="lowercase">{workspace.slug}</Badge>
- </div>
- <div className="flex justify-between text-sm">
- <span className="font-medium text-neutral-700">ID</span>
- <span className="text-neutral-500">{workspace.id}</span>
- </div>
- <div className="flex justify-between text-sm">
- <span className="font-medium text-neutral-700">Plan</span>
- <span className="text-neutral-500">
- {capitalize(workspace.plan)}
- </span>
- </div>
- {items.map((item) => (
- <div className="flex justify-between text-sm">
- <span className="font-medium text-neutral-700">
- {item.label}
- </span>
- <span className="text-neutral-500">
- {nFormatter(workspace[item.id], { full: true })}
- </span>
+
+ {data.workspaces.length > 0 && (
+ <div>
+ <h3 className="mb-2 text-sm font-semibold text-neutral-900">
+ Workspaces
+ </h3>
+ <div className="grid grid-cols-2 gap-4">
+ {data.workspaces.map((workspace) => (
+ <div
+ key={workspace.slug}
+ className="flex flex-col space-y-2 rounded-lg border border-neutral-200 p-2"
+ >
+ <div className="flex items-center space-x-2">
+ <p className="font-semibold">{workspace.name}</p>
+ <Badge className="lowercase">{workspace.slug}</Badge>
+ </div>
+ <div className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">ID</span>
+ <span className="text-neutral-500">{workspace.id}</span>
+ </div>
+ <div className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">Plan</span>
+ <span className="text-neutral-500">
+ {capitalize(workspace.plan)}
+ </span>
+ </div>
+ {workspaceItems.map((item) => (
+ <div key={item.id} className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">
+ {item.label}
+ </span>
+ <span className="text-neutral-500">
+ {nFormatter(workspace[item.id], { full: true })}
+ </span>
+ </div>
+ ))}
</div>
))}
</div>
- ))}
- </div>
+ </div>
+ )}
+
+ {data.workspaces.length > 0 && data.programs.length > 0 && (
+ <div className="my-2 border-b border-neutral-200" />
+ )}
+
+ {data.programs.length > 0 && (
+ <div>
+ <h3 className="mb-2 text-sm font-semibold text-neutral-900">
+ Programs
+ </h3>
+ <div className="grid grid-cols-2 gap-4">
+ {data.programs.map((program) => (
+ <div
+ key={program.id}
+ className="flex flex-col space-y-2 rounded-lg border border-neutral-200 p-2"
+ >
+ <div className="flex items-center space-x-2">
+ <p className="font-semibold">{program.name}</p>
+ <Badge className="lowercase">{program.slug}</Badge>
+ </div>
+ <div className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">ID</span>
+ <span className="text-neutral-500">{program.id}</span>
+ </div>
+ <div className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">Status</span>
+ <StatusBadge
+ variant={PartnerStatusBadges[program.status].variant}
+ >
+ {PartnerStatusBadges[program.status].label}
+ </StatusBadge>
+ </div>
+ {programItems.map((item) => (
+ <div key={item.id} className="flex justify-between text-sm">
+ <span className="font-medium text-neutral-700">
+ {item.label}
+ </span>
+ <span className="text-neutral-500">
+ {item.isCurrency
+ ? `$${nFormatter(program[item.id], { full: true })}`
+ : nFormatter(program[item.id], { full: true })}
+ </span>
+ </div>
+ ))}
+ </div>
+ ))}
+ </div>
+ </div>
+ )}
</div>
);
}
diff --git a/apps/web/app/(ee)/api/admin/impersonate/route.ts b/apps/web/app/(ee)/api/admin/impersonate/route.ts
index 5cb580091f..f765db7eba 100644
--- a/apps/web/app/(ee)/api/admin/impersonate/route.ts
+++ b/apps/web/app/(ee)/api/admin/impersonate/route.ts
@@ -1,4 +1,3 @@
-import { prefixWorkspaceId } from "@/lib/api/workspaces/workspace-id";
import { hashToken, withAdmin } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { APP_DOMAIN, PARTNERS_DOMAIN } from "@dub/utils";
@@ -39,6 +38,39 @@ export const POST = withAdmin(async ({ req }) => {
},
},
},
+ orderBy: {
+ project: {
+ totalClicks: "desc",
+ },
+ },
+ },
+ partners: {
+ select: {
+ partner: {
+ select: {
+ programs: {
+ select: {
+ program: {
+ select: {
+ id: true,
+ name: true,
+ slug: true,
+ },
+ },
+ status: true,
+ totalClicks: true,
+ totalLeads: true,
+ totalConversions: true,
+ totalSaleAmount: true,
+ totalCommissions: true,
+ },
+ orderBy: {
+ totalCommissions: "desc",
+ },
+ },
+ },
+ },
+ },
},
},
});
@@ -51,12 +83,17 @@ export const POST = withAdmin(async ({ req }) => {
email: response.email,
workspaces: response.projects.map(({ project }) => ({
...project,
- id: prefixWorkspaceId(project.id),
clicks: project.usage,
links: project.linksUsage,
totalClicks: project.totalClicks,
totalLinks: project.totalLinks,
})),
+ programs: response.partners[0].partner.programs.map(
+ ({ program, ...rest }) => ({
+ ...program,
+ ...rest,
+ }),
+ ),
impersonateUrl: await getImpersonateUrl(response.email),
};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/page-client.tsx
index d8ad38455d..8a46bed783 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/page-client.tsx
@@ -4,7 +4,6 @@ import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import DeleteWorkspace from "@/ui/workspaces/delete-workspace";
import UploadLogo from "@/ui/workspaces/upload-logo";
-import WorkspaceId from "@/ui/workspaces/workspace-id";
import { Form } from "@dub/ui";
import { useSession } from "next-auth/react";
import { useRouter } from "next/navigation";
@@ -92,7 +91,6 @@ export default function WorkspaceSettingsClient() {
}
/>
<UploadLogo />
- <WorkspaceId />
<DeleteWorkspace />
</>
);
diff --git a/apps/web/lib/tinybird/record-link.ts b/apps/web/lib/tinybird/record-link.ts
index ef33bdd1f5..8d9ea38e8a 100644
--- a/apps/web/lib/tinybird/record-link.ts
+++ b/apps/web/lib/tinybird/record-link.ts
@@ -2,7 +2,6 @@ import { waitUntil } from "@vercel/functions";
import { z } from "zod";
import { ExpandedLink } from "../api/links";
import { decodeKeyIfCaseSensitive } from "../api/links/case-sensitivity";
-import { prefixWorkspaceId } from "../api/workspaces/workspace-id";
import { tb, tbOld } from "./client";
export const dubLinksMetadataSchema = z.object({
@@ -46,10 +45,7 @@ export const recordLinkTB = tb.buildIngestEndpoint({
workspace_id: z
.string()
.nullish()
- .transform((v) => {
- if (!v) return ""; // return empty string if null or undefined
- return prefixWorkspaceId(v);
- }),
+ .transform((v) => (v ? v : "")),
}),
wait: true,
});
diff --git a/apps/web/ui/workspaces/workspace-id.tsx b/apps/web/ui/workspaces/workspace-id.tsx
deleted file mode 100644
index 0ed6c950d7..0000000000
--- a/apps/web/ui/workspaces/workspace-id.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-"use client";
-
-import useWorkspace from "@/lib/swr/use-workspace";
-import { CopyButton } from "@dub/ui";
-
-export default function WorkspaceId() {
- const { id } = useWorkspace();
-
- return (
- <>
- <div className="rounded-lg border border-neutral-200 bg-white">
- <div className="relative flex flex-col space-y-6 p-5 sm:p-10">
- <div className="flex flex-col space-y-3">
- <h2 className="text-xl font-medium">Workspace ID</h2>
- <p className="text-sm text-neutral-500">
- Unique ID of your workspace on Dub.
- </p>
- </div>
- {id ? (
- <div className="flex w-full max-w-md items-center justify-between rounded-md border border-neutral-300 bg-white p-2">
- <p className="text-sm text-neutral-500">{id}</p>
- <CopyButton value={id} className="rounded-md" />
- </div>
- ) : (
- <div className="h-[2.35rem] w-full max-w-md animate-pulse rounded-md bg-neutral-200" />
- )}
- </div>
- <div className="flex items-center justify-between rounded-b-lg border-t border-neutral-200 bg-neutral-50 px-3 py-5 sm:px-10">
- <p className="text-sm text-neutral-500">
- Used to identify your workspace when interacting with the{" "}
- <a
- href="https://dub.co/api"
- target="_blank"
- className="underline underline-offset-2 transition-colors hover:text-neutral-700"
- >
- Dub API
- </a>
- .
- </p>
- </div>
- </div>
- </>
- );
-}