The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
change default `groupBy` to `type`
Steven Tey1a8b9fcae18b
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-composite-chart.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-composite-chart.tsxindex c9efeb8583..e160eec459 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-composite-chart.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-composite-chart.tsx@@ -52,7 +52,7 @@ export function EarningsCompositeChart() {start,end,interval = DUB_PARTNERS_ANALYTICS_INTERVAL,- groupBy = "linkId",+ groupBy = "type",} = searchParamsObj as {start?: string;end?: string;@@ -150,20 +150,20 @@ export function EarningsCompositeChart() {{label: (<div className="flex items-center gap-1.5 text-neutral-600">- <Hyperlink className="size-4" />- <span className="text-sm">Link</span>+ <Sliders className="size-4" />+ <span className="text-sm">Type</span></div>),- value: "linkId",+ value: "type",},{label: (<div className="flex items-center gap-1.5 text-neutral-600">- <Sliders className="size-4" />- <span className="text-sm">Type</span>+ <Hyperlink className="size-4" />+ <span className="text-sm">Link</span></div>),- value: "type",+ value: "linkId",},]}selected={groupBy}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page-client.tsxdeleted file mode 100644index 765a7a41f5..0000000000--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page-client.tsx+++ /dev/null@@ -1,100 +0,0 @@-"use client";--import { CUSTOMER_PAGE_EVENTS_LIMIT } from "@/lib/constants/misc";-import useCustomer from "@/lib/swr/use-customer";-import useWorkspace from "@/lib/swr/use-workspace";-import { CommissionResponse, CustomerEnriched } from "@/lib/types";-import { CustomerPartnerEarningsTable } from "@/ui/customers/customer-partner-earnings-table";-import { PartnerAvatar } from "@/ui/partners/partner-avatar";-import { ArrowUpRight } from "@dub/ui";-import { fetcher } from "@dub/utils";-import Link from "next/link";-import { redirect, useParams } from "next/navigation";-import { memo } from "react";-import useSWR from "swr";--export function CustomerEarningsPageClient() {- const { customerId } = useParams<{ customerId: string }>();-- const { slug } = useWorkspace();- const { data: customer, isLoading } = useCustomer<CustomerEnriched>({- customerId,- query: { includeExpandedFields: true },- });-- if (!customer && !isLoading) redirect(`/${slug}/customers`);-- return !customer || (customer.partner && customer.programId) ? (- <section className="flex flex-col gap-4">- <h2 className="text-lg font-semibold text-neutral-900">- Partner earnings- </h2>- <div className="border-border-subtle flex flex-col overflow-hidden rounded-lg border">- <Link- href={`/${slug}/program/partners/${customer?.partner?.id}`}- target="_blank"- className="group flex items-center justify-between overflow-hidden bg-neutral-100 px-3 py-2.5"- >- <div className="flex min-w-0 items-center gap-3">- {customer?.partner ? (- <>- <PartnerAvatar partner={customer.partner} className="size-5" />- <span className="block min-w-0 truncate text-sm font-medium text-neutral-900">- {customer.partner.name}- </span>- </>- ) : (- <>- <div className="size-5 animate-pulse rounded-full bg-neutral-200" />- <div className="h-5 w-24 animate-pulse rounded bg-neutral-200" />- </>- )}- </div>- <ArrowUpRight className="size-3 shrink-0 -translate-x-0.5 translate-y-0.5 opacity-0 transition-[transform,opacity] group-hover:translate-x-0 group-hover:translate-y-0 group-hover:opacity-100" />- </Link>-- <div className="border-border-subtle border-t">- <PartnerEarningsTable customerId={customerId} />- </div>- </div>- </section>- ) : null;-}--const PartnerEarningsTable = memo(({ customerId }: { customerId: string }) => {- const { id: workspaceId, slug } = useWorkspace();-- const { data: commissions, isLoading: isComissionsLoading } = useSWR<- CommissionResponse[]- >(- `/api/commissions?${new URLSearchParams({- customerId,- workspaceId: workspaceId!,- pageSize: CUSTOMER_PAGE_EVENTS_LIMIT.toString(),- })}`,- fetcher,- );-- const { data: totalCommissions, isLoading: isTotalCommissionsLoading } =- useSWR<{ all: { count: number } }>(- // Only fetch total earnings count if the earnings data is equal to the limit- commissions?.length === CUSTOMER_PAGE_EVENTS_LIMIT &&- `/api/commissions/count?${new URLSearchParams({- customerId,- workspaceId: workspaceId!,- })}`,- fetcher,- );-- return (- <CustomerPartnerEarningsTable- commissions={commissions}- totalCommissions={- isTotalCommissionsLoading- ? undefined- : totalCommissions?.all?.count ?? commissions?.length- }- isLoading={isComissionsLoading}- />- );-});diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page.tsxindex effdf5c3a7..6c9a612a2d 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/links/customers/[customerId]/earnings/page.tsx@@ -1,5 +1,100 @@-import { CustomerEarningsPageClient } from "./page-client";+"use client";++import { CUSTOMER_PAGE_EVENTS_LIMIT } from "@/lib/constants/misc";+import useCustomer from "@/lib/swr/use-customer";+import useWorkspace from "@/lib/swr/use-workspace";+import { CommissionResponse, CustomerEnriched } from "@/lib/types";+import { CustomerPartnerEarningsTable } from "@/ui/customers/customer-partner-earnings-table";+import { PartnerAvatar } from "@/ui/partners/partner-avatar";+import { ArrowUpRight } from "@dub/ui";+import { fetcher } from "@dub/utils";+import Link from "next/link";+import { redirect, useParams } from "next/navigation";+import { memo } from "react";+import useSWR from "swr";export default function CustomerEarningsPage() {- return <CustomerEarningsPageClient />;+ const { customerId } = useParams<{ customerId: string }>();++ const { slug } = useWorkspace();+ const { data: customer, isLoading } = useCustomer<CustomerEnriched>({+ customerId,+ query: { includeExpandedFields: true },+ });++ if (!customer && !isLoading) redirect(`/${slug}/customers`);++ return !customer || (customer.partner && customer.programId) ? (+ <section className="flex flex-col gap-4">+ <h2 className="text-lg font-semibold text-neutral-900">+ Partner earnings+ </h2>+ <div className="border-border-subtle flex flex-col overflow-hidden rounded-lg border">+ <Link+ href={`/${slug}/program/partners/${customer?.partner?.id}`}+ target="_blank"+ className="group flex items-center justify-between overflow-hidden bg-neutral-100 px-3 py-2.5"+ >+ <div className="flex min-w-0 items-center gap-3">+ {customer?.partner ? (+ <>+ <PartnerAvatar partner={customer.partner} className="size-5" />+ <span className="block min-w-0 truncate text-sm font-medium text-neutral-900">+ {customer.partner.name}+ </span>+ </>+ ) : (+ <>+ <div className="size-5 animate-pulse rounded-full bg-neutral-200" />+ <div className="h-5 w-24 animate-pulse rounded bg-neutral-200" />+ </>+ )}+ </div>+ <ArrowUpRight className="size-3 shrink-0 -translate-x-0.5 translate-y-0.5 opacity-0 transition-[transform,opacity] group-hover:translate-x-0 group-hover:translate-y-0 group-hover:opacity-100" />+ </Link>++ <div className="border-border-subtle border-t">+ <PartnerEarningsTable customerId={customerId} />+ </div>+ </div>+ </section>+ ) : null;}++const PartnerEarningsTable = memo(({ customerId }: { customerId: string }) => {+ const { id: workspaceId, slug } = useWorkspace();++ const { data: commissions, isLoading: isComissionsLoading } = useSWR<+ CommissionResponse[]+ >(+ `/api/commissions?${new URLSearchParams({+ customerId,+ workspaceId: workspaceId!,+ pageSize: CUSTOMER_PAGE_EVENTS_LIMIT.toString(),+ })}`,+ fetcher,+ );++ const { data: totalCommissions, isLoading: isTotalCommissionsLoading } =+ useSWR<{ all: { count: number } }>(+ // Only fetch total earnings count if the earnings data is equal to the limit+ commissions?.length === CUSTOMER_PAGE_EVENTS_LIMIT &&+ `/api/commissions/count?${new URLSearchParams({+ customerId,+ workspaceId: workspaceId!,+ })}`,+ fetcher,+ );++ return (+ <CustomerPartnerEarningsTable+ commissions={commissions}+ totalCommissions={+ isTotalCommissionsLoading+ ? undefined+ : totalCommissions?.all?.count ?? commissions?.length+ }+ isLoading={isComissionsLoading}+ />+ );+});