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.

small tweaks

Steven Tey1aaa2b86bf3c
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-composite-chart.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-composite-chart.tsx
index dccd9b665f..734510893b 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-composite-chart.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-composite-chart.tsx
@@ -1,9 +1,22 @@
+"use client";
+
import { formatDateTooltip } from "@/lib/analytics/format-date-tooltip";
import { IntervalOptions } from "@/lib/analytics/types";
import { usePartnerEarningsTimeseries } from "@/lib/swr/use-partner-earnings-timeseries";
-import { LoadingSpinner, useRouterStuff } from "@dub/ui";
+import { CustomerProps, LinkProps } from "@/lib/types";
+import { LinkIcon } from "@/ui/links/link-icon";
+import { CommissionTypeIcon } from "@/ui/partners/comission-type-icon";
+import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
+import { Filter, LoadingSpinner, useRouterStuff } from "@dub/ui";
import { Areas, TimeSeriesChart, XAxis, YAxis } from "@dub/ui/charts";
-import { cn, currencyFormatter, getPrettyUrl } from "@dub/utils";
+import { Hyperlink, Sliders, User } from "@dub/ui/icons";
+import {
+ capitalize,
+ cn,
+ currencyFormatter,
+ getPrettyUrl,
+ linkConstructor,
+} from "@dub/utils";
import NumberFlow from "@number-flow/react";
import { Fragment, useMemo } from "react";
@@ -76,103 +89,237 @@ export function EarningsCompositeChart() {
);
return (
- <div className="rounded-lg border border-neutral-200 p-6">
- <div className="flex flex-col gap-1">
- <span className="text-sm text-neutral-500">Total Earnings</span>
- <div className="mt-1">
- {total !== undefined ? (
- <NumberFlow
- className="text-lg font-medium leading-none text-neutral-800"
- value={total / 100}
- format={{
- style: "currency",
- currency: "USD",
- // @ts-ignore – trailingZeroDisplay is a valid option but TS is outdated
- trailingZeroDisplay: "stripIfInteger",
+ <div className="flex flex-col gap-6">
+ <EarningsTableControls />
+ <div className="rounded-lg border border-neutral-200 p-6">
+ <div className="flex flex-col gap-1">
+ <span className="text-sm text-neutral-500">Total Earnings</span>
+ <div className="mt-1">
+ {total !== undefined ? (
+ <NumberFlow
+ className="text-lg font-medium leading-none text-neutral-800"
+ value={total / 100}
+ format={{
+ style: "currency",
+ currency: "USD",
+ // @ts-ignore – trailingZeroDisplay is a valid option but TS is outdated
+ trailingZeroDisplay: "stripIfInteger",
+ }}
+ />
+ ) : (
+ <div className="h-[27px] w-24 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
+ </div>
+ <div className="mt-5 h-80">
+ {chartData ? (
+ <TimeSeriesChart
+ data={chartData}
+ series={series}
+ tooltipClassName="p-0"
+ tooltipContent={(d) => {
+ return (
+ <>
+ <div className="flex justify-between border-b border-neutral-200 p-3 text-xs">
+ <p className="font-medium leading-none text-neutral-900">
+ {formatDateTooltip(d.date, {
+ interval,
+ start,
+ end,
+ })}
+ </p>
+ <p className="text-right leading-none text-neutral-500">
+ {currencyFormatter((d.values.total || 0) / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </p>
+ </div>
+ <div className="grid max-w-64 grid-cols-[minmax(0,1fr),min-content] gap-x-6 gap-y-2 px-4 py-3 text-xs">
+ {series.map(({ id, colorClassName, valueAccessor }) => {
+ const link = data?.links?.find((l) => l.id === id);
+ return (
+ <Fragment key={id}>
+ <div className="flex items-center gap-2">
+ <div
+ className={cn(
+ colorClassName,
+ "size-2 shrink-0 rounded-sm bg-current opacity-50 shadow-[inset_0_0_0_1px_#0003]",
+ )}
+ />
+ <span className="min-w-0 truncate font-medium text-neutral-700">
+ {link?.shortLink
+ ? getPrettyUrl(link.shortLink)
+ : "Short link"}
+ </span>
+ </div>
+ <p className="text-right text-neutral-500">
+ {currencyFormatter(valueAccessor(d), {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </p>
+ </Fragment>
+ );
+ })}
+ </div>
+ </>
+ );
}}
- />
+ >
+ <Areas />
+ <XAxis
+ tickFormat={(d) =>
+ formatDateTooltip(d, {
+ interval,
+ start,
+ end,
+ })
+ }
+ />
+ <YAxis
+ showGridLines
+ tickFormat={(v) => `${currencyFormatter(v)}`}
+ />
+ </TimeSeriesChart>
) : (
- <div className="h-[27px] w-24 animate-pulse rounded-md bg-neutral-200" />
+ <div className="flex size-full items-center justify-center">
+ <LoadingSpinner />
+ </div>
)}
</div>
</div>
- <div className="mt-5 h-80">
- {chartData ? (
- <TimeSeriesChart
- data={chartData}
- series={series}
- tooltipClassName="p-0"
- tooltipContent={(d) => {
- return (
- <>
- <div className="flex justify-between border-b border-neutral-200 p-3 text-xs">
- <p className="font-medium leading-none text-neutral-900">
- {formatDateTooltip(d.date, {
- interval,
- start,
- end,
- })}
- </p>
- <p className="text-right leading-none text-neutral-500">
- {currencyFormatter((d.values.total || 0) / 100, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })}
- </p>
- </div>
- <div className="grid max-w-64 grid-cols-[minmax(0,1fr),min-content] gap-x-6 gap-y-2 px-4 py-3 text-xs">
- {series.map(({ id, colorClassName, valueAccessor }) => {
- const link = data?.links?.find((l) => l.id === id);
- return (
- <Fragment key={id}>
- <div className="flex items-center gap-2">
- <div
- className={cn(
- colorClassName,
- "size-2 shrink-0 rounded-sm bg-current opacity-50 shadow-[inset_0_0_0_1px_#0003]",
- )}
- />
- <span className="min-w-0 truncate font-medium text-neutral-700">
- {link?.shortLink
- ? getPrettyUrl(link.shortLink)
- : "Short link"}
- </span>
- </div>
- <p className="text-right text-neutral-500">
- {currencyFormatter(valueAccessor(d), {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })}
- </p>
- </Fragment>
- );
- })}
- </div>
- </>
- );
- }}
- >
- <Areas />
- <XAxis
- tickFormat={(d) =>
- formatDateTooltip(d, {
- interval,
- start,
- end,
- })
- }
- />
- <YAxis
- showGridLines
- tickFormat={(v) => `${currencyFormatter(v)}`}
- />
- </TimeSeriesChart>
- ) : (
- <div className="flex size-full items-center justify-center">
- <LoadingSpinner />
- </div>
- )}
+ </div>
+ );
+}
+
+function EarningsTableControls() {
+ const { queryParams, searchParamsObj } = useRouterStuff();
+
+ // TODO: Fetch links and customers
+ const links = [] as LinkProps[];
+ const customers = [] as CustomerProps[];
+
+ const filters = useMemo(
+ () => [
+ {
+ key: "type",
+ icon: Sliders,
+ label: "Type",
+ options: ["click", "lead", "sale"].map((slug) => ({
+ value: slug,
+ label: capitalize(slug) as string,
+ icon: <CommissionTypeIcon type={slug} />,
+ })),
+ },
+ {
+ key: "linkId",
+ icon: Hyperlink,
+ label: "Link",
+ getOptionIcon: (value, props) => {
+ const url = props.option?.data?.url;
+ const [domain, key] = value.split("/");
+
+ return <LinkIcon url={url} domain={domain} linkKey={key} />;
+ },
+ options:
+ links?.map(({ id, domain, key }) => ({
+ value: id,
+ label: linkConstructor({ domain, key, pretty: true }),
+ })) ?? null,
+ },
+ {
+ key: "customerId",
+ icon: User,
+ label: "Customer",
+ options:
+ customers?.map(({ id, name, email }) => ({
+ value: id,
+ label: name || email || "-",
+ })) ?? null,
+ },
+ ],
+ [],
+ );
+
+ const activeFilters = useMemo(() => {
+ const { type, linkId, customerId } = searchParamsObj;
+ return [
+ ...(type ? [{ key: "type", value: type }] : []),
+ ...(linkId ? [{ key: "linkId", value: linkId }] : []),
+ ...(customerId ? [{ key: "customerId", value: customerId }] : []),
+ ];
+ }, [searchParamsObj]);
+
+ const onSelect = (key: string, value: any) =>
+ queryParams({
+ set: {
+ [key]: value,
+ },
+ del: "page",
+ });
+
+ const onRemove = (key: string, value: any) =>
+ queryParams({
+ del: [key, "page"],
+ });
+
+ const onRemoveAll = () =>
+ queryParams({
+ del: ["type", "linkId", "customerId"],
+ });
+
+ return (
+ <div>
+ <div className="flex flex-col gap-3 md:flex-row">
+ {/* <Filter.Select
+ filters={filters}
+ activeFilters={activeFilters}
+ onSelect={onSelect}
+ onRemove={onRemove}
+ // onSearchChange={setSearch}
+ // onSelectedFilterChange={setSelectedFilter}
+ // emptyState={{
+ // domain: (
+ // <div className="flex flex-col items-center gap-2 p-2 text-center text-sm">
+ // <div className="flex items-center justify-center rounded-2xl border border-neutral-200 bg-neutral-50 p-3">
+ // <Globe className="size-6 text-neutral-700" />
+ // </div>
+ // <p className="mt-2 font-medium text-neutral-950">
+ // No domains found
+ // </p>
+ // <p className="mx-auto mt-1 w-full max-w-[180px] text-neutral-700">
+ // Add a custom domain to match your brand
+ // </p>
+ // <div>
+ // <Button
+ // className="mt-1 h-8"
+ // onClick={() => router.push(`/${slug}/settings/domains`)}
+ // text="Add domain"
+ // />
+ // </div>
+ // </div>
+ // ),
+ // }}
+ /> */}
+ <SimpleDateRangePicker
+ className="w-full sm:min-w-[200px] md:w-fit"
+ align="start"
+ />
</div>
+
+ <div
+ className={cn(
+ "transition-[height] duration-[300ms]",
+ activeFilters.length ? "h-3" : "h-0",
+ )}
+ />
+ <Filter.List
+ filters={filters}
+ activeFilters={activeFilters}
+ onRemove={onRemove}
+ onRemoveAll={onRemoveAll}
+ />
</div>
);
}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-table.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-table.tsx
index 589173f1ab..3a16cf5396 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-table.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/earnings-table.tsx
@@ -1,17 +1,12 @@
"use client";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import { CustomerProps, LinkProps, PartnerEarningsResponse } from "@/lib/types";
+import { PartnerEarningsResponse } from "@/lib/types";
import FilterButton from "@/ui/analytics/events/filter-button";
-import { LinkIcon } from "@/ui/links/link-icon";
-import { CommissionTypeIcon } from "@/ui/partners/comission-type-icon";
-import { CommissionTypeBadge } from "@/ui/partners/commission-type-badge";
import { SaleStatusBadges } from "@/ui/partners/sale-status-badges";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import {
CopyText,
- Filter,
LinkLogo,
StatusBadge,
Table,
@@ -19,22 +14,17 @@ import {
useRouterStuff,
useTable,
} from "@dub/ui";
-import { CircleDollar, Hyperlink, Sliders, User } from "@dub/ui/icons";
+import { CircleDollar } from "@dub/ui/icons";
import {
- capitalize,
- cn,
currencyFormatter,
fetcher,
formatDate,
formatDateTime,
getApexDomain,
getPrettyUrl,
- linkConstructor,
} from "@dub/utils";
import { Cell } from "@tanstack/react-table";
-import { useMemo } from "react";
import useSWR from "swr";
-import { EarningsCompositeChart } from "./earnings-composite-chart";
type ColumnMeta = {
filterParams?: (
@@ -42,13 +32,7 @@ type ColumnMeta = {
) => Record<string, any>;
};
-export function EarningsTablePartner({
- limit,
- withChart,
-}: {
- limit?: number;
- withChart?: boolean;
-}) {
+export function EarningsTablePartner({ limit }: { limit?: number }) {
const { programEnrollment } = useProgramEnrollment();
const { queryParams, searchParamsObj, getQueryString } = useRouterStuff();
@@ -69,14 +53,16 @@ export function EarningsTablePartner({
error,
} = useSWR<PartnerEarningsResponse[]>(
programEnrollment &&
- `/api/partner-profile/programs/${programEnrollment.programId}/earnings${getQueryString()}`,
+ `/api/partner-profile/programs/${programEnrollment.programId}/earnings${getQueryString(
+ limit ? { pageSize: limit } : {},
+ )}`,
fetcher,
);
const { pagination, setPagination } = usePagination(limit);
const { table, ...tableProps } = useTable({
- data: earnings?.slice(0, limit) || [],
+ data: earnings || [],
loading: isLoading,
error: error ? "Failed to fetch earnings." : undefined,
columns: [
@@ -90,17 +76,18 @@ export function EarningsTablePartner({
</p>
),
},
- {
- id: "type",
- header: "Type",
- accessorKey: "type",
- meta: {
- filterParams: ({ getValue }) => ({
- type: getValue(),
- }),
- },
- cell: ({ row }) => <CommissionTypeBadge type={row.original.type} />,
- },
+ // TODO: add this back once we have a way to hide/show column visibility
+ // {
+ // id: "type",
+ // header: "Type",
+ // accessorKey: "type",
+ // meta: {
+ // filterParams: ({ getValue }) => ({
+ // type: getValue(),
+ // }),
+ // },
+ // cell: ({ row }) => <CommissionTypeBadge type={row.original.type} />,
+ // },
{
id: "link",
header: "Link",
@@ -194,7 +181,9 @@ export function EarningsTablePartner({
...(sortOrder && { sortOrder }),
},
del: "page",
+ scroll: false,
}),
+ enableColumnResizing: true,
}),
rowCount: earningsCount?.count || 0,
emptyState: (
@@ -212,159 +201,22 @@ export function EarningsTablePartner({
resourceName: (plural) => `earning${plural ? "s" : ""}`,
});
- return (
- <div className="flex flex-col gap-6">
- {!limit && <EarningsTableControls />}
- {withChart && <EarningsCompositeChart />}
- {isLoading || earnings?.length ? (
- <Table
- {...tableProps}
- table={table}
- containerClassName="border-neutral-200"
- />
- ) : (
- <AnimatedEmptyState
- title="No earnings found"
- description="No earnings have been made for this program yet."
- cardContent={() => (
- <>
- <CircleDollar className="size-4 text-neutral-700" />
- <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
- </>
- )}
- />
+ return isLoading || earnings?.length ? (
+ <Table
+ {...tableProps}
+ table={table}
+ containerClassName="border-neutral-200"
+ />
+ ) : (
+ <AnimatedEmptyState
+ title="No earnings found"
+ description="No earnings have been made for this program yet."
+ cardContent={() => (
+ <>
+ <CircleDollar className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
)}
- </div>
- );
-}
-
-function EarningsTableControls() {
- const { queryParams, searchParamsObj } = useRouterStuff();
-
- // TODO: Fetch links and customers
- const links = [] as LinkProps[];
- const customers = [] as CustomerProps[];
-
- const filters = useMemo(
- () => [
- {
- key: "type",
- icon: Sliders,
- label: "Type",
- options: ["click", "lead", "sale"].map((slug) => ({
- value: slug,
- label: capitalize(slug) as string,
- icon: <CommissionTypeIcon type={slug} />,
- })),
- },
- {
- key: "linkId",
- icon: Hyperlink,
- label: "Link",
- getOptionIcon: (value, props) => {
- const url = props.option?.data?.url;
- const [domain, key] = value.split("/");
-
- return <LinkIcon url={url} domain={domain} linkKey={key} />;
- },
- options:
- links?.map(({ id, domain, key }) => ({
- value: id,
- label: linkConstructor({ domain, key, pretty: true }),
- })) ?? null,
- },
- {
- key: "customerId",
- icon: User,
- label: "Customer",
- options:
- customers?.map(({ id, name, email }) => ({
- value: id,
- label: name || email || "-",
- })) ?? null,
- },
- ],
- [],
- );
-
- const activeFilters = useMemo(() => {
- const { type, linkId, customerId } = searchParamsObj;
- return [
- ...(type ? [{ key: "type", value: type }] : []),
- ...(linkId ? [{ key: "linkId", value: linkId }] : []),
- ...(customerId ? [{ key: "customerId", value: customerId }] : []),
- ];
- }, [searchParamsObj]);
-
- const onSelect = (key: string, value: any) =>
- queryParams({
- set: {
- [key]: value,
- },
- del: "page",
- });
-
- const onRemove = (key: string, value: any) =>
- queryParams({
- del: [key, "page"],
- });
-
- const onRemoveAll = () =>
- queryParams({
- del: ["type", "linkId", "customerId"],
- });
-
- return (
- <div>
- <div className="flex flex-col gap-3 md:flex-row">
- {/* <Filter.Select
- filters={filters}
- activeFilters={activeFilters}
- onSelect={onSelect}
- onRemove={onRemove}
- // onSearchChange={setSearch}
- // onSelectedFilterChange={setSelectedFilter}
- // emptyState={{
- // domain: (
- // <div className="flex flex-col items-center gap-2 p-2 text-center text-sm">
- // <div className="flex items-center justify-center rounded-2xl border border-neutral-200 bg-neutral-50 p-3">
- // <Globe className="size-6 text-neutral-700" />
- // </div>
- // <p className="mt-2 font-medium text-neutral-950">
- // No domains found
- // </p>
- // <p className="mx-auto mt-1 w-full max-w-[180px] text-neutral-700">
- // Add a custom domain to match your brand
- // </p>
- // <div>
- // <Button
- // className="mt-1 h-8"
- // onClick={() => router.push(`/${slug}/settings/domains`)}
- // text="Add domain"
- // />
- // </div>
- // </div>
- // ),
- // }}
- /> */}
- <SimpleDateRangePicker
- className="w-full sm:min-w-[200px] md:w-fit"
- align="start"
- />
- </div>
-
- <div
- className={cn(
- "transition-[height] duration-[300ms]",
- activeFilters.length ? "h-3" : "h-0",
- )}
- />
- <Filter.List
- filters={filters}
- activeFilters={activeFilters}
- onRemove={onRemove}
- onRemoveAll={onRemoveAll}
- />
- </div>
+ />
);
}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/page.tsx
index 84403d2633..3e7e58909c 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/page.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/earnings/page.tsx
@@ -1,12 +1,14 @@
import { PageContent } from "@/ui/layout/page-content";
import { MaxWidthWrapper } from "@dub/ui";
+import { EarningsCompositeChart } from "./earnings-composite-chart";
import { EarningsTablePartner } from "./earnings-table";
export default function ProgramEarning() {
return (
<PageContent title="Earnings" hideReferButton>
- <MaxWidthWrapper>
- <EarningsTablePartner withChart />
+ <MaxWidthWrapper className="flex flex-col gap-6">
+ <EarningsCompositeChart />
+ <EarningsTablePartner />
</MaxWidthWrapper>
</PageContent>
);