diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-05 09:38:32 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-05 09:38:32 +0700 |
| commit | 8aa9307006910e5b512fc6551f0046f0c5a6a2d5 (patch) | |
| tree | 4380367b52d4881e37d26b4f5477b6eec462a91c /src-migrate/modules/cart/components/ItemSelect.tsx | |
| parent | 574754df6366cd693fbe2cd04a7a50fdf9597d1e (diff) | |
| parent | 7eb2d613c6b16c89dd06491a54b229bcbcb8dc13 (diff) | |
Merge branch 'development' of https://bitbucket.org/altafixco/next-indoteknik into development
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Diffstat (limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')
| -rw-r--r-- | src-migrate/modules/cart/components/ItemSelect.tsx | 28 |
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 ( |
