From cd42bd6bc08bf3c891c644bf358499160159af5d Mon Sep 17 00:00:00 2001 From: randy-ar Date: Mon, 29 Dec 2025 13:26:39 +0700 Subject: [PATCH] fix(FE): change hatchery to optional in master data supplier --- .../pages/master-data/nonstock/form/NonstockForm.tsx | 8 ++++---- .../master-data/supplier/form/SupplierForm.schema.ts | 2 +- .../pages/master-data/supplier/form/SupplierForm.tsx | 9 ++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/pages/master-data/nonstock/form/NonstockForm.tsx b/src/components/pages/master-data/nonstock/form/NonstockForm.tsx index 47875902..af72f22f 100644 --- a/src/components/pages/master-data/nonstock/form/NonstockForm.tsx +++ b/src/components/pages/master-data/nonstock/form/NonstockForm.tsx @@ -79,14 +79,14 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => { uomId: initialValues?.uom_id ?? 0, uom: initialValues?.uom ? { - value: initialValues?.uom.id, - label: initialValues?.uom.name, + value: initialValues?.uom?.id, + label: initialValues?.uom?.name, } : null, supplierIds: - initialValues?.suppliers.map((supplier) => supplier.id) ?? [], + initialValues?.suppliers?.map((supplier) => supplier.id) ?? [], suppliers: - initialValues?.suppliers.map((supplier) => ({ + initialValues?.suppliers?.map((supplier) => ({ value: supplier.id, label: supplier.name, })) ?? [], diff --git a/src/components/pages/master-data/supplier/form/SupplierForm.schema.ts b/src/components/pages/master-data/supplier/form/SupplierForm.schema.ts index 12c70b1c..9ec3890a 100644 --- a/src/components/pages/master-data/supplier/form/SupplierForm.schema.ts +++ b/src/components/pages/master-data/supplier/form/SupplierForm.schema.ts @@ -18,7 +18,7 @@ export const SupplierFormSchema = Yup.object({ value: Yup.string().required(), label: Yup.string().required(), }).required('Tipe wajib diisi!'), - hatchery: Yup.string().required('Hatchery wajib diisi!'), + hatchery: Yup.string().optional(), phone: Yup.string() .matches(/^[0-9]+$/, 'Nomor telepon hanya boleh berisi angka!') .min(10, 'Nomor telepon minimal 10 digit!') diff --git a/src/components/pages/master-data/supplier/form/SupplierForm.tsx b/src/components/pages/master-data/supplier/form/SupplierForm.tsx index d410ac11..2cacea89 100644 --- a/src/components/pages/master-data/supplier/form/SupplierForm.tsx +++ b/src/components/pages/master-data/supplier/form/SupplierForm.tsx @@ -142,7 +142,7 @@ const SupplierForm = ({ pic: values.pic, type: values.type.value, category: values.category.value, - hatchery: values.hatchery, + hatchery: values.hatchery ?? '', phone: values.phone, email: values.email, address: values.address, @@ -171,12 +171,12 @@ const SupplierForm = ({ useEffect(() => { formikSetValues(formikInitialValues); if (formType != 'add') { - const hatcheryArrays = formikInitialValues.hatchery.split(','); - const hatcheryCreatedOptions = hatcheryArrays.map((item) => ({ + const hatcheryArrays = formikInitialValues.hatchery?.split(','); + const hatcheryCreatedOptions = hatcheryArrays?.map((item) => ({ value: item, label: item, })); - setHatcheryOptionValues(hatcheryCreatedOptions); + setHatcheryOptionValues(hatcheryCreatedOptions ?? []); } }, [formikSetValues, formikInitialValues, setHatcheryOptionValues]); useEffect(() => { @@ -302,7 +302,6 @@ const SupplierForm = ({