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.

Update customer-selector.tsx

Steven Tey45e3bb75b5f6
diff --git a/apps/web/ui/customers/customer-selector.tsx b/apps/web/ui/customers/customer-selector.tsx
index 838c9f6c31..51fabbd75d 100644
--- a/apps/web/ui/customers/customer-selector.tsx
+++ b/apps/web/ui/customers/customer-selector.tsx
@@ -26,6 +26,12 @@ export function CustomerSelector({
query: useAsync ? { search: debouncedSearch } : undefined,
});
+ const { customers: selectedCustomers } = useCustomers({
+ query: selectedCustomerId
+ ? { customerIds: [selectedCustomerId] }
+ : undefined,
+ });
+
useEffect(() => {
if (customers && !useAsync && customers.length >= CUSTOMERS_MAX_PAGE_SIZE) {
setUseAsync(true);
@@ -53,8 +59,25 @@ export function CustomerSelector({
}, [customers]);
const selectedOption = useMemo(() => {
- return customerOptions?.find((o) => o.value === selectedCustomerId) || null;
- }, [customerOptions, selectedCustomerId]);
+ if (!selectedCustomerId) return null;
+
+ const customer = [...(customers || []), ...(selectedCustomers || [])].find(
+ (c) => c.id === selectedCustomerId,
+ );
+
+ if (!customer) return null;
+
+ return {
+ value: customer.id,
+ label: customer.name || customer.email || customer.externalId,
+ icon: (
+ <img
+ src={customer.avatar || `${OG_AVATAR_URL}${customer.id}`}
+ className="size-4 rounded-full"
+ />
+ ),
+ };
+ }, [customers, selectedCustomers, selectedCustomerId]);
return (
<>