refactor(FE): Refactor Formik field updates to use setFieldValue

This commit is contained in:
rstubryan
2026-03-05 15:00:20 +07:00
parent a5ebc6d1ae
commit 77eae32a3d
2 changed files with 18 additions and 19 deletions
@@ -167,29 +167,26 @@ const SupplierForm = ({
},
});
const { setValues: formikSetValues } = formik;
const { setFieldValue } = formik;
// Initialize Formik
useEffect(() => {
formikSetValues(formikInitialValues);
if (formType != 'add') {
const hatcheryArrays = formikInitialValues.hatchery?.split(',');
const hatcheryCreatedOptions = hatcheryArrays?.map((item) => ({
if (formType !== 'add' && initialValues?.hatchery) {
const hatcheryArrays = initialValues.hatchery.split(',');
const hatcheryCreatedOptions = hatcheryArrays.map((item) => ({
value: item,
label: item,
}));
setHatcheryOptionValues(hatcheryCreatedOptions ?? []);
setHatcheryOptionValues(hatcheryCreatedOptions);
}
}, [formikSetValues, formikInitialValues, setHatcheryOptionValues]);
}, [formType, initialValues?.hatchery]);
useEffect(() => {
const commaSeparatedValues = hatcheryOptionsValues
.map((item) => item.value)
.join(',');
formikSetValues({
...formik.values,
hatchery: commaSeparatedValues,
});
}, [hatcheryOptionsValues, formikSetValues]);
setFieldValue('hatchery', commaSeparatedValues);
}, [hatcheryOptionsValues, setFieldValue]);
// Option Handler
const typeChangeHandler = (val: OptionType | OptionType[] | null) => {