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.

WIP customer pages

Tim Wilson9b1a70f43d92
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
new file mode 100644
index 0000000000..5786660a94
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
@@ -0,0 +1,68 @@
+"use client";
+
+import useCustomer from "@/lib/swr/use-customer";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { CopyButton, Tooltip } from "@dub/ui";
+import { COUNTRIES, DICEBEAR_AVATAR_URL } from "@dub/utils";
+import { notFound, useParams } from "next/navigation";
+
+export function CustomerPageClient() {
+ const { customerId } = useParams<{ customerId: string }>();
+
+ const { slug } = useWorkspace();
+ const { data: customer, isLoading, error } = useCustomer({ customerId });
+
+ if (isLoading) return <div>Loading...</div>;
+ if (error) return <div>Error: {error.message}</div>;
+
+ if (!customer) notFound();
+
+ return (
+ <div className="mt-4 flex items-center gap-4">
+ <div className="relative w-fit">
+ <img
+ src={customer.avatar || `${DICEBEAR_AVATAR_URL}${customer.name}`}
+ alt={customer.name}
+ className="size-12 rounded-full"
+ />
+ {customer.country && (
+ <Tooltip content={COUNTRIES[customer.country]}>
+ <div className="absolute -right-1 top-0 overflow-hidden rounded-full bg-neutral-50 p-0.5 transition-transform duration-100 hover:scale-[1.15]">
+ <img
+ alt=""
+ src={`https://flag.vercel.app/m/${customer.country}.svg`}
+ className="size-3 rounded-full"
+ />
+ </div>
+ </Tooltip>
+ )}
+ </div>
+ <div className="flex flex-col gap-1">
+ <div className="flex items-center gap-2">
+ <h1 className="text-lg font-semibold leading-tight text-neutral-900">
+ {customer.name}
+ </h1>
+ <span className="rounded-full border border-neutral-200 bg-neutral-200 px-1.5 py-0.5 text-xs text-neutral-900">
+ {new Date(customer.createdAt).toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ })}
+ </span>
+ </div>
+
+ {customer.email && (
+ <div className="flex items-center gap-1">
+ <span className="text-sm text-neutral-500">{customer.email}</span>
+ <CopyButton
+ value={customer.email}
+ variant="neutral"
+ className="p-1 [&>*]:h-3 [&>*]:w-3"
+ successMessage="Copied email to clipboard!"
+ />
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page.tsx
new file mode 100644
index 0000000000..19c6afb82d
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page.tsx
@@ -0,0 +1,13 @@
+import { PageContent } from "@/ui/layout/page-content";
+import { MaxWidthWrapper } from "@dub/ui";
+import { CustomerPageClient } from "./page-client";
+
+export default function CustomerPage() {
+ return (
+ <PageContent>
+ <MaxWidthWrapper>
+ <CustomerPageClient />
+ </MaxWidthWrapper>
+ </PageContent>
+ );
+}
diff --git a/apps/web/lib/swr/use-customer.ts b/apps/web/lib/swr/use-customer.ts
new file mode 100644
index 0000000000..4162f6b322
--- /dev/null
+++ b/apps/web/lib/swr/use-customer.ts
@@ -0,0 +1,38 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import { z } from "zod";
+import { CustomerProps } from "../types";
+import { getCustomersQuerySchema } from "../zod/schemas/customers";
+import useWorkspace from "./use-workspace";
+
+const partialQuerySchema = getCustomersQuerySchema.pick({
+ includeExpandedFields: true,
+});
+
+export default function useCustomer({
+ customerId,
+ query,
+ enabled = true,
+}: {
+ customerId: CustomerProps["id"];
+ query?: z.infer<typeof partialQuerySchema>;
+ enabled?: boolean;
+}) {
+ const { id: workspaceId } = useWorkspace();
+
+ const { data, error, isLoading } = useSWR<CustomerProps>(
+ enabled && workspaceId
+ ? `/api/customers/${customerId}?${new URLSearchParams({
+ workspaceId: workspaceId,
+ ...query,
+ } as Record<string, any>).toString()}`
+ : undefined,
+ fetcher,
+ );
+
+ return {
+ data,
+ isLoading,
+ error,
+ };
+}