(id, value)
| 49 | } |
| 50 | |
| 51 | const toggleCartItemQuantity = (id, value) => { |
| 52 | foundProduct = cartItems.find((item) => item._id === id) |
| 53 | index = cartItems.findIndex((product) => product._id === id) |
| 54 | const AddNewCartItems = cartItems.filter(item => item._id !== id); |
| 55 | |
| 56 | if(value === 'inc') { |
| 57 | let newCartItems = [...AddNewCartItems, {...foundProduct, quantity: foundProduct.quantity + 1}] |
| 58 | setCartItems(newCartItems); |
| 59 | setTotalPrice(prevTotalPrice => prevTotalPrice + foundProduct.price) |
| 60 | setTotalQty(prevTotalQty => prevTotalQty + 1) |
| 61 | } else if(value === 'dec') { |
| 62 | if(foundProduct.quantity > 1) { |
| 63 | let newCartItems = [...AddNewCartItems, {...foundProduct, quantity: foundProduct.quantity - 1}] |
| 64 | setCartItems(newCartItems); |
| 65 | setTotalPrice(prevTotalPrice => prevTotalPrice - foundProduct.price) |
| 66 | setTotalQty(prevTotalQty => prevTotalQty - 1) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | const incQty = () => { |
| 72 | setQty((prevQty) => prevQty + 1); |
nothing calls this directly
no outgoing calls
no test coverage detected