From 76c1b2f62885dffe4a65f8265ec89e22e9a64146 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 15 Jan 2026 16:35:32 +0700 Subject: [PATCH] refactor(FE): Derive current total chick qty from flock data --- .../recording/form/RecordingForm.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 9dd3df1f..32c8c4c6 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -725,7 +725,26 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { }, [existingRecordings, today]); const currentTotalChickQty = useMemo(() => { - if (!isResponseSuccess(existingRecordings) || !selectedKandang) return null; + if (type === 'add' && projectFlockKandangLookup) { + return projectFlockKandangLookup.available_quantity || null; + } + + if ((type === 'edit' || type === 'detail') && projectFlockKandangDetail) { + if ( + projectFlockKandangDetail.available_qtys && + projectFlockKandangDetail.available_qtys.length > 0 + ) { + return projectFlockKandangDetail.available_qtys.reduce( + (sum, item) => sum + (item.available_qty || 0), + 0 + ); + } + return null; + } + + if (!isResponseSuccess(existingRecordings) || !selectedKandang) { + return null; + } let projectFlockKandangId: number | undefined; @@ -745,6 +764,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { return recording?.project_flock.total_chick_qty || null; }, [ + type, existingRecordings, selectedKandang, projectFlockKandangLookup,