mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 07:15:44 +00:00
fix: get real max quantity in target project flock kandang
This commit is contained in:
@@ -288,6 +288,48 @@ const TransferToLayingFormModal = () => {
|
|||||||
return { available: countAvailable, unavailable: countUnavailable };
|
return { available: countAvailable, unavailable: countUnavailable };
|
||||||
}, [mappedFlockSourceKandangsAvailability]);
|
}, [mappedFlockSourceKandangsAvailability]);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: flockDestinationKandangsMaxTargetQty,
|
||||||
|
isLoading: isLoadingFlockDestinationKandangsMaxTargetQty,
|
||||||
|
} = useSWR(
|
||||||
|
formik.values.flockDestination
|
||||||
|
? [
|
||||||
|
'transfer-to-laying',
|
||||||
|
'max-target-qty',
|
||||||
|
String(formik.values.flockDestination.value),
|
||||||
|
]
|
||||||
|
: undefined,
|
||||||
|
([, , id]: string[]) =>
|
||||||
|
TransferToLayingApi.getMappedFlockKandangsMaxTargetQty(Number(id))
|
||||||
|
);
|
||||||
|
|
||||||
|
const mappedFlockDestinationKandangsMaxTargetQty: {
|
||||||
|
kandang_name: string;
|
||||||
|
max_target_qty: number;
|
||||||
|
project_flock_kandang_id: number;
|
||||||
|
}[] = useMemo(() => {
|
||||||
|
if (
|
||||||
|
!flockDestinationKandangsMaxTargetQty ||
|
||||||
|
!selectedFlockDestinationRawData
|
||||||
|
)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
return selectedFlockDestinationRawData
|
||||||
|
? selectedFlockDestinationRawData.kandangs.map((kandang) => {
|
||||||
|
const maxQty =
|
||||||
|
flockDestinationKandangsMaxTargetQty[
|
||||||
|
kandang.project_flock_kandang_id
|
||||||
|
]?.max_target_qty;
|
||||||
|
|
||||||
|
return {
|
||||||
|
kandang_name: kandang.name,
|
||||||
|
max_target_qty: maxQty,
|
||||||
|
project_flock_kandang_id: kandang.project_flock_kandang_id,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
: [];
|
||||||
|
}, [flockDestinationKandangsMaxTargetQty, selectedFlockDestinationRawData]);
|
||||||
|
|
||||||
const mappedFlockDestinationKandangsAvailabilityInfo: {
|
const mappedFlockDestinationKandangsAvailabilityInfo: {
|
||||||
available: number;
|
available: number;
|
||||||
unavailable: number;
|
unavailable: number;
|
||||||
@@ -298,9 +340,8 @@ const TransferToLayingFormModal = () => {
|
|||||||
let countAvailable = 0;
|
let countAvailable = 0;
|
||||||
let countUnavailable = 0;
|
let countUnavailable = 0;
|
||||||
|
|
||||||
selectedFlockDestinationRawData?.kandangs.forEach((item) => {
|
mappedFlockDestinationKandangsMaxTargetQty.forEach((item) => {
|
||||||
// TODO: change this to real available quota later
|
if (item.max_target_qty > 0) {
|
||||||
if (item.capacity > 0) {
|
|
||||||
countAvailable += 1;
|
countAvailable += 1;
|
||||||
} else {
|
} else {
|
||||||
countUnavailable += 1;
|
countUnavailable += 1;
|
||||||
@@ -308,7 +349,7 @@ const TransferToLayingFormModal = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return { available: countAvailable, unavailable: countUnavailable };
|
return { available: countAvailable, unavailable: countUnavailable };
|
||||||
}, [selectedFlockDestinationRawData]);
|
}, [mappedFlockDestinationKandangsMaxTargetQty]);
|
||||||
|
|
||||||
const totalEnteredChickenForTransfer =
|
const totalEnteredChickenForTransfer =
|
||||||
formik.values.flockSourceKandangs.reduce(
|
formik.values.flockSourceKandangs.reduce(
|
||||||
@@ -648,10 +689,9 @@ const TransferToLayingFormModal = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='w-full rounded-xl border border-base-content/10'>
|
<div className='w-full rounded-xl border border-base-content/10'>
|
||||||
{selectedFlockDestinationRawData?.kandangs.map(
|
{mappedFlockDestinationKandangsMaxTargetQty.map(
|
||||||
(item, itemIdx) => {
|
(item, itemIdx) => {
|
||||||
// TODO: change this to real available quota later
|
const isAvailable = item.max_target_qty > 0;
|
||||||
const isAvailable = item.capacity > 0;
|
|
||||||
const isChecked =
|
const isChecked =
|
||||||
formik.values.flockDestinationKandangs.some(
|
formik.values.flockDestinationKandangs.some(
|
||||||
(k) =>
|
(k) =>
|
||||||
@@ -669,11 +709,10 @@ const TransferToLayingFormModal = () => {
|
|||||||
{
|
{
|
||||||
kandang: {
|
kandang: {
|
||||||
value: item.project_flock_kandang_id,
|
value: item.project_flock_kandang_id,
|
||||||
label: item.name,
|
label: item.kandang_name,
|
||||||
},
|
},
|
||||||
quantity: '',
|
quantity: '',
|
||||||
// TODO: change this to real available quota later
|
maxQuantity: item.max_target_qty,
|
||||||
maxQuantity: item.capacity,
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
@@ -718,9 +757,8 @@ const TransferToLayingFormModal = () => {
|
|||||||
'cursor-not-allowed': !isAvailable,
|
'cursor-not-allowed': !isAvailable,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{item.name}{' '}
|
{item.kandang_name}{' '}
|
||||||
{/* TODO: change this to real available quota later */}
|
<span className='text-base-content/20'>{`(Max: ${item.max_target_qty})`}</span>
|
||||||
<span className='text-base-content/20'>{`(Max: ${item.capacity})`}</span>
|
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user