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