feat: add listen channel field to DetailDevice component and update ListDevice to display it; enhance quantity handling in SparepartCardList to prevent negative adjustments

This commit is contained in:
2025-12-04 15:59:57 +07:00
parent 147171373c
commit acaf1b3946
3 changed files with 31 additions and 3 deletions

View File

@@ -21,8 +21,15 @@ const SparepartCardList = ({
const [loadingQuantities, setLoadingQuantities] = useState({});
const handleQuantityChange = (id, value) => {
// Prevent the adjustment from going below the negative value of the original quantity
// This ensures the final quantity (original + adjustment) never goes below 0
const originalQty = data.find((item) => item.sparepart_id === id)?.sparepart_qty || 0;
const maxNegativeAdjustment = -originalQty;
const clampedValue = Math.max(value, maxNegativeAdjustment);
const newQuantities = { ...updateQuantities };
newQuantities[id] = value;
newQuantities[id] = clampedValue;
setUpdateQuantities(newQuantities);
};
@@ -319,7 +326,9 @@ const SparepartCardList = ({
quantity - 1
)
}
disabled={isLoading}
disabled={
isLoading || item.sparepart_qty + quantity <= 0
}
style={{ width: 28, height: 28 }}
/>
<Text