add customer_id prop to RhfVehicleSelectField and update vehicle query
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
parent
615a0fda59
commit
0c43c8edd2
@ -208,6 +208,7 @@ export function JobCardForm({ resourceId, initialData, onSuccess }: JobCardFormP
|
|||||||
|
|
||||||
const hasInsurance = form.watch("has_insurance")
|
const hasInsurance = form.watch("has_insurance")
|
||||||
const status = form.watch("status")
|
const status = form.watch("status")
|
||||||
|
const customer = form.watch("customer")
|
||||||
const isCheckIn = status === "check_in"
|
const isCheckIn = status === "check_in"
|
||||||
|
|
||||||
const { mutate, error, isPending } = useFormMutation(form, {
|
const { mutate, error, isPending } = useFormMutation(form, {
|
||||||
@ -250,7 +251,7 @@ export function JobCardForm({ resourceId, initialData, onSuccess }: JobCardFormP
|
|||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
<RhfCustomerSelectField name="customer" />
|
<RhfCustomerSelectField name="customer" />
|
||||||
<RhfVehicleSelectField name="vehicle" />
|
<RhfVehicleSelectField name="vehicle" customer_id={customer?.value} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<RhfCheckboxField name="has_insurance" label="Has Insurance Work?" />
|
<RhfCheckboxField name="has_insurance" label="Has Insurance Work?" />
|
||||||
|
|||||||
@ -72,6 +72,7 @@ export type RhfVehicleSelectFieldProps<
|
|||||||
required?: boolean
|
required?: boolean
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
|
customer_id?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Component ──
|
// ── Component ──
|
||||||
@ -86,6 +87,7 @@ export function RhfVehicleSelectField<
|
|||||||
required,
|
required,
|
||||||
disabled,
|
disabled,
|
||||||
placeholder = "Search by make, model, year, or plate...",
|
placeholder = "Search by make, model, year, or plate...",
|
||||||
|
customer_id,
|
||||||
}: RhfVehicleSelectFieldProps<TValues, TName>) {
|
}: RhfVehicleSelectFieldProps<TValues, TName>) {
|
||||||
const api = useAuthApi()
|
const api = useAuthApi()
|
||||||
const anchorRef = useRef<HTMLDivElement>(null)
|
const anchorRef = useRef<HTMLDivElement>(null)
|
||||||
@ -100,9 +102,9 @@ export function RhfVehicleSelectField<
|
|||||||
} = useController({ name, control, disabled })
|
} = useController({ name, control, disabled })
|
||||||
|
|
||||||
const { data: options = [], isLoading } = useQuery<VehicleOption[]>({
|
const { data: options = [], isLoading } = useQuery<VehicleOption[]>({
|
||||||
queryKey: [VEHICLE_ROUTES.INDEX, "vehicle-select"],
|
queryKey: [VEHICLE_ROUTES.INDEX, "vehicle-select", customer_id],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const res = await api.vehicles.list()
|
const res = await api.vehicles.list({ customer_id: customer_id || undefined })
|
||||||
return extractItems(res).map(buildVehicleOption)
|
return extractItems(res).map(buildVehicleOption)
|
||||||
},
|
},
|
||||||
staleTime: 5 * 60 * 1000,
|
staleTime: 5 * 60 * 1000,
|
||||||
@ -129,7 +131,7 @@ export function RhfVehicleSelectField<
|
|||||||
|
|
||||||
const combobox = (
|
const combobox = (
|
||||||
<div ref={anchorRef}>
|
<div ref={anchorRef}>
|
||||||
<Combobox
|
<Combobox
|
||||||
value={field.value}
|
value={field.value}
|
||||||
onValueChange={(val: VehicleOption | VehicleOption[] | null) => {
|
onValueChange={(val: VehicleOption | VehicleOption[] | null) => {
|
||||||
const single = Array.isArray(val) ? val[0] ?? null : val
|
const single = Array.isArray(val) ? val[0] ?? null : val
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user