From 65a011c97f00bba4dd39b1d66690fa5a2a82d300 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Wed, 1 Apr 2020 20:17:16 -0600 Subject: [PATCH] Cart error messages --- pages/store/cart.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 + })()} )