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.

add CustomerFilterItem and hideInFilterDropdown

Steven Teyb8ff1514b93f
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
index c7c01aed0b..32879c5ec5 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
@@ -14,7 +14,7 @@ import { CustomerDetailsColumn } from "@/ui/customers/customer-details-column";
import { CustomerPartnerEarningsTable } from "@/ui/customers/customer-partner-earnings-table";
import { CustomerSalesTable } from "@/ui/customers/customer-sales-table";
import { BackLink } from "@/ui/shared/back-link";
-import { ArrowUpRight, CopyButton } from "@dub/ui";
+import { ArrowUpRight, Button, CopyButton } from "@dub/ui";
import { OG_AVATAR_URL, fetcher } from "@dub/utils";
import Link from "next/link";
import { notFound, useParams } from "next/navigation";
@@ -135,9 +135,20 @@ export function CustomerPageClient() {
)}
<section className="flex flex-col">
- <h2 className="py-3 text-lg font-semibold text-neutral-900">
- Activity
- </h2>
+ <div className="flex items-center justify-between">
+ <h2 className="py-3 text-lg font-semibold text-neutral-900">
+ Activity
+ </h2>
+ <Link
+ href={`/${slug}/events?interval=all&customerId=${customerId}`}
+ >
+ <Button
+ variant="secondary"
+ text="View all"
+ className="h-7 px-2"
+ />
+ </Link>
+ </div>
<CustomerActivityList
activity={customerActivity}
isLoading={!customer || isCustomerActivityLoading}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index a4a3298efd..1db66d8869 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -1,18 +1,17 @@
"use client";
import { CUSTOMER_PAGE_EVENTS_LIMIT } from "@/lib/partners/constants";
+import usePartnerCustomer from "@/lib/swr/use-partner-customer";
import useProgramEnrollment from "@/lib/swr/use-program-enrollment";
-import {
- PartnerEarningsResponse,
- PartnerProfileCustomerProps,
-} from "@/lib/types";
+import { PartnerEarningsResponse } from "@/lib/types";
import { CustomerActivityList } from "@/ui/customers/customer-activity-list";
import { CustomerDetailsColumn } from "@/ui/customers/customer-details-column";
import { CustomerSalesTable } from "@/ui/customers/customer-sales-table";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { BackLink } from "@/ui/shared/back-link";
-import { MoneyBill2, Tooltip } from "@dub/ui";
+import { Button, MoneyBill2, Tooltip } from "@dub/ui";
import { fetcher, OG_AVATAR_URL } from "@dub/utils";
+import Link from "next/link";
import { notFound, useParams } from "next/navigation";
import { memo } from "react";
import useSWR from "swr";
@@ -24,10 +23,9 @@ export function ProgramCustomerPageClient() {
customerId: string;
}>();
- const { data: customer, isLoading } = useSWR<PartnerProfileCustomerProps>(
- `/api/partner-profile/programs/${programSlug}/customers/${customerId}`,
- fetcher,
- );
+ const { data: customer, isLoading } = usePartnerCustomer({
+ customerId,
+ });
if (!customer && !isLoading) notFound();
@@ -86,9 +84,20 @@ export function ProgramCustomerPageClient() {
</section>
<section className="flex flex-col">
- <h2 className="py-3 text-lg font-semibold text-neutral-900">
- Activity
- </h2>
+ <div className="flex items-center justify-between">
+ <h2 className="py-3 text-lg font-semibold text-neutral-900">
+ Activity
+ </h2>
+ <Link
+ href={`/programs/${programSlug}/events?interval=all&customerId=${customerId}`}
+ >
+ <Button
+ variant="secondary"
+ text="View all"
+ className="h-7 px-2"
+ />
+ </Link>
+ </div>
<CustomerActivityList
activity={customer?.activity}
isLoading={!customer}
diff --git a/apps/web/lib/swr/use-customer.ts b/apps/web/lib/swr/use-customer.ts
index 3b9ce736cc..d32fa883c3 100644
--- a/apps/web/lib/swr/use-customer.ts
+++ b/apps/web/lib/swr/use-customer.ts
@@ -21,7 +21,7 @@ export default function useCustomer<
const { id: workspaceId } = useWorkspace();
const { data, error, isLoading } = useSWR<T>(
- customerId && workspaceId
+ workspaceId && customerId
? `/api/customers/${customerId}?${new URLSearchParams({
workspaceId: workspaceId,
...query,
diff --git a/apps/web/lib/swr/use-partner-customer.ts b/apps/web/lib/swr/use-partner-customer.ts
new file mode 100644
index 0000000000..d9b3a7ca29
--- /dev/null
+++ b/apps/web/lib/swr/use-partner-customer.ts
@@ -0,0 +1,23 @@
+import { fetcher } from "@dub/utils";
+import { useParams } from "next/navigation";
+import useSWR from "swr";
+import { PartnerProfileCustomerProps } from "../types";
+
+export default function usePartnerCustomer({
+ customerId,
+}: {
+ customerId: string;
+}) {
+ const { programSlug } = useParams<{ programSlug: string }>();
+
+ const { data, isLoading } = useSWR<PartnerProfileCustomerProps>(
+ programSlug &&
+ `/api/partner-profile/programs/${programSlug}/customers/${customerId}`,
+ fetcher,
+ );
+
+ return {
+ data,
+ isLoading,
+ };
+}
diff --git a/apps/web/lib/zod/schemas/partner-profile.ts b/apps/web/lib/zod/schemas/partner-profile.ts
index 567cd9818a..a2ca124805 100644
--- a/apps/web/lib/zod/schemas/partner-profile.ts
+++ b/apps/web/lib/zod/schemas/partner-profile.ts
@@ -101,7 +101,6 @@ export const partnerProfileAnalyticsQuerySchema = analyticsQuerySchema.omit({
tenantId: true,
programId: true,
partnerId: true,
- customerId: true,
tagId: true,
tagIds: true,
folderId: true,
@@ -113,7 +112,6 @@ export const partnerProfileEventsQuerySchema = eventsQuerySchema.omit({
tenantId: true,
programId: true,
partnerId: true,
- customerId: true,
tagId: true,
tagIds: true,
folderId: true,
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index afc28f5361..3e4224cb0e 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -15,6 +15,7 @@ import useDomainsCount from "@/lib/swr/use-domains-count";
import useFolder from "@/lib/swr/use-folder";
import useFolders from "@/lib/swr/use-folders";
import useFoldersCount from "@/lib/swr/use-folders-count";
+import usePartnerCustomer from "@/lib/swr/use-partner-customer";
import useTags from "@/lib/swr/use-tags";
import useTagsCount from "@/lib/swr/use-tags-count";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -188,10 +189,16 @@ export default function Toggle({
});
const selectedCustomerId = searchParamsObj.customerId;
- const { data: selectedCustomer } = useCustomer({
+
+ const { data: selectedCustomerWorkspace } = useCustomer({
+ customerId: selectedCustomerId,
+ });
+ const { data: selectedCustomerPartner } = usePartnerCustomer({
customerId: selectedCustomerId,
});
+ const selectedCustomer = selectedCustomerPartner || selectedCustomerWorkspace;
+
const [requestedFilters, setRequestedFilters] = useState<string[]>([]);
const activeFilters = useMemo(() => {
@@ -218,14 +225,14 @@ export default function Toggle({
// Handle folderId special case
...(folderId ? [{ key: "folderId", value: folderId }] : []),
// Handle customerId special case
- ...(selectedCustomerId && selectedCustomer
+ ...(selectedCustomer
? [
{
key: "customerId",
value:
selectedCustomer.email ||
- selectedCustomer.name ||
- selectedCustomer.externalId,
+ selectedCustomer["name"] ||
+ selectedCustomer["externalId"],
},
]
: []),
@@ -250,7 +257,13 @@ export default function Toggle({
});
return filters;
- }, [searchParamsObj, selectedTagIds, selectedCustomerId, selectedCustomer]);
+ }, [
+ searchParamsObj,
+ selectedTagIds,
+ partnerPage,
+ selectedCustomerId,
+ selectedCustomer,
+ ]);
const isRequested = useCallback(
(key: string) =>
@@ -372,6 +385,41 @@ export default function Toggle({
) ?? null,
};
+ const CustomerFilterItem = {
+ key: "customerId",
+ icon: User,
+ label: "Customer",
+ hideInFilterDropdown: partnerPage,
+ shouldFilter: !customersAsync,
+ getOptionIcon: () => {
+ return selectedCustomer ? (
+ <img
+ src={
+ selectedCustomer["avatar"] ||
+ `${OG_AVATAR_URL}${selectedCustomer.id}`
+ }
+ alt={`${selectedCustomer.email} avatar`}
+ className="size-4 rounded-full"
+ />
+ ) : null;
+ },
+ options: customers?.map(({ id, email, name, avatar }) => {
+ return {
+ value: id,
+ label: email ?? name,
+ icon: (
+ <img
+ src={avatar || `${OG_AVATAR_URL}${id}`}
+ alt={`${email} avatar`}
+ className="size-4 rounded-full"
+ />
+ ),
+ };
+ }) ?? [
+ { value: selectedCustomerId, label: selectedCustomerId, icon: User },
+ ],
+ };
+
const filters: ComponentProps<typeof Filter.Select>["filters"] = useMemo(
() => [
{
@@ -389,8 +437,9 @@ export default function Toggle({
...(dashboardProps
? []
: partnerPage
- ? [LinkFilterItem]
+ ? [LinkFilterItem, CustomerFilterItem]
: [
+ CustomerFilterItem,
...(flags?.linkFolders
? [
{
@@ -500,40 +549,6 @@ export default function Toggle({
]),
],
},
-
- {
- key: "customerId",
- icon: User,
- label: "Customer",
- shouldFilter: !customersAsync,
- getOptionIcon: (value) => {
- return selectedCustomer ? (
- <img
- src={
- selectedCustomer.avatar ||
- `${OG_AVATAR_URL}${selectedCustomer.id}`
- }
- alt={`${selectedCustomer.email} avatar`}
- className="size-4 rounded-full"
- />
- ) : null;
- },
- options:
- customers?.map(({ id, email, name, avatar }) => {
- return {
- value: id,
- label: email ?? name,
- icon: (
- <img
- src={avatar || `${OG_AVATAR_URL}${id}`}
- alt={`${email} avatar`}
- className="size-4 rounded-full"
- />
- ),
- };
- }) ?? null,
- },
-
LinkFilterItem,
{
key: "root",
diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsx
index 5a6c0ac127..9a971613d2 100644
--- a/packages/ui/src/filter/filter-select.tsx
+++ b/packages/ui/src/filter/filter-select.tsx
@@ -219,17 +219,19 @@ export function FilterSelect({
>
{!selectedFilter
? // Top-level filters
- filters.map((filter) => (
- <Fragment key={filter.key}>
- <FilterButton
- filter={filter}
- onSelect={() => openFilter(filter.key)}
- />
- {filter.separatorAfter && (
- <Command.Separator className="-mx-1 my-1 border-b border-neutral-200" />
- )}
- </Fragment>
- ))
+ filters
+ .filter((filter) => !filter.hideInFilterDropdown)
+ .map((filter) => (
+ <Fragment key={filter.key}>
+ <FilterButton
+ filter={filter}
+ onSelect={() => openFilter(filter.key)}
+ />
+ {filter.separatorAfter && (
+ <Command.Separator className="-mx-1 my-1 border-b border-neutral-200" />
+ )}
+ </Fragment>
+ ))
: // Filter options
selectedFilter.options
?.filter((option) => !search || !option.hideDuringSearch)
diff --git a/packages/ui/src/filter/types.ts b/packages/ui/src/filter/types.ts
index ffc0f48d8d..309d9646df 100644
--- a/packages/ui/src/filter/types.ts
+++ b/packages/ui/src/filter/types.ts
@@ -10,9 +10,10 @@ export type Filter = {
key: string;
icon: FilterIcon;
label: string;
+ options: FilterOption[] | null;
+ hideInFilterDropdown?: boolean;
shouldFilter?: boolean;
separatorAfter?: boolean;
- options: FilterOption[] | null;
multiple?: boolean;
getOptionIcon?: (
value: FilterOption["value"],