diff --git a/pages/store/cart.js b/pages/store/cart.js index fa8fa66..dac20b9 100644 --- a/pages/store/cart.js +++ b/pages/store/cart.js @@ -10,7 +10,8 @@ import Table from '~/components/table' export default function Cart(){ const [cart, setCart] = useCart() const numItems = (cart?.items) ? cart.items.length : 0 - const allInStock = !cart?.items.some(item => !item.number_in_stock || item.number_in_stock < 1) + const allInStock = !cart?.items.some(item => !item.item.number_in_stock || item.item.number_in_stock < 1) + const allHaveEnough = !cart?.items.some(item => item.count > item.item.number_in_stock) const handleRemove = id => async ev => { if(ev) ev.preventDefault() @@ -36,6 +37,7 @@ export default function Cart(){ <> {row.item.name} {(!row.item.number_in_stock || row.item.number_in_stock < 1) && Out of stock} + {(row.item.number_in_stock > 0 && row.count > row.item.number_in_stock) && Not enough in stock} )}, {name: 'Quantity in Cart', extractor: row => row.count}, @@ -72,7 +74,18 @@ export default function Cart(){ } - + {(()=>{ + if(!(cart?.items?.length)) + return + + if(!allInStock) + return + + if(!allHaveEnough) + return + + return + })()} )