fix removing all shopping cart items when removing one item

This commit is contained in:
Nuwan 2025-02-22 02:11:58 +05:30
parent 9c0e643b23
commit dcb842035f
1 changed files with 14 additions and 2 deletions

View File

@ -46,7 +46,19 @@ export const useShoppingCart = () => {
}
}, [shoppingCart]);
const removeCartItem = useCallback(async (id) => {
// const removeCartItem = useCallback(async (id) => {
// try {
// await removeShoppingCart({id});
// setShoppingCart(shoppingCart.filter(item => item.id !== id));
// return true;
// } catch (error) {
// console.error(error);
// return false;
// }
// }, []);
const removeCartItem = async (id) => {
try {
await removeShoppingCart({id});
setShoppingCart(shoppingCart.filter(item => item.id !== id));
@ -56,7 +68,7 @@ export const useShoppingCart = () => {
return false;
}
}, []);
}
const hasOnlyFreeItemsInShoppingCart = useCallback(() => {
return shoppingCart.length === 0 || shoppingCart.every(item => item.product_info.free);