refactor(FE): Derive current total chick qty from flock data

This commit is contained in:
rstubryan
2026-01-15 16:35:32 +07:00
parent 0a5414a3ac
commit 76c1b2f628
@@ -725,7 +725,26 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [existingRecordings, today]); }, [existingRecordings, today]);
const currentTotalChickQty = useMemo(() => { 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; let projectFlockKandangId: number | undefined;
@@ -745,6 +764,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
return recording?.project_flock.total_chick_qty || null; return recording?.project_flock.total_chick_qty || null;
}, [ }, [
type,
existingRecordings, existingRecordings,
selectedKandang, selectedKandang,
projectFlockKandangLookup, projectFlockKandangLookup,