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.

Add basic details

Tim Wilson5cc711d25708
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
index d777bc8148..8506ae6939 100644
--- 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
@@ -2,22 +2,46 @@
import useCustomer from "@/lib/swr/use-customer";
import useWorkspace from "@/lib/swr/use-workspace";
+import { CustomerActivityResponse } from "@/lib/types";
import { BackLink } from "@/ui/shared/back-link";
import { CopyButton } from "@dub/ui";
-import { DICEBEAR_AVATAR_URL } from "@dub/utils";
+import {
+ cn,
+ COUNTRIES,
+ currencyFormatter,
+ DICEBEAR_AVATAR_URL,
+ fetcher,
+ getPrettyUrl,
+} from "@dub/utils";
+import Link from "next/link";
import { notFound, useParams } from "next/navigation";
+import { HTMLProps } from "react";
+import useSWR from "swr";
export function CustomerPageClient() {
const { customerId } = useParams<{ customerId: string }>();
- const { slug } = useWorkspace();
- const { data: customer, isLoading, error } = useCustomer({ customerId });
+ const { id: workspaceId, slug } = useWorkspace();
+ const {
+ data: customer,
+ isLoading,
+ error,
+ } = useCustomer({ customerId, query: { includeExpandedFields: true } });
+
+ let { data: customerActivity, isLoading: isCustomerActivityLoading } =
+ useSWR<CustomerActivityResponse>(
+ customer &&
+ `/api/customers/${customer.id}/activity?workspaceId=${workspaceId}`,
+ fetcher,
+ );
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
if (!customer) notFound();
+ const link = customerActivity?.link;
+
return (
<div className="mt-2">
<BackLink href={`/${slug}/links`}>Dashboard</BackLink>
@@ -47,6 +71,91 @@ export function CustomerPageClient() {
)}
</div>
</div>
+ <div className="mt-8 grid grid-cols-1 gap-16 md:grid-cols-[minmax(0,1fr)_240px]">
+ {/* Main content */}
+ <div className="flex flex-col gap-10">
+ <section className="flex flex-col gap-4">
+ <h2 className="text-lg font-semibold text-neutral-900">Sales</h2>
+ <div className="h-64 rounded-lg bg-neutral-100" />
+ </section>
+
+ <section className="flex flex-col gap-4">
+ <h2 className="text-lg font-semibold text-neutral-900">Activity</h2>
+ <div className="h-64 rounded-lg bg-neutral-100" />
+ </section>
+ </div>
+
+ {/* Right side details */}
+ <div className="flex flex-col gap-6 text-sm text-neutral-900">
+ {customer.country && (
+ <div className="flex flex-col gap-2">
+ <DetailHeading>Details</DetailHeading>
+ <span className="flex items-center gap-2">
+ <img
+ src={`https://hatscripts.github.io/circle-flags/flags/${customer.country.toLowerCase()}.svg`}
+ alt=""
+ className="size-3.5"
+ />
+ {COUNTRIES[customer.country]}
+ </span>
+ </div>
+ )}
+
+ <div className="flex flex-col gap-2">
+ <DetailHeading>Customer since</DetailHeading>
+ <span>
+ {new Date(customer.createdAt).toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ })}
+ </span>
+ </div>
+
+ <div className="flex flex-col gap-2">
+ <DetailHeading>Lifetime value</DetailHeading>
+ {isCustomerActivityLoading ? (
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
+ ) : (
+ <span>
+ {customerActivity?.ltv !== undefined
+ ? currencyFormatter(customerActivity.ltv / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })
+ : "-"}
+ </span>
+ )}
+ </div>
+
+ <div className="flex flex-col gap-2">
+ <DetailHeading>Referral link </DetailHeading>
+ {isCustomerActivityLoading ? (
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
+ ) : link ? (
+ <Link
+ href={`/${slug}/links/${link.domain}/${link.key}`}
+ target="_blank"
+ className="min-w-0 overflow-hidden truncate hover:text-neutral-950 hover:underline"
+ >
+ {getPrettyUrl(link.shortLink)}
+ </Link>
+ ) : (
+ <span>-</span>
+ )}
+ </div>
+ </div>
+ </div>
</div>
);
}
+
+const DetailHeading = ({
+ className,
+ ...rest
+}: HTMLProps<HTMLHeadingElement>) => (
+ <h2
+ className={cn("font-semibold text-neutral-900", className)}
+ {...rest}
+ ></h2>
+);