fix: update default values in service form and enhance validation for required fields
This commit is contained in:
parent
4b51ffe457
commit
25c3125894
@ -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: "",
|
||||||
|
|||||||
@ -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) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user