mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Derive current total chick qty from flock data
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user