mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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 };
|
||||
}, [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: {
|
||||
available: number;
|
||||
unavailable: number;
|
||||
@@ -298,9 +340,8 @@ const TransferToLayingFormModal = () => {
|
||||
let countAvailable = 0;
|
||||
let countUnavailable = 0;
|
||||
|
||||
selectedFlockDestinationRawData?.kandangs.forEach((item) => {
|
||||
// TODO: change this to real available quota later
|
||||
if (item.capacity > 0) {
|
||||
mappedFlockDestinationKandangsMaxTargetQty.forEach((item) => {
|
||||
if (item.max_target_qty > 0) {
|
||||
countAvailable += 1;
|
||||
} else {
|
||||
countUnavailable += 1;
|
||||
@@ -308,7 +349,7 @@ const TransferToLayingFormModal = () => {
|
||||
});
|
||||
|
||||
return { available: countAvailable, unavailable: countUnavailable };
|
||||
}, [selectedFlockDestinationRawData]);
|
||||
}, [mappedFlockDestinationKandangsMaxTargetQty]);
|
||||
|
||||
const totalEnteredChickenForTransfer =
|
||||
formik.values.flockSourceKandangs.reduce(
|
||||
@@ -648,10 +689,9 @@ const TransferToLayingFormModal = () => {
|
||||
</div>
|
||||
|
||||
<div className='w-full rounded-xl border border-base-content/10'>
|
||||
{selectedFlockDestinationRawData?.kandangs.map(
|
||||
{mappedFlockDestinationKandangsMaxTargetQty.map(
|
||||
(item, itemIdx) => {
|
||||
// TODO: change this to real available quota later
|
||||
const isAvailable = item.capacity > 0;
|
||||
const isAvailable = item.max_target_qty > 0;
|
||||
const isChecked =
|
||||
formik.values.flockDestinationKandangs.some(
|
||||
(k) =>
|
||||
@@ -669,11 +709,10 @@ const TransferToLayingFormModal = () => {
|
||||
{
|
||||
kandang: {
|
||||
value: item.project_flock_kandang_id,
|
||||
label: item.name,
|
||||
label: item.kandang_name,
|
||||
},
|
||||
quantity: '',
|
||||
// TODO: change this to real available quota later
|
||||
maxQuantity: item.capacity,
|
||||
maxQuantity: item.max_target_qty,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
@@ -718,9 +757,8 @@ const TransferToLayingFormModal = () => {
|
||||
'cursor-not-allowed': !isAvailable,
|
||||
})}
|
||||
>
|
||||
{item.name}{' '}
|
||||
{/* TODO: change this to real available quota later */}
|
||||
<span className='text-base-content/20'>{`(Max: ${item.capacity})`}</span>
|
||||
{item.kandang_name}{' '}
|
||||
<span className='text-base-content/20'>{`(Max: ${item.max_target_qty})`}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user