fix validation issues
This commit is contained in:
parent
c5d406792f
commit
cdd1cbc31a
@ -37,7 +37,7 @@ export default function VehiclesPage() {
|
||||
onExport={(filters) => api.vehicles.exportData(filters)}
|
||||
fileName='vehicles'
|
||||
/>
|
||||
<FormDialog title="Vehicle">
|
||||
<FormDialog title="Vehicle" classNames={{dialogContent:'lg:min-w-4xl'}}>
|
||||
{(resourceId) => (
|
||||
<VehicleForm
|
||||
resourceId={resourceId}
|
||||
|
||||
@ -26,8 +26,7 @@ import { toRelation, toId } from "@/shared/lib/utils"
|
||||
import { formatUppercase } from "@/shared/utils/formatters"
|
||||
|
||||
import { vehicleFormSchema, type VehicleFormValues } from "./vehicle.schema"
|
||||
import { VEHICLE_ROUTES } from "@garage/api"
|
||||
|
||||
|
||||
// ── Props ──
|
||||
|
||||
export type VehicleFormProps = {
|
||||
@ -39,11 +38,11 @@ export type VehicleFormProps = {
|
||||
// ── Default values ──
|
||||
|
||||
const DEFAULT_VALUES: VehicleFormValues = {
|
||||
shop_type: null,
|
||||
vehicle_body_type: null,
|
||||
vehicle_fuel_type: null,
|
||||
vehicle_transmission: null,
|
||||
vehicle_color: null,
|
||||
shop_type_id: null,
|
||||
vehicle_body_type_id: null,
|
||||
vehicle_fuel_type_id: null,
|
||||
vehicle_transmission_id: null,
|
||||
vehicle_color_id: null,
|
||||
make: "",
|
||||
model: "",
|
||||
year: "",
|
||||
@ -70,11 +69,11 @@ function mapToFormValues(data: unknown): VehicleFormValues {
|
||||
const d = (data as any)?.data ?? data ?? {}
|
||||
|
||||
return {
|
||||
shop_type: toRelation(d.shop_type_id, d.shop_type?.title),
|
||||
vehicle_body_type: toRelation(d.vehicle_body_type_id, d.vehicle_body_type?.title),
|
||||
vehicle_fuel_type: toRelation(d.vehicle_fuel_type_id, d.vehicle_fuel_type?.title),
|
||||
vehicle_transmission: toRelation(d.vehicle_transmission_id, d.vehicle_transmission?.title),
|
||||
vehicle_color: toRelation(d.vehicle_color_id, d.vehicle_color?.title),
|
||||
shop_type_id: toRelation(d.shop_type_id, d.shop_type?.title),
|
||||
vehicle_body_type_id: toRelation(d.vehicle_body_type_id, d.vehicle_body_type?.title),
|
||||
vehicle_fuel_type_id: toRelation(d.vehicle_fuel_type_id, d.vehicle_fuel_type?.title),
|
||||
vehicle_transmission_id: toRelation(d.vehicle_transmission_id, d.vehicle_transmission?.title),
|
||||
vehicle_color_id: toRelation(d.vehicle_color_id, d.vehicle_color?.title),
|
||||
make: d.make || "",
|
||||
model: d.model || "",
|
||||
year: d.year || "",
|
||||
@ -91,11 +90,11 @@ function mapToFormValues(data: unknown): VehicleFormValues {
|
||||
|
||||
function mapToPayload(values: VehicleFormValues) {
|
||||
return {
|
||||
shop_type_id: toId(values.shop_type),
|
||||
vehicle_body_type_id: toId(values.vehicle_body_type),
|
||||
vehicle_fuel_type_id: toId(values.vehicle_fuel_type),
|
||||
vehicle_transmission_id: toId(values.vehicle_transmission),
|
||||
vehicle_color_id: toId(values.vehicle_color),
|
||||
shop_type_id: toId(values.shop_type_id),
|
||||
vehicle_body_type_id: toId(values.vehicle_body_type_id),
|
||||
vehicle_fuel_type_id: toId(values.vehicle_fuel_type_id),
|
||||
vehicle_transmission_id: toId(values.vehicle_transmission_id),
|
||||
vehicle_color_id: toId(values.vehicle_color_id),
|
||||
make: values.make,
|
||||
model: values.model,
|
||||
year: values.year,
|
||||
@ -161,7 +160,7 @@ export function VehicleForm({ resourceId, initialData, onSuccess }: VehicleFormP
|
||||
{/* Associations */}
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<RhfAsyncSelectField
|
||||
name="shop_type"
|
||||
name="shop_type_id"
|
||||
label="Shop Type"
|
||||
placeholder="Select shop type"
|
||||
queryKey={["shop-types"]}
|
||||
@ -172,7 +171,7 @@ export function VehicleForm({ resourceId, initialData, onSuccess }: VehicleFormP
|
||||
{...STORE_OBJECT}
|
||||
/>
|
||||
<RhfAsyncSelectField
|
||||
name="vehicle_body_type"
|
||||
name="vehicle_body_type_id"
|
||||
label="Body Type"
|
||||
placeholder="Select body type"
|
||||
queryKey={["vehicle-body-types"]}
|
||||
@ -186,7 +185,7 @@ export function VehicleForm({ resourceId, initialData, onSuccess }: VehicleFormP
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<RhfAsyncSelectField
|
||||
name="vehicle_fuel_type"
|
||||
name="vehicle_fuel_type_id"
|
||||
label="Fuel Type"
|
||||
placeholder="Select fuel type"
|
||||
queryKey={["vehicle-fuel-types"]}
|
||||
@ -197,7 +196,7 @@ export function VehicleForm({ resourceId, initialData, onSuccess }: VehicleFormP
|
||||
{...STORE_OBJECT}
|
||||
/>
|
||||
<RhfAsyncSelectField
|
||||
name="vehicle_transmission"
|
||||
name="vehicle_transmission_id"
|
||||
label="Transmission"
|
||||
placeholder="Select transmission"
|
||||
queryKey={["vehicle-transmissions"]}
|
||||
@ -211,7 +210,7 @@ export function VehicleForm({ resourceId, initialData, onSuccess }: VehicleFormP
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<RhfAsyncSelectField
|
||||
name="vehicle_color"
|
||||
name="vehicle_color_id"
|
||||
label="Color"
|
||||
placeholder="Select color"
|
||||
queryKey={["vehicle-colors"]}
|
||||
|
||||
@ -6,11 +6,11 @@ export const relationFieldSchema = z
|
||||
|
||||
export const vehicleFormSchema = z.object({
|
||||
// ── Relations ──
|
||||
shop_type: relationFieldSchema,
|
||||
vehicle_body_type: relationFieldSchema,
|
||||
vehicle_fuel_type: relationFieldSchema,
|
||||
vehicle_transmission: relationFieldSchema,
|
||||
vehicle_color: relationFieldSchema,
|
||||
shop_type_id: relationFieldSchema,
|
||||
vehicle_body_type_id: relationFieldSchema,
|
||||
vehicle_fuel_type_id: relationFieldSchema,
|
||||
vehicle_transmission_id: relationFieldSchema,
|
||||
vehicle_color_id: relationFieldSchema,
|
||||
|
||||
// ── Vehicle identity ──
|
||||
make: z.string().optional(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user