summaryrefslogtreecommitdiff
path: root/src-migrate/modules/cart/components/ItemSelect.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')
-rw-r--r--src-migrate/modules/cart/components/ItemSelect.tsx28
1 files changed, 13 insertions, 15 deletions
diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx
index d4a1b537..b904a1de 100644
--- a/src-migrate/modules/cart/components/ItemSelect.tsx
+++ b/src-migrate/modules/cart/components/ItemSelect.tsx
@@ -13,25 +13,23 @@ type Props = {
const CartItemSelect = ({ item }: Props) => {
const auth = getAuth()
- const { updateCartItem, cart } = useCartStore()
+ const { loadCart } = useCartStore()
const [isLoad, setIsLoad] = useState<boolean>(false)
const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
- 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);
+ 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)
}
return (