fix(FE): change hatchery to optional in master data supplier

This commit is contained in:
randy-ar
2025-12-29 13:26:39 +07:00
parent ea7f8a68f4
commit cd42bd6bc0
3 changed files with 9 additions and 10 deletions
@@ -79,14 +79,14 @@ const NonstockForm = ({ type = 'add', initialValues }: NonstockFormProps) => {
uomId: initialValues?.uom_id ?? 0, uomId: initialValues?.uom_id ?? 0,
uom: initialValues?.uom uom: initialValues?.uom
? { ? {
value: initialValues?.uom.id, value: initialValues?.uom?.id,
label: initialValues?.uom.name, label: initialValues?.uom?.name,
} }
: null, : null,
supplierIds: supplierIds:
initialValues?.suppliers.map((supplier) => supplier.id) ?? [], initialValues?.suppliers?.map((supplier) => supplier.id) ?? [],
suppliers: suppliers:
initialValues?.suppliers.map((supplier) => ({ initialValues?.suppliers?.map((supplier) => ({
value: supplier.id, value: supplier.id,
label: supplier.name, label: supplier.name,
})) ?? [], })) ?? [],
@@ -18,7 +18,7 @@ export const SupplierFormSchema = Yup.object({
value: Yup.string().required(), value: Yup.string().required(),
label: Yup.string().required(), label: Yup.string().required(),
}).required('Tipe wajib diisi!'), }).required('Tipe wajib diisi!'),
hatchery: Yup.string().required('Hatchery wajib diisi!'), hatchery: Yup.string().optional(),
phone: Yup.string() phone: Yup.string()
.matches(/^[0-9]+$/, 'Nomor telepon hanya boleh berisi angka!') .matches(/^[0-9]+$/, 'Nomor telepon hanya boleh berisi angka!')
.min(10, 'Nomor telepon minimal 10 digit!') .min(10, 'Nomor telepon minimal 10 digit!')
@@ -142,7 +142,7 @@ const SupplierForm = ({
pic: values.pic, pic: values.pic,
type: values.type.value, type: values.type.value,
category: values.category.value, category: values.category.value,
hatchery: values.hatchery, hatchery: values.hatchery ?? '',
phone: values.phone, phone: values.phone,
email: values.email, email: values.email,
address: values.address, address: values.address,
@@ -171,12 +171,12 @@ const SupplierForm = ({
useEffect(() => { useEffect(() => {
formikSetValues(formikInitialValues); formikSetValues(formikInitialValues);
if (formType != 'add') { if (formType != 'add') {
const hatcheryArrays = formikInitialValues.hatchery.split(','); const hatcheryArrays = formikInitialValues.hatchery?.split(',');
const hatcheryCreatedOptions = hatcheryArrays.map((item) => ({ const hatcheryCreatedOptions = hatcheryArrays?.map((item) => ({
value: item, value: item,
label: item, label: item,
})); }));
setHatcheryOptionValues(hatcheryCreatedOptions); setHatcheryOptionValues(hatcheryCreatedOptions ?? []);
} }
}, [formikSetValues, formikInitialValues, setHatcheryOptionValues]); }, [formikSetValues, formikInitialValues, setHatcheryOptionValues]);
useEffect(() => { useEffect(() => {
@@ -302,7 +302,6 @@ const SupplierForm = ({
<SelectInput <SelectInput
isMulti isMulti
createables createables
required
placeholder='Pilih Hatchery' placeholder='Pilih Hatchery'
label='Hatchery' label='Hatchery'
value={hatcheryOptionsValues} value={hatcheryOptionsValues}