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.

FilterButtonTableRow

Steven Teyc2a96ef9c8d0
diff --git a/apps/web/app/api/customers/count/route.ts b/apps/web/app/api/customers/count/route.ts
index 3002733ccb..7ee97e6c9d 100644
--- a/apps/web/app/api/customers/count/route.ts
+++ b/apps/web/app/api/customers/count/route.ts
@@ -6,7 +6,7 @@ import { NextResponse } from "next/server";
// GET /api/customers/count
export const GET = withWorkspace(async ({ workspace, searchParams }) => {
- const { email, externalId, search, country, groupBy } =
+ const { email, externalId, search, country, linkId, groupBy } =
getCustomersCountQuerySchema.parse(searchParams);
const commonWhere: Prisma.CustomerWhereInput = {
@@ -26,6 +26,9 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
...(country && {
country,
}),
+ ...(linkId && {
+ linkId,
+ }),
}),
};
diff --git a/apps/web/app/api/customers/route.ts b/apps/web/app/api/customers/route.ts
index 9676471393..9cb9269c75 100644
--- a/apps/web/app/api/customers/route.ts
+++ b/apps/web/app/api/customers/route.ts
@@ -47,6 +47,7 @@ export const GET = withWorkspace(
externalId,
search,
country,
+ linkId,
includeExpandedFields,
page,
pageSize,
@@ -79,6 +80,9 @@ export const GET = withWorkspace(
country,
}),
}),
+ ...(linkId && {
+ linkId,
+ }),
},
orderBy: {
[sortBy]: sortOrder,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
index 1fd9a7caa3..e96ef54266 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/commissions/commission-table.tsx
@@ -3,13 +3,13 @@
import useCommissionsCount from "@/lib/swr/use-commissions-count";
import useWorkspace from "@/lib/swr/use-workspace";
import { CommissionResponse } from "@/lib/types";
-import FilterButton from "@/ui/analytics/events/filter-button";
import { CustomerRowItem } from "@/ui/customers/customer-row-item";
import { CommissionRowMenu } from "@/ui/partners/commission-row-menu";
import { CommissionStatusBadges } from "@/ui/partners/commission-status-badges";
import { CommissionTypeBadge } from "@/ui/partners/commission-type-badge";
import { PartnerRowItem } from "@/ui/partners/partner-row-item";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { FilterButtonTableRow } from "@/ui/shared/filter-button-table-row";
import SimpleDateRangePicker from "@/ui/shared/simple-date-range-picker";
import {
AnimatedSizeContainer,
@@ -188,7 +188,9 @@ const CommissionTableInner = memo(
return (
!limit &&
- meta?.filterParams && <FilterButton set={meta.filterParams(cell)} />
+ meta?.filterParams && (
+ <FilterButtonTableRow set={meta.filterParams(cell)} />
+ )
);
},
...(!limit && {
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx
index 6f1f773f19..8455fbc2f6 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/earnings/earnings-table.tsx
@@ -3,11 +3,11 @@
import usePartnerEarningsCount from "@/lib/swr/use-partner-earnings-count";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
import { PartnerEarningsResponse } from "@/lib/types";
-import FilterButton from "@/ui/analytics/events/filter-button";
import { CustomerRowItem } from "@/ui/customers/customer-row-item";
import { CommissionStatusBadges } from "@/ui/partners/commission-status-badges";
import { CommissionTypeBadge } from "@/ui/partners/commission-type-badge";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { FilterButtonTableRow } from "@/ui/shared/filter-button-table-row";
import {
CopyText,
LinkLogo,
@@ -191,7 +191,9 @@ export function EarningsTablePartner({ limit }: { limit?: number }) {
cellRight: (cell) => {
const meta = cell.column.columnDef.meta as ColumnMeta | undefined;
return (
- meta?.filterParams && <FilterButton set={meta.filterParams(cell)} />
+ meta?.filterParams && (
+ <FilterButtonTableRow set={meta.filterParams(cell)} />
+ )
);
},
...(!limit && {
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 4e40cab7b3..fc0bd938a3 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -32,6 +32,12 @@ export const getCustomersQuerySchema = z
.describe(
"A filter on the list based on the customer's `country` field.",
),
+ linkId: z
+ .string()
+ .optional()
+ .describe(
+ "A filter on the list based on the customer's `linkId` field (the referral link ID).",
+ ),
includeExpandedFields: booleanQuerySchema
.optional()
.describe(
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index a6ffb7a172..5ace96cff3 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -5,6 +5,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { ClickEvent, LeadEvent, SaleEvent } from "@/lib/types";
import { CustomerRowItem } from "@/ui/customers/customer-row-item";
import EmptyState from "@/ui/shared/empty-state";
+import { FilterButtonTableRow } from "@/ui/shared/filter-button-table-row";
import {
CopyText,
LinkLogo,
@@ -38,7 +39,6 @@ import DeviceIcon from "../device-icon";
import EditColumnsButton from "./edit-columns-button";
import { EventsContext } from "./events-provider";
import { EXAMPLE_EVENTS_DATA } from "./example-data";
-import FilterButton from "./filter-button";
import { RowMenuButton } from "./row-menu-button";
import { eventColumns, useColumnVisibility } from "./use-column-visibility";
@@ -553,7 +553,12 @@ export default function EventsTable({
cellRight: (cell) => {
const meta = cell.column.columnDef.meta as ColumnMeta | undefined;
return (
- meta?.filterParams && <FilterButton set={meta.filterParams(cell)} />
+ meta?.filterParams && (
+ <FilterButtonTableRow
+ set={meta.filterParams(cell)}
+ className="bg-[linear-gradient(to_right,transparent,white_10%)]"
+ />
+ )
);
},
tdClassName: (columnId) => (columnId === "customer" ? "p-0" : ""),
diff --git a/apps/web/ui/customers/customer-table/customer-table.tsx b/apps/web/ui/customers/customer-table/customer-table.tsx
index 3d96668abe..d22f72c820 100644
--- a/apps/web/ui/customers/customer-table/customer-table.tsx
+++ b/apps/web/ui/customers/customer-table/customer-table.tsx
@@ -7,6 +7,7 @@ import { CustomerProps } from "@/lib/types";
import EditColumnsButton from "@/ui/analytics/events/edit-columns-button";
import { CustomerRowItem } from "@/ui/customers/customer-row-item";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { FilterButtonTableRow } from "@/ui/shared/filter-button-table-row";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
import {
AnimatedSizeContainer,
@@ -33,7 +34,7 @@ import {
getPrettyUrl,
isClickOnInteractiveChild,
} from "@dub/utils";
-import { Row } from "@tanstack/react-table";
+import { Cell, Row } from "@tanstack/react-table";
import { Command } from "cmdk";
import Image from "next/image";
import Link from "next/link";
@@ -45,6 +46,12 @@ import { EXAMPLE_CUSTOMER_DATA } from "./example-data";
import { customersColumns, useColumnVisibility } from "./use-column-visibility";
import { useCustomerFilters } from "./use-customer-filters";
+type ColumnMeta = {
+ filterParams?: (
+ args: Pick<Cell<CustomerProps, any>, "getValue">,
+ ) => Record<string, any>;
+};
+
export function CustomerTable() {
const { id: workspaceId, slug: workspaceSlug, plan } = useWorkspace();
@@ -108,6 +115,12 @@ export function CustomerTable() {
{
id: "country",
header: "Country",
+ accessorKey: "country",
+ meta: {
+ filterParams: ({ getValue }) => ({
+ country: getValue(),
+ }),
+ },
minSize: 150,
cell: ({ row }) => {
const country = row.original.country;
@@ -247,6 +260,14 @@ export function CustomerTable() {
scroll: false,
}),
columnPinning: { right: ["menu"] },
+ cellRight: (cell) => {
+ const meta = cell.column.columnDef.meta as ColumnMeta | undefined;
+ return (
+ meta?.filterParams && (
+ <FilterButtonTableRow set={meta.filterParams(cell)} />
+ )
+ );
+ },
thClassName: "border-l-0",
tdClassName:
"border-l-0 group-hover/row:bg-bg-muted transition-colors duration-75",
diff --git a/apps/web/ui/customers/customer-table/use-customer-filters.tsx b/apps/web/ui/customers/customer-table/use-customer-filters.tsx
index ddc331b946..48b2666d0d 100644
--- a/apps/web/ui/customers/customer-table/use-customer-filters.tsx
+++ b/apps/web/ui/customers/customer-table/use-customer-filters.tsx
@@ -62,11 +62,16 @@ export function useCustomerFilters(
right: nFormatter(_count, { full: true }),
permalink: `/${slug}/analytics?event=leads&country=${country}`,
})) ?? [],
+ meta: {
+ filterParams: ({ getValue }) => ({
+ country: getValue(),
+ }),
+ },
},
{
key: "linkId",
icon: Hyperlink,
- label: "Link",
+ label: "Referral link",
options:
linksCount?.map(({ linkId, shortLink, _count }) => ({
value: linkId,
@@ -74,6 +79,11 @@ export function useCustomerFilters(
right: nFormatter(_count, { full: true }),
permalink: `/${slug}/links/${getPrettyUrl(shortLink)}`,
})) ?? [],
+ meta: {
+ filterParams: ({ getValue }) => ({
+ linkId: getValue(),
+ }),
+ },
},
],
[countriesCount, linksCount],
diff --git a/apps/web/ui/analytics/events/filter-button.tsx b/apps/web/ui/shared/filter-button-table-row.tsx
similarity index 62%
rename from apps/web/ui/analytics/events/filter-button.tsx
rename to apps/web/ui/shared/filter-button-table-row.tsx
index f98af5f5f9..90173f66c5 100644
--- a/apps/web/ui/analytics/events/filter-button.tsx
+++ b/apps/web/ui/shared/filter-button-table-row.tsx
@@ -1,12 +1,24 @@
import { useRouterStuff } from "@dub/ui";
import { FilterBars } from "@dub/ui/icons";
+import { cn } from "@dub/utils";
import Link from "next/link";
-export default function FilterButton({ set }: { set: Record<string, any> }) {
+export function FilterButtonTableRow({
+ set,
+ className,
+}: {
+ set: Record<string, any>;
+ className?: string;
+}) {
const { queryParams } = useRouterStuff();
return (
- <div className="absolute right-1 top-0 flex h-full shrink-0 translate-x-3 items-center justify-center bg-[linear-gradient(to_right,transparent,white_10%)] p-2 opacity-0 transition-all group-hover:translate-x-0 group-hover:opacity-100">
+ <div
+ className={cn(
+ "absolute right-1 top-0 flex h-full shrink-0 translate-x-3 items-center justify-center p-2 opacity-0 transition-all group-hover:translate-x-0 group-hover:opacity-100",
+ className,
+ )}
+ >
<Link
href={
queryParams({