From 49e9e958fa106fb8da125d5c456252d0db8dccb9 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 22 Jan 2026 14:20:16 +0700 Subject: [PATCH] refactor(FE): Use local state for record date and disable reinitialization --- .../recording/form/RecordingForm.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 7365c6ca..65f72925 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -197,6 +197,11 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { const router = useRouter(); // ===== STATE MANAGEMENT ===== + const [selectedRecordDate, setSelectedRecordDate] = useState( + initialValues?.record_datetime + ? new Date(initialValues.record_datetime).toISOString().split('T')[0] + : new Date().toISOString().split('T')[0] + ); const [selectedStocks, setSelectedStocks] = useState([]); const [selectedDepletions, setSelectedDepletions] = useState([]); const [selectedEggs, setSelectedEggs] = useState([]); @@ -911,6 +916,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { baseValues = getRecordingGrowingFormInitialValues(initialValues); } + baseValues.record_date = selectedRecordDate; + if (type === 'add') { baseValues.location = selectedLocation ? { @@ -967,13 +974,22 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { } return baseValues; - }, [initialValues, isLayingCategory, projectFlockKandangDetail, type]); + }, [ + initialValues, + isLayingCategory, + projectFlockKandangDetail, + type, + selectedRecordDate, + selectedLocation, + selectedProjectFlock, + selectedKandang, + ]); const formik = useFormik< RecordingGrowingFormValues | RecordingLayingFormValues >({ initialValues: formikInitialValues, - enableReinitialize: true, + enableReinitialize: false, validationSchema: (() => { let schema; if (isLayingCategory) { @@ -1333,6 +1349,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { (e: React.ChangeEvent) => { const newDate = e.target.value; formik.setFieldValue('record_date', newDate); + setSelectedRecordDate(newDate); setCurrentRecordDate(newDate); if (duplicateErrorShown) { toast.dismiss();