diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-31 11:44:49 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-31 11:44:49 +0700 |
| commit | a76376b74c02ee6875b68b6cfb59090a159df40a (patch) | |
| tree | 58b38643f835852ed7ca443fef42a8487f9d7ba2 /src-migrate/modules/cart | |
| parent | ae6033238a4e7765bce7cbe96a2662f3c00b67c1 (diff) | |
<iman> update new cart pop up
Diffstat (limited to 'src-migrate/modules/cart')
| -rw-r--r-- | src-migrate/modules/cart/components/ItemSelect.tsx | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx index b904a1de..d4a1b537 100644 --- a/src-migrate/modules/cart/components/ItemSelect.tsx +++ b/src-migrate/modules/cart/components/ItemSelect.tsx @@ -13,23 +13,25 @@ type Props = { const CartItemSelect = ({ item }: Props) => { const auth = getAuth() - const { loadCart } = useCartStore() + const { updateCartItem, cart } = useCartStore() const [isLoad, setIsLoad] = useState<boolean>(false) const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => { - if (typeof auth !== 'object') return - - setIsLoad(true) - await upsertUserCart({ - userId: auth.id, - type: item.cart_type, - id: item.id, - qty: item.quantity, - selected: e.target.checked - }) - await loadCart(auth.id) - setIsLoad(false) + if (typeof auth !== 'object' || !cart) return + + setIsLoad(true); + const updatedCartItems = cart.products.map(cartItem => + cartItem.id === item.id + ? { ...cartItem, selected: e.target.checked } + : cartItem + ); + + // Update the entire cart + const updatedCart = { ...cart, products: updatedCartItems }; + updateCartItem(updatedCart); + + setIsLoad(false); } return ( |
