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.

Rename customers components, update for partners side (#3382)

Steven Tey8cbe7f8d534d
diff --git a/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts b/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
index d3aa8e6445..4613101642 100644
--- a/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
+++ b/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
@@ -31,11 +31,6 @@ export const GET = withWorkspace(
_count: true,
});
- const totalPrograms = programEnrollments.reduce(
- (acc, enrollment) => acc + enrollment._count,
- 0,
- );
-
// approved and archived statuses
const trustedPrograms = programEnrollments
.filter((enrollment) =>
@@ -50,7 +45,7 @@ export const GET = withWorkspace(
return NextResponse.json(
partnerCrossProgramSummarySchema.parse({
- totalPrograms,
+ totalPrograms: trustedPrograms + bannedPrograms,
trustedPrograms,
bannedPrograms,
}),
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
index d144d0f0f6..97c1cf92ed 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/(index)/page-client.tsx
@@ -9,6 +9,7 @@ import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import { SearchBoxPersisted } from "@/ui/shared/search-box";
import {
AnimatedSizeContainer,
+ EditColumnsButton,
Filter,
LinkLogo,
Table,
@@ -27,11 +28,12 @@ import {
getPrettyUrl,
} from "@dub/utils";
import Link from "next/link";
-import { useParams } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import { useMemo } from "react";
import { usePartnerCustomerFilters } from "./use-partner-customer-filters";
export function ProgramCustomersPageClient() {
+ const router = useRouter();
const { searchParams, queryParams } = useRouterStuff();
const { programSlug } = useParams<{ programSlug: string }>();
@@ -59,8 +61,24 @@ export function ProgramCustomersPageClient() {
} = usePartnerCustomerFilters();
const customersColumns = {
- all: ["customer", "country", "link", "saleAmount", "createdAt"],
- defaultVisible: ["customer", "country", "link", "saleAmount", "createdAt"],
+ all: [
+ "customer",
+ "country",
+ "link",
+ "saleAmount",
+ "createdAt",
+ "firstSaleAt",
+ "subscriptionCanceledAt",
+ ],
+ defaultVisible: [
+ "customer",
+ "country",
+ "link",
+ "saleAmount",
+ "createdAt",
+ "firstSaleAt",
+ "subscriptionCanceledAt",
+ ],
};
const { columnVisibility, setColumnVisibility } = useColumnVisibility(
@@ -69,109 +87,185 @@ export function ProgramCustomersPageClient() {
);
const columns = useMemo(
- () => [
- {
- id: "customer",
- header: "Customer",
- enableHiding: false,
- minSize: 250,
- cell: ({ row }) => {
- return (
- <CustomerRowItem
- customer={row.original}
- href={`/programs/${programSlug}/customers/${row.original.id}`}
- chartActivityIconMode="visible"
- />
- );
+ () =>
+ [
+ {
+ id: "customer",
+ header: "Customer",
+ enableHiding: false,
+ minSize: 250,
+ cell: ({ row }) => {
+ return (
+ <CustomerRowItem
+ customer={row.original}
+ chartActivityIconMode="visible"
+ />
+ );
+ },
},
- },
- {
- id: "country",
- header: "Country",
- accessorKey: "country",
- minSize: 150,
- cell: ({ row }) => {
- const country = row.original.country;
- return (
- <div className="flex items-center gap-2">
- {country && (
- <img
- alt={`${country} flag`}
- src={`https://hatscripts.github.io/circle-flags/flags/${country.toLowerCase()}.svg`}
- className="size-4 shrink-0"
+ {
+ id: "country",
+ header: "Country",
+ accessorKey: "country",
+ minSize: 150,
+ cell: ({ row }) => {
+ const country = row.original.country;
+ return (
+ <div className="flex items-center gap-2">
+ {country && (
+ <img
+ alt={`${country} flag`}
+ src={`https://hatscripts.github.io/circle-flags/flags/${country.toLowerCase()}.svg`}
+ className="size-4 shrink-0"
+ />
+ )}
+ <span className="min-w-0 truncate">
+ {(country ? COUNTRIES[country] : null) ?? "-"}
+ </span>
+ </div>
+ );
+ },
+ },
+ {
+ id: "link",
+ header: "Link",
+ accessorKey: "activity.link",
+ cell: ({ row }) =>
+ row.original.activity.link ? (
+ <Link
+ href={`/programs/${programSlug}/links?domain=${row.original.activity.link.domain}&key=${row.original.activity.link.key}`}
+ className="flex cursor-alias items-center gap-3 decoration-dotted underline-offset-2 hover:underline"
+ >
+ <LinkLogo
+ apexDomain={getApexDomain(
+ row.original.activity.link.shortLink,
+ )}
+ className="size-4 shrink-0 sm:size-4"
/>
- )}
- <span className="min-w-0 truncate">
- {(country ? COUNTRIES[country] : null) ?? "-"}
+ <span
+ className="truncate"
+ title={row.original.activity.link.shortLink}
+ >
+ {getPrettyUrl(row.original.activity.link.shortLink)}
+ </span>
+ </Link>
+ ) : (
+ "-"
+ ),
+ size: 250,
+ },
+ {
+ id: "saleAmount",
+ header: "Lifetime value",
+ accessorKey: "activity.ltv",
+ cell: ({ getValue }) => (
+ <div className="flex items-center gap-2">
+ <span>
+ {currencyFormatter(getValue() ?? 0, {
+ trailingZeroDisplay: "stripIfInteger",
+ })}
</span>
+ <span className="text-neutral-400">USD</span>
</div>
- );
+ ),
},
- },
- {
- id: "link",
- header: "Link",
- accessorKey: "activity.link",
- cell: ({ row }) =>
- row.original.activity.link ? (
- <Link
- href={`/programs/${programSlug}/links?domain=${row.original.activity.link.domain}&key=${row.original.activity.link.key}`}
- className="flex cursor-alias items-center gap-3 decoration-dotted underline-offset-2 hover:underline"
+ {
+ id: "createdAt",
+ header: "Created",
+ cell: ({ row }) => (
+ <TimestampTooltip
+ timestamp={row.original.createdAt}
+ rows={["local"]}
+ side="left"
+ delayDuration={150}
>
- <LinkLogo
- apexDomain={getApexDomain(row.original.activity.link.shortLink)}
- className="size-4 shrink-0 sm:size-4"
- />
- <span
- className="truncate"
- title={row.original.activity.link.shortLink}
- >
- {getPrettyUrl(row.original.activity.link.shortLink)}
+ <span>
+ {formatDate(row.original.createdAt, { month: "short" })}
</span>
- </Link>
- ) : (
- "-"
+ </TimestampTooltip>
),
- size: 250,
- },
- {
- id: "saleAmount",
- header: "Lifetime value",
- accessorKey: "activity.ltv",
- cell: ({ getValue }) => (
- <div className="flex items-center gap-2">
- <span>
- {currencyFormatter(getValue() ?? 0, {
- trailingZeroDisplay: "stripIfInteger",
- })}
- </span>
- <span className="text-neutral-400">USD</span>
- </div>
- ),
- },
- {
- id: "createdAt",
- header: "Created",
- cell: ({ row }) => (
- <TimestampTooltip
- timestamp={row.original.createdAt}
- rows={["local"]}
- side="left"
- delayDuration={150}
- >
- <span>
- {formatDate(row.original.createdAt, { month: "short" })}
- </span>
- </TimestampTooltip>
- ),
- },
- ],
+ },
+ {
+ id: "firstSaleAt",
+ header: "Paid",
+ meta: {
+ headerTooltip: "The date the customer made their first sale.",
+ },
+ cell: ({ row }) =>
+ row.original.firstSaleAt ? (
+ <TimestampTooltip
+ timestamp={row.original.firstSaleAt}
+ rows={["local"]}
+ side="left"
+ delayDuration={150}
+ >
+ <span>
+ {formatDate(row.original.firstSaleAt, { month: "short" })}
+ </span>
+ </TimestampTooltip>
+ ) : (
+ "-"
+ ),
+ },
+ {
+ id: "subscriptionCanceledAt",
+ header: "Canceled",
+ meta: {
+ headerTooltip: "The date the customer canceled their subscription.",
+ },
+ cell: ({ row }) =>
+ row.original.subscriptionCanceledAt ? (
+ <TimestampTooltip
+ timestamp={row.original.subscriptionCanceledAt}
+ rows={["local"]}
+ side="left"
+ delayDuration={150}
+ >
+ <span>
+ {formatDate(row.original.subscriptionCanceledAt, {
+ month: "short",
+ })}
+ </span>
+ </TimestampTooltip>
+ ) : (
+ "-"
+ ),
+ },
+ // Menu
+ {
+ id: "menu",
+ enableHiding: false,
+ minSize: 43,
+ size: 43,
+ maxSize: 43,
+ header: () => <EditColumnsButton table={table} />,
+ },
+ ].filter((c) => c.id === "menu" || customersColumns.all.includes(c.id)),
[programSlug],
);
const { table, ...tableProps } = useTable({
data: customers || [],
columns,
+ columnPinning: { right: ["menu"] },
+ onRowClick: (row, e) => {
+ const url = `/programs/${programSlug}/customers/${row.original.id}`;
+
+ if (e.metaKey || e.ctrlKey) window.open(url, "_blank");
+ else router.push(url);
+ },
+ onRowAuxClick: (row) =>
+ window.open(
+ `/programs/${programSlug}/customers/${row.original.id}`,
+ "_blank",
+ ),
+ rowProps: (row) => ({
+ onPointerEnter: () => {
+ router.prefetch(
+ `/programs/${programSlug}/customers/${row.original.id}`,
+ );
+ },
+ }),
pagination,
onPaginationChange: setPagination,
columnVisibility,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/page-client.tsx
index 644b5f9051..06feee6ea1 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/page-client.tsx
@@ -1,5 +1,5 @@
-import { CustomerTable } from "@/ui/customers/customer-table/customer-table";
+import { CustomersTable } from "@/ui/customers/customers-table/customers-table";
export function CustomersPageClient() {
- return <CustomerTable />;
+ return <CustomersTable />;
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-stats.tsx
similarity index 95%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-stats.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-stats.tsx
index 98530ac500..03a9a9323b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-stats.tsx
@@ -1,16 +1,14 @@
"use client";
import useCommissionsCount from "@/lib/swr/use-commissions-count";
-import useProgram from "@/lib/swr/use-program";
import useWorkspace from "@/lib/swr/use-workspace";
import { CommissionStatusBadges } from "@/ui/partners/commission-status-badges";
import { ProgramStatsFilter } from "@/ui/partners/program-stats-filter";
import { useRouterStuff } from "@dub/ui";
import { Users } from "@dub/ui/icons";
-export function CommissionStats() {
+export function CommissionsStats() {
const { slug } = useWorkspace();
- const { program } = useProgram();
const { queryParams } = useRouterStuff();
const { commissionsCount, error } = useCommissionsCount({
exclude: ["status", "page"],
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx
similarity index 99%
rename from apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx
rename to apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx
index 0cfcd039b5..489887e32b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commission-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/commissions-table.tsx
@@ -64,7 +64,7 @@ const commissionsColumns = {
],
};
-export function CommissionTable() {
+export function CommissionsTable() {
const {
filters,
activeFilters,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/page.tsx
index b7a410684d..37727d02d1 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/page.tsx
@@ -3,8 +3,8 @@
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { CommissionPopoverButtons } from "./commission-popover-buttons";
-import { CommissionStats } from "./commission-stats";
-import { CommissionTable } from "./commission-table";
+import { CommissionsStats } from "./commissions-stats";
+import { CommissionsTable } from "./commissions-table";
import { CreateCommissionButton } from "./create-commission-button";
export default function ProgramCommissions() {
@@ -24,9 +24,9 @@ export default function ProgramCommissions() {
}
>
<PageWidthWrapper>
- <CommissionStats />
+ <CommissionsStats />
<div className="mt-6">
- <CommissionTable />
+ <CommissionsTable />
</div>
</PageWidthWrapper>
</PageContent>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/page.tsx
index 190aa6717b..7d17da135d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/customers/(index)/page.tsx
@@ -1,12 +1,12 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import { CustomerTable } from "@/ui/customers/customer-table/customer-table";
+import { CustomersTable } from "@/ui/customers/customers-table/customers-table";
export default function ProgramCustomersPage() {
const { defaultProgramId } = useWorkspace();
return (
- <CustomerTable
+ <CustomersTable
query={{ programId: defaultProgramId || undefined }}
isProgramPage
/>
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index 4643e85d13..97cf125e15 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -100,6 +100,8 @@ export const PartnerProfileCustomerSchema = CustomerEnrichedSchema.pick({
email: true,
country: true,
createdAt: true,
+ firstSaleAt: true,
+ subscriptionCanceledAt: true,
}).extend({
activity: customerActivityResponseSchema,
});
diff --git a/apps/web/ui/customers/customer-table/customer-table.tsx b/apps/web/ui/customers/customers-table/customers-table.tsx
similarity index 99%
rename from apps/web/ui/customers/customer-table/customer-table.tsx
rename to apps/web/ui/customers/customers-table/customers-table.tsx
index 426f767f54..9c71cd53d8 100644
--- a/apps/web/ui/customers/customer-table/customer-table.tsx
+++ b/apps/web/ui/customers/customers-table/customers-table.tsx
@@ -56,7 +56,7 @@ type ColumnMeta = {
) => Record<string, any>;
};
-export function CustomerTable({
+export function CustomersTable({
query,
isProgramPage = false,
}: {
diff --git a/apps/web/ui/customers/customer-table/example-data.ts b/apps/web/ui/customers/customers-table/example-data.ts
similarity index 86%
rename from apps/web/ui/customers/customer-table/example-data.ts
rename to apps/web/ui/customers/customers-table/example-data.ts
index 30d104e70f..7bdbce3c41 100644
--- a/apps/web/ui/customers/customer-table/example-data.ts
+++ b/apps/web/ui/customers/customers-table/example-data.ts
@@ -11,6 +11,8 @@ export const EXAMPLE_CUSTOMER_DATA = [
sales: 1,
saleAmount: 20_00,
createdAt: new Date(new Date().getTime() - 14 * millisecondsPerDay),
+ firstSaleAt: null,
+ subscriptionCanceledAt: null,
link: null,
discount: null,
},
@@ -24,6 +26,8 @@ export const EXAMPLE_CUSTOMER_DATA = [
sales: 30,
saleAmount: 1200_00,
createdAt: new Date(new Date().getTime() - 20 * millisecondsPerDay),
+ firstSaleAt: null,
+ subscriptionCanceledAt: null,
link: null,
discount: null,
},
@@ -37,6 +41,8 @@ export const EXAMPLE_CUSTOMER_DATA = [
sales: 3,
saleAmount: 90_00,
createdAt: new Date(new Date().getTime() - 30 * millisecondsPerDay),
+ firstSaleAt: null,
+ subscriptionCanceledAt: null,
link: null,
discount: null,
},
diff --git a/apps/web/ui/customers/customer-table/use-customer-filters.tsx b/apps/web/ui/customers/customers-table/use-customer-filters.tsx
similarity index 100%
rename from apps/web/ui/customers/customer-table/use-customer-filters.tsx
rename to apps/web/ui/customers/customers-table/use-customer-filters.tsx