mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE): Refactor Formik field updates to use setFieldValue
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user