The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add cell filter buttons
Tim Wilson64d9b0d029dd
diff --git a/apps/web/app/api/embed/commissions/route.ts b/apps/web/app/api/embed/commissions/route.tsindex 1a304e2111..9580430f56 100644--- a/apps/web/app/api/embed/commissions/route.ts+++ b/apps/web/app/api/embed/commissions/route.ts@@ -28,12 +28,14 @@ export const GET = withEmbedToken(updatedAt: true,customer: {select: {+ id: true,email: true,avatar: true,},},link: {select: {+ id: true,shortLink: true,url: true,},diff --git a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.tsindex 7cc8641c26..1f56b71307 100644--- a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts+++ b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts@@ -62,6 +62,7 @@ export const GET = withPartnerProfile(customer: true,link: {select: {+ id: true,shortLink: true,url: true,},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.tsxindex 58e0e7aa3a..1218b2e19f 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@@ -2,6 +2,7 @@import useProgramEnrollment from "@/lib/swr/use-program-enrollment";import { CustomerProps, LinkProps, 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";@@ -30,10 +31,17 @@ import {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?: (+ args: Pick<Cell<PartnerEarningsResponse, any>, "getValue">,+ ) => Record<string, any>;+};+export function EarningsTablePartner({limit,withChart,@@ -86,12 +94,22 @@ export function EarningsTablePartner({id: "type",header: "Type",accessorKey: "type",+ meta: {+ filterParams: ({ getValue }) => ({+ type: getValue(),+ }),+ },cell: ({ row }) => <CommissionTypeBadge type={row.original.type} />,},{id: "link",header: "Link",accessorKey: "link",+ meta: {+ filterParams: ({ getValue }) => ({+ linkId: getValue().id,+ }),+ },cell: ({ row }) => (<div className="flex items-center gap-3"><LinkLogo@@ -114,6 +132,11 @@ export function EarningsTablePartner({id: "customer",header: "Customer",accessorKey: "customer",+ meta: {+ filterParams: ({ getValue }) => ({+ customerId: getValue().id,+ }),+ },cell: ({ row }) =>row.original.customer ? row.original.customer.email : "-",},@@ -152,6 +175,12 @@ export function EarningsTablePartner({},},],+ cellRight: (cell) => {+ const meta = cell.column.columnDef.meta as ColumnMeta | undefined;+ return (+ meta?.filterParams && <FilterButton set={meta.filterParams(cell)} />+ );+ },...(!limit && {pagination,onPaginationChange: setPagination,@@ -258,8 +287,12 @@ function EarningsTableControls() {);const activeFilters = useMemo(() => {- const { type } = searchParamsObj;- return [...(type ? [{ key: "type", value: type }] : [])];+ 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) =>@@ -277,7 +310,7 @@ function EarningsTableControls() {const onRemoveAll = () =>queryParams({- del: ["type"],+ del: ["type", "linkId", "customerId"],});return (diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 73555eb1eb..41d3756fd9 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -181,6 +181,7 @@ export const PartnerEarningsSchema = SaleResponseSchema.omit({type: z.string(),customer: z.object({+ id: z.string(),email: z.string().transform((email) => email.replace(/(?<=^.).+(?=.@)/, "********")),@@ -188,6 +189,7 @@ export const PartnerEarningsSchema = SaleResponseSchema.omit({}).nullable(),link: LinkSchema.pick({+ id: true,shortLink: true,url: true,}),