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 ──
const DEFAULT_VALUES: ServiceFormValues = {
shop_type: null,
category: null,
unit_type: null,
department: null,
shop_type: { value: "", label: "" },
category: { value: "", label: "" },
unit_type: { value: "", label: "" },
department: { value: "", label: "" },
labor_name: "",
service_code: "",
labor_matrix: "",

View File

@ -5,8 +5,13 @@ export const relationFieldSchema = z
.object({ value: z.string(), label: z.string() })
.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",
})
}
})
const optionalNumericField = z.preprocess(