This commit is contained in:
2026-04-07 06:32:40 +03:00
parent 24a44481a0
commit 11db1e6941
101 changed files with 54585 additions and 39160 deletions
@@ -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,
})