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.

Start adding customer/link filter

Tim Wilson045de8ef7db4
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 e5efeef052..6c8f7670f0 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,7 +1,8 @@
"use client";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import { PartnerEarningsResponse } from "@/lib/types";
+import { CustomerProps, LinkProps, PartnerEarningsResponse } from "@/lib/types";
+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";
@@ -17,7 +18,7 @@ import {
useRouterStuff,
useTable,
} from "@dub/ui";
-import { CircleDollar, Sliders } from "@dub/ui/icons";
+import { CircleDollar, Hyperlink, Sliders, User } from "@dub/ui/icons";
import {
capitalize,
cn,
@@ -27,6 +28,7 @@ import {
formatDateTime,
getApexDomain,
getPrettyUrl,
+ linkConstructor,
} from "@dub/utils";
import { useMemo } from "react";
import useSWR from "swr";
@@ -201,6 +203,10 @@ export function EarningsTablePartner({ limit }: { limit?: number }) {
function EarningsTableControls() {
const { queryParams, searchParamsObj } = useRouterStuff();
+ // TODO: Fetch links and customers
+ const links = [] as LinkProps[];
+ const customers = [] as CustomerProps[];
+
const filters = useMemo(
() => [
{
@@ -211,9 +217,34 @@ function EarningsTableControls() {
value: slug,
label: capitalize(slug) as string,
icon: <CommissionTypeIcon type={slug} />,
- // right: nFormatter(count, { full: true }),
})),
},
+ {
+ 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,
+ },
],
[],
);
@@ -279,6 +310,7 @@ function EarningsTableControls() {
align="start"
/>
</div>
+
<div
className={cn(
"transition-[height] duration-[300ms]",
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index fa615ab019..03c3a519ac 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -163,6 +163,16 @@ export const getPartnerSalesQuerySchema = getSalesQuerySchema
sortBy: z.enum(["createdAt", "amount", "earnings"]).default("createdAt"),
});
+export const PARTNER_CUSTOMERS_MAX_PAGE_SIZE = 100;
+
+export const getPartnerCustomersQuerySchema = z
+ .object({
+ search: z.string().optional(),
+ })
+ .merge(
+ getPaginationQuerySchema({ pageSize: PARTNER_CUSTOMERS_MAX_PAGE_SIZE }),
+ );
+
export const PartnerEarningsSchema = SaleResponseSchema.omit({
partner: true,
customer: true,
@@ -190,6 +200,7 @@ export const getPartnerSalesCountQuerySchema = getSalesCountQuerySchema
})
.extend({
type: z.enum(["click", "lead", "sale"]).optional(),
+ groupBy: z.enum(["customer"]).optional(),
});
export const createPartnerSchema = z.object({
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 5cd1f0eea9..081f4bdd94 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -59,7 +59,6 @@ import {
COUNTRIES,
DUB_DEMO_LINKS,
DUB_LOGO,
- fetcher,
getApexDomain,
getNextPlan,
GOOGLE_FAVICON_URL,
@@ -76,9 +75,9 @@ import {
useMemo,
useState,
} from "react";
-import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { FolderIcon } from "../folders/folder-icon";
+import { LinkIcon } from "../links/link-icon";
import TagBadge from "../links/tag-badge";
import AnalyticsOptions from "./analytics-options";
import { AnalyticsContext } from "./analytics-provider";
@@ -998,31 +997,3 @@ function UpgradeTooltip({
/>
);
}
-
-function LinkIcon({
- url: urlProp,
- domain,
- linkKey,
-}: {
- url?: string;
- domain?: string;
- linkKey?: string;
-}) {
- const { id: workspaceId } = useWorkspace();
- const { data } = useSWR<{ url: string }>(
- !urlProp && workspaceId && domain && linkKey
- ? `/api/links/info?${new URLSearchParams({ workspaceId, domain, key: linkKey }).toString()}`
- : null,
- fetcher,
- );
-
- const url = urlProp || data?.url;
- return url ? (
- <LinkLogo
- apexDomain={getApexDomain(url)}
- className="h-4 w-4 sm:h-4 sm:w-4"
- />
- ) : (
- <Hyperlink className="h-4 w-4" />
- );
-}
diff --git a/apps/web/ui/links/link-icon.tsx b/apps/web/ui/links/link-icon.tsx
new file mode 100644
index 0000000000..fee55c5526
--- /dev/null
+++ b/apps/web/ui/links/link-icon.tsx
@@ -0,0 +1,32 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Hyperlink, LinkLogo } from "@dub/ui";
+import { fetcher, getApexDomain } from "@dub/utils";
+import useSWR from "swr";
+
+export function LinkIcon({
+ url: urlProp,
+ domain,
+ linkKey,
+}: {
+ url?: string;
+ domain?: string;
+ linkKey?: string;
+}) {
+ const { id: workspaceId } = useWorkspace();
+ const { data } = useSWR<{ url: string }>(
+ !urlProp && workspaceId && domain && linkKey
+ ? `/api/links/info?${new URLSearchParams({ workspaceId, domain, key: linkKey }).toString()}`
+ : null,
+ fetcher,
+ );
+
+ const url = urlProp || data?.url;
+ return url ? (
+ <LinkLogo
+ apexDomain={getApexDomain(url)}
+ className="h-4 w-4 sm:h-4 sm:w-4"
+ />
+ ) : (
+ <Hyperlink className="h-4 w-4" />
+ );
+}