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.

revert PartnerCustomerSelector

Steven Teya76248d9c51b
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index cf69cece0b..b351687c27 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -7,7 +7,6 @@ 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 { PartnerCustomerSelector } from "@/ui/customers/partner-customer-selector";
import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
@@ -16,13 +15,7 @@ import { cn, fetcher, formatDate } from "@dub/utils";
import { addMonths, isBefore } from "date-fns";
import { AlertCircle } from "lucide-react";
import Link from "next/link";
-import {
- redirect,
- useParams,
- usePathname,
- useRouter,
- useSearchParams,
-} from "next/navigation";
+import { redirect, useParams } from "next/navigation";
import { memo, useMemo } from "react";
import useSWR from "swr";
@@ -32,9 +25,6 @@ export function ProgramCustomerPageClient() {
programSlug: string;
customerId: string;
}>();
- const router = useRouter();
- const pathname = usePathname();
- const searchParams = useSearchParams();
const { data: customer, isLoading } = usePartnerCustomer({
customerId,
@@ -59,12 +49,6 @@ export function ProgramCustomerPageClient() {
redirect(`/programs/${programSlug}`);
}
- const switchToCustomer = (newCustomerId: string) => {
- if (customerId === newCustomerId) return;
- const url = `${pathname.replace(`/customers/${customerId}`, `/customers/${newCustomerId}`)}?${searchParams.toString()}`;
- router.push(url);
- };
-
return (
<PageContent
title={
@@ -81,11 +65,13 @@ export function ProgramCustomerPageClient() {
<User className="size-4" />
</Link>
<ChevronRight className="text-content-muted size-2.5 shrink-0 [&_*]:stroke-2" />
- <PartnerCustomerSelector
- variant="header"
- selectedCustomerId={customer?.id ?? null}
- setSelectedCustomerId={switchToCustomer}
- />
+ <div>
+ {customer ? (
+ customer.name || customer.email
+ ) : (
+ <div className="h-6 w-32 animate-pulse rounded-md bg-neutral-200" />
+ )}
+ </div>
</div>
}
>
diff --git a/apps/web/ui/customers/partner-customer-selector.tsx b/apps/web/ui/customers/partner-customer-selector.tsx
deleted file mode 100644
index 8895c86844..0000000000
--- a/apps/web/ui/customers/partner-customer-selector.tsx
+++ /dev/null
@@ -1,133 +0,0 @@
-"use client";
-
-import usePartnerCustomer from "@/lib/swr/use-partner-customer";
-import { PartnerProfileCustomerProps } from "@/lib/types";
-import { Combobox, ComboboxProps } from "@dub/ui";
-import { fetcher, OG_AVATAR_URL } from "@dub/utils";
-import { useParams } from "next/navigation";
-import { useMemo, useState } from "react";
-import { useDebounce } from "use-debounce";
-import useSWR from "swr";
-
-type PartnerCustomer = PartnerProfileCustomerProps & { name?: string | null };
-
-type PartnerCustomerSelectorProps = {
- selectedCustomerId: string | null;
- setSelectedCustomerId: (customerId: string) => void;
- disabled?: boolean;
- variant?: "default" | "header";
-} & Partial<ComboboxProps<false, any>>;
-
-export function PartnerCustomerSelector({
- selectedCustomerId,
- setSelectedCustomerId,
- disabled,
- variant = "header",
- ...rest
-}: PartnerCustomerSelectorProps) {
- const { programSlug } = useParams<{ programSlug: string }>();
- const [search, setSearch] = useState("");
- const [debouncedSearch] = useDebounce(search, 500);
- const [openPopover, setOpenPopover] = useState(false);
-
- const { data: customers, isLoading: loading } = useSWR<PartnerCustomer[]>(
- programSlug
- ? `/api/partner-profile/programs/${programSlug}/customers?pageSize=100${debouncedSearch ? `&search=${encodeURIComponent(debouncedSearch)}` : ""}`
- : null,
- fetcher,
- { keepPreviousData: true },
- );
-
- const { data: selectedCustomer, isLoading: selectedCustomerLoading } =
- usePartnerCustomer({
- customerId: selectedCustomerId ?? "",
- });
-
- const customerOptions = useMemo(() => {
- return customers?.map((customer) => ({
- value: customer.id,
- label: customer.name || customer.email ?? "",
- icon: (
- <img
- src={`${OG_AVATAR_URL}${customer.id}`}
- alt=""
- className="size-4 rounded-full"
- />
- ),
- }));
- }, [customers]);
-
- const selectedOption = useMemo(() => {
- if (!selectedCustomerId || !selectedCustomer) return null;
- return {
- value: selectedCustomer.id,
- label: selectedCustomer.name || selectedCustomer.email ?? "",
- icon: (
- <img
- src={`${OG_AVATAR_URL}${selectedCustomer.id}`}
- alt=""
- className="size-4 rounded-full"
- />
- ),
- };
- }, [selectedCustomerId, selectedCustomer]);
-
- return (
- <Combobox
- options={loading ? undefined : customerOptions}
- setSelected={(option) => {
- if (!option) return;
- setSelectedCustomerId(option.value);
- }}
- selected={selectedOption}
- icon={
- variant === "header" && !selectedOption?.icon ? (
- <div className="size-5 flex-none animate-pulse rounded-full bg-neutral-200" />
- ) : (
- selectedOption?.icon
- )
- }
- caret={true}
- placeholder={variant === "header" ? "" : "Select customer"}
- searchPlaceholder="Search customers..."
- onSearchChange={setSearch}
- shouldFilter={false}
- matchTriggerWidth
- open={openPopover}
- onOpenChange={setOpenPopover}
- {...(variant === "header"
- ? {
- popoverProps: {
- contentClassName: "min-w-[280px]",
- },
- labelProps: {
- className: "text-lg font-semibold leading-7 text-neutral-900",
- },
- iconProps: {
- className: "size-6",
- },
- buttonProps: {
- disabled,
- className:
- "w-full justify-start px-2 py-1 h-8 transition-none max-md:bg-bg-subtle hover:bg-bg-subtle md:hover:bg-subtle border-none rounded-lg",
- },
- }
- : {
- buttonProps: {
- disabled,
- className:
- "w-full justify-start border-neutral-300 px-3 rounded-lg",
- },
- })}
- {...rest}
- >
- {variant === "header" && !selectedOption?.label ? (
- <div className="h-6 w-[120px] animate-pulse rounded bg-neutral-100" />
- ) : selectedCustomerLoading && selectedCustomerId ? (
- <div className="h-6 w-[120px] animate-pulse rounded bg-neutral-100" />
- ) : (
- selectedOption?.label
- )}
- </Combobox>
- );
-}