The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
optimize partner program overview page
Steven Tey400c0eb9d11b
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.tsindex a92f44fae9..298c35ffbb 100644--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts@@ -41,10 +41,6 @@ export const GET = withPartnerProfile(linkId = foundLink.id;}- if (links.length === 0) {- return NextResponse.json([], { status: 200 });- }-const response = await getAnalytics({...(program.id === "prog_1K0QHV7MP3PR05CJSCF5VN93X"? { event: rest.event, groupBy: "count", interval: "all" }diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsxindex 10a1bfc06b..ca6d70494e 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/page-client.tsx@@ -329,21 +329,27 @@ function StatCard({const { getQueryString } = useRouterStuff();const { start, end, interval } = useContext(ProgramOverviewContext);- const { data: total } = usePartnerAnalytics({- event: "composite",- interval,- start,- end,- });-const { data: timeseries, error } = usePartnerAnalytics({groupBy: "timeseries",+ event: "composite",interval,start,end,- event,});+ const totals = useMemo(() => {+ return timeseries && timeseries.length > 0+ ? timeseries.reduce(+ (acc, { clicks, leads, sales }) => ({+ clicks: acc.clicks + clicks,+ leads: acc.leads + leads,+ sales: acc.sales + sales,+ }),+ { clicks: 0, leads: 0, sales: 0 },+ )+ : { clicks: 0, leads: 0, sales: 0 };+ }, [timeseries]);+return (<div className="group block rounded-lg border border-neutral-300 bg-white p-5 pb-3"><div className="flex justify-between">@@ -351,12 +357,12 @@ function StatCard({<span className="mb-1 block text-base font-semibold leading-none text-neutral-800">{title}</span>- {total !== undefined ? (+ {totals !== undefined ? (<div className="flex items-center gap-1 text-lg font-medium text-neutral-600"><NumberFlow- value={total[event]}+ value={totals[event]}format={{- notation: total[event] > 999999 ? "compact" : "standard",+ notation: totals[event] > 999999 ? "compact" : "standard",}}/></div>diff --git a/apps/web/ui/partners/stat-card.tsx b/apps/web/ui/partners/stat-card.tsxdeleted file mode 100644index a7ed992449..0000000000--- a/apps/web/ui/partners/stat-card.tsx+++ /dev/null@@ -1,90 +0,0 @@-import { MiniAreaChart } from "@dub/ui";-import { LoadingSpinner } from "@dub/ui/icons";-import { currencyFormatter, nFormatter } from "@dub/utils";-import Link from "next/link";--interface StatCardProps {- title: string;- event: "clicks" | "leads" | "sales";- timeseries?: any;- error?: any;- color?: string;- href?: string;- total?: {- clicks: number;- leads: number;- sales: number;- saleAmount: number;- };-}--export function StatCard({- title,- event,- total,- timeseries,- error,- color,- href,-}: StatCardProps) {- return (- <Wrapper- href={href}- className="hover:drop-shadow-card-hover block rounded-md border border-neutral-300 bg-white p-5 transition-[filter]"- >- <span className="block text-sm text-neutral-500">{title}</span>- {total !== undefined ? (- <div className="flex items-center gap-1 text-2xl text-neutral-800">- {nFormatter(total[event])}- {event === "sales" && (- <span className="text-base text-neutral-500">- ({currencyFormatter(total.saleAmount / 100)})- </span>- )}- </div>- ) : (- <div className="h-8 w-16 animate-pulse rounded-md bg-neutral-200" />- )}- <div className="mt-2 h-16 w-full">- {timeseries ? (- <MiniAreaChart- data={timeseries.map((d) => ({- date: new Date(d.start),- value: d[event],- }))}- curve={false}- color={color}- />- ) : (- <div className="flex size-full items-center justify-center">- {error ? (- <span className="text-sm text-neutral-500">- Failed to load data.- </span>- ) : (- <LoadingSpinner />- )}- </div>- )}- </div>- </Wrapper>- );-}--const Wrapper = ({- href,- children,- className,-}: {- href?: string;- children: React.ReactNode;- className?: string;-}) => {- return href ? (- <Link href={href} className={className}>- {children}- </Link>- ) : (- <div className={className}>{children}</div>- );-};