Open Jared-Jianbin opened 2 years ago
Someone is attempting to deploy a commit to a Personal Account owned by @adrianhajdin on Vercel.
@adrianhajdin first needs to authorize it.
Fix for toggleCartItemQuantity changing the order of product in cart
const toggleCartItemQuantity = (id, action) => { foundProduct = cartItems.find(item => item._id === id) index = cartItems.findIndex(product => product._id === id) const currCartItem = cartItems.filter(item => item._id !== id)
if(action === 'inc'){
currCartItem.splice(index, 0, {...foundProduct, quantity: foundProduct.quantity+1})
setCartItems(currCartItem)
setTotalPrice(prevTotalPrice => prevTotalPrice + foundProduct.price)
setTotalQuantities(prevTotalQuantities => prevTotalQuantities + 1)
}else if(action === 'dec'){
if(foundProduct.quantity > 1){
currCartItem.splice(index, 0, {...foundProduct, quantity: foundProduct.quantity-1})
setCartItems(currCartItem)
setTotalPrice (prevTotalPrice => prevTotalPrice - foundProduct.price)
setTotalQuantities(prevTotalQuantities => prevTotalQuantities - 1)
}
}
}
Merge
Fixed the quantity change position issue in the cart, the position is changed because the index of product changed in the array, I used map to return them in the same order.