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 | |
| parent | ae6033238a4e7765bce7cbe96a2662f3c00b67c1 (diff) | |
<iman> update new cart pop up
Diffstat (limited to 'src-migrate/modules')
| -rw-r--r-- | src-migrate/modules/cart/components/ItemSelect.tsx | 28 | ||||
| -rw-r--r-- | src-migrate/modules/product-promo/components/AddToCart.tsx | 2 |
2 files changed, 16 insertions, 14 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 ( diff --git a/src-migrate/modules/product-promo/components/AddToCart.tsx b/src-migrate/modules/product-promo/components/AddToCart.tsx index 3d0955e3..a3938142 100644 --- a/src-migrate/modules/product-promo/components/AddToCart.tsx +++ b/src-migrate/modules/product-promo/components/AddToCart.tsx @@ -135,7 +135,7 @@ const ProductPromoAddToCart = ({product, promotion }: Props) => { {!!product?.manufacture?.name ? ( <Link href={createSlug('/shop/brands/', product.manufacture.name, product.manufacture.id.toString())} - className=' hover:underline' + className=' hover:underline text-red-500' color={"red"} > {product.manufacture.name} |
