fix: update default values in service form and enhance validation for required fields

This commit is contained in:
Mohammad Khyata 2026-05-08 16:02:51 +03:00
parent 4b51ffe457
commit 25c3125894
2 changed files with 11 additions and 6 deletions

View File

@ -43,10 +43,10 @@ export type ServiceFormProps = {
// ── Default values ── // ── Default values ──
const DEFAULT_VALUES: ServiceFormValues = { const DEFAULT_VALUES: ServiceFormValues = {
shop_type: null, shop_type: { value: "", label: "" },
category: null, category: { value: "", label: "" },
unit_type: null, unit_type: { value: "", label: "" },
department: null, department: { value: "", label: "" },
labor_name: "", labor_name: "",
service_code: "", service_code: "",
labor_matrix: "", labor_matrix: "",

View File

@ -5,9 +5,14 @@ export const relationFieldSchema = z
.object({ value: z.string(), label: z.string() }) .object({ value: z.string(), label: z.string() })
.nullable() .nullable()
const requiredRelationFieldSchema = relationFieldSchema.refine((value) => value !== null, { const requiredRelationFieldSchema = relationFieldSchema.superRefine((value, ctx) => {
if (!value?.value) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "This field is required", message: "This field is required",
}) })
}
})
const optionalNumericField = z.preprocess( const optionalNumericField = z.preprocess(
(value) => { (value) => {