mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Reset dependent fields when location or project flock
changes
This commit is contained in:
@@ -393,6 +393,77 @@ const UniformityForm = ({
|
|||||||
}
|
}
|
||||||
}, [setFieldValue]);
|
}, [setFieldValue]);
|
||||||
|
|
||||||
|
// ===== RESET PROJECT FLOCK & KANDANG WHEN LOCATION CHANGES =====
|
||||||
|
const prevLocationIdRef = useRef<number | string>('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentLocationId = formik.values.location_id || '';
|
||||||
|
|
||||||
|
if (currentLocationId === prevLocationIdRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevLocationIdRef.current = currentLocationId;
|
||||||
|
|
||||||
|
if (formik.values.project_flock !== null) {
|
||||||
|
setFieldTouched('project_flock', false);
|
||||||
|
setFieldValue('project_flock', null);
|
||||||
|
}
|
||||||
|
if (formik.values.project_flock_id !== 0) {
|
||||||
|
setFieldTouched('project_flock_id', false);
|
||||||
|
setFieldValue('project_flock_id', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (formik.values.kandang !== null) {
|
||||||
|
setFieldTouched('kandang', false);
|
||||||
|
setFieldValue('kandang', null);
|
||||||
|
}
|
||||||
|
if (formik.values.kandang_id !== 0) {
|
||||||
|
setFieldTouched('kandang_id', false);
|
||||||
|
setFieldValue('kandang_id', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedProjectFlock(null);
|
||||||
|
setSelectedKandang(null);
|
||||||
|
}, [
|
||||||
|
formik.values.location_id,
|
||||||
|
formik.values.project_flock,
|
||||||
|
formik.values.project_flock_id,
|
||||||
|
formik.values.kandang,
|
||||||
|
formik.values.kandang_id,
|
||||||
|
setFieldTouched,
|
||||||
|
setFieldValue,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const prevProjectFlockIdRef = useRef<number | string>('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentProjectFlockId = formik.values.project_flock_id || '';
|
||||||
|
|
||||||
|
if (currentProjectFlockId === prevProjectFlockIdRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevProjectFlockIdRef.current = currentProjectFlockId;
|
||||||
|
|
||||||
|
if (formik.values.kandang !== null) {
|
||||||
|
setFieldTouched('kandang', false);
|
||||||
|
setFieldValue('kandang', null);
|
||||||
|
}
|
||||||
|
if (formik.values.kandang_id !== 0) {
|
||||||
|
setFieldTouched('kandang_id', false);
|
||||||
|
setFieldValue('kandang_id', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedKandang(null);
|
||||||
|
}, [
|
||||||
|
formik.values.project_flock_id,
|
||||||
|
formik.values.kandang,
|
||||||
|
formik.values.kandang_id,
|
||||||
|
setFieldTouched,
|
||||||
|
setFieldValue,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleDownloadTemplate = useCallback(() => {
|
const handleDownloadTemplate = useCallback(() => {
|
||||||
const population = projectFlockKandangLookup?.population;
|
const population = projectFlockKandangLookup?.population;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user