The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
show totals
Steven Tey428803921523
diff --git a/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx b/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsxindex 679eef80a9..8a5d5943d3 100644--- a/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx+++ b/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx@@ -22,6 +22,7 @@ interface TimeseriesData {date: Date;payouts: number;fees: number;+ total: number;}interface InvoiceData {@@ -35,7 +36,7 @@ interface InvoiceData {}type Tab = {- id: "payouts" | "fees";+ id: "payouts" | "fees" | "total";label: string;colorClassName: string;};@@ -61,24 +62,31 @@ export default function PayoutsPageClient() {{id: "payouts",label: "Payouts",- colorClassName: "text-blue-500/50",+ colorClassName: "text-blue-500/50 bg-blue-500/50 border-blue-500",},{id: "fees",label: "Fees",- colorClassName: "text-red-500/50",+ colorClassName: "text-red-500/50 bg-red-500/50 border-red-500",+ },+ {+ id: "total",+ label: "Total",+ colorClassName: "text-green-500/50 bg-green-500/50 border-green-500",},];- const [selectedTab, setSelectedTab] = useState<"payouts" | "fees">("payouts");+ const [selectedTab, setSelectedTab] = useState<"payouts" | "fees" | "total">(+ "payouts",+ );const tab = tabs.find(({ id }) => id === selectedTab) ?? tabs[0];// take the last 12 monthsconst chartData =- timeseriesData?.map(({ date, payouts, fees }) => ({+ timeseriesData?.map(({ date, ...rest }) => ({date: new Date(date),values: {- value: selectedTab === "payouts" ? payouts : fees,+ value: rest[selectedTab],},})) ?? null;@@ -94,6 +102,7 @@ export default function PayoutsPageClient() {payouts:timeseriesData?.reduce((acc, { payouts }) => acc + payouts, 0) ?? 0,fees: timeseriesData?.reduce((acc, { fees }) => acc + fees, 0) ?? 0,+ total: timeseriesData?.reduce((acc, { total }) => acc + total, 0) ?? 0,};}, [timeseriesData]);@@ -183,7 +192,7 @@ export default function PayoutsPageClient() {<div className="mx-auto flex w-full max-w-screen-xl flex-col space-y-6 p-6"><SimpleDateRangePicker defaultInterval="mtd" className="w-fit" /><div className="flex flex-col divide-y divide-neutral-200 rounded-lg border border-neutral-200 bg-white">- <div className="scrollbar-hide grid w-full grid-cols-2 divide-x overflow-y-hidden">+ <div className="scrollbar-hide grid w-full grid-cols-3 divide-x overflow-y-hidden">{tabs.map(({ id, label, colorClassName }) => {return (<button@@ -223,7 +232,7 @@ export default function PayoutsPageClient() {format={{style: "currency",currency: "USD",- // @ts-ignore – trailingZeroDisplay is a valid option but TS is outdated+ // @ts-ignore – trailingZeroDisplay is a valid option but TS is outdatedtrailingZeroDisplay: "stripIfInteger",}}/>@@ -261,7 +270,7 @@ export default function PayoutsPageClient() {<div className="flex items-center gap-2"><divclassName={cn(- "h-2 w-2 rounded-sm opacity-50 shadow-[inset_0_0_0_1px_#0003]",+ "h-2 w-2 rounded-sm shadow-[inset_0_0_0_1px_#0003]",tab.colorClassName,)}/>diff --git a/apps/web/app/api/admin/payouts/route.ts b/apps/web/app/api/admin/payouts/route.tsindex a86309d885..4416bb5962 100644--- a/apps/web/app/api/admin/payouts/route.ts+++ b/apps/web/app/api/admin/payouts/route.ts@@ -9,6 +9,7 @@ import { NextResponse } from "next/server";interface TimeseriesPoint {payouts: number;fees: number;+ total: number;}interface FormattedTimeseriesPoint extends TimeseriesPoint {@@ -55,12 +56,13 @@ export const GET = withAdmin(async ({ searchParams }) => {// Calculate timeseries data for payouts and feesconst timeseriesData = await prisma.$queryRaw<- { date: Date; payouts: number; fees: number }[]+ { date: Date; payouts: number; fees: number; total: number }[]>`SELECTDATE_FORMAT(CONVERT_TZ(paidAt, "UTC", ${timezone}), ${dateFormat}) as date,SUM(amount) as payouts,- SUM(fee) as fees+ SUM(fee) as fees,+ SUM(total) as totalFROM InvoiceWHEREworkspaceId != ${ACME_WORKSPACE_ID}@@ -89,6 +91,7 @@ export const GET = withAdmin(async ({ searchParams }) => {{payouts: Number(item.payouts),fees: Number(item.fees),+ total: Number(item.total),},]),);@@ -108,6 +111,7 @@ export const GET = withAdmin(async ({ searchParams }) => {...(timeseriesLookup[periodKey] || {payouts: 0,fees: 0,+ total: 0,}),});