updates
This commit is contained in:
@@ -70,6 +70,8 @@ export type RhfCustomerSelectFieldProps<
|
||||
required?: boolean
|
||||
disabled?: boolean
|
||||
placeholder?: string
|
||||
/** Filter customers by customer_type.name (case-insensitive). */
|
||||
customerType?: string
|
||||
}
|
||||
|
||||
// ── Component ──
|
||||
@@ -84,6 +86,7 @@ export function RhfCustomerSelectField<
|
||||
required,
|
||||
disabled,
|
||||
placeholder = "Search by name, company, or phone...",
|
||||
customerType,
|
||||
}: RhfCustomerSelectFieldProps<TValues, TName>) {
|
||||
const api = useAuthApi()
|
||||
const anchorRef = useRef<HTMLDivElement>(null)
|
||||
@@ -96,10 +99,16 @@ export function RhfCustomerSelectField<
|
||||
} = useController({ name, control, disabled })
|
||||
|
||||
const { data: options = [], isLoading } = useQuery<CustomerOption[]>({
|
||||
queryKey: [CUSTOMER_ROUTES.INDEX, "customer-select"],
|
||||
queryKey: [CUSTOMER_ROUTES.INDEX, "customer-select", customerType ?? "all"],
|
||||
queryFn: async () => {
|
||||
const res = await api.customers.list()
|
||||
return extractItems(res).map(buildCustomerOption)
|
||||
const items = extractItems(res)
|
||||
const filtered = customerType
|
||||
? items.filter((item: any) =>
|
||||
item.customer_type?.name?.toLowerCase() === customerType.toLowerCase(),
|
||||
)
|
||||
: items
|
||||
return filtered.map(buildCustomerOption)
|
||||
},
|
||||
staleTime: 5 * 60 * 1000,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user