From cf3bcd1f3d1e0649204a786e9532a099772dad85 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 09:42:34 +0700 Subject: update cart pop up --- src-migrate/pages/shop/cart/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index f33dde09..a2e477da 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -1,6 +1,6 @@ import style from './cart.module.css'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useEffect, useMemo, useRef, useState } from 'react'; import Link from 'next/link'; import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react'; import { toast } from 'react-hot-toast'; @@ -28,10 +28,12 @@ const CartPage = () => { const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) const [isLoadDelete, setIsLoadDelete] = useState(false) - const { loadCart, cart, summary } = useCartStore(); + const { loadCart, cart, summary, } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); + const [hasChanged, setHasChanged] = useState(false); + const prevCartRef = useRef(null); useEffect(() => { const handleScroll = () => { -- cgit v1.2.3 From ae6033238a4e7765bce7cbe96a2662f3c00b67c1 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 09:51:26 +0700 Subject: upadate new cart pop up --- src-migrate/pages/shop/cart/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index a2e477da..c9ff86b7 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -28,7 +28,7 @@ const CartPage = () => { const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) const [isLoadDelete, setIsLoadDelete] = useState(false) - const { loadCart, cart, summary, } = useCartStore(); + const { loadCart, cart, summary, updateCartItem} = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); -- cgit v1.2.3 From a76376b74c02ee6875b68b6cfb59090a159df40a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 31 Aug 2024 11:44:49 +0700 Subject: update new cart pop up --- src-migrate/pages/shop/cart/index.tsx | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/shop/cart/index.tsx b/src-migrate/pages/shop/cart/index.tsx index c9ff86b7..2fa53681 100644 --- a/src-migrate/pages/shop/cart/index.tsx +++ b/src-migrate/pages/shop/cart/index.tsx @@ -28,7 +28,7 @@ const CartPage = () => { const [buttonSelectNow, setButtonSelectNow] = useState(true); const [isLoad, setIsLoad] = useState(false) const [isLoadDelete, setIsLoadDelete] = useState(false) - const { loadCart, cart, summary, updateCartItem} = useCartStore(); + const { loadCart, cart, summary, updateCartItem } = useCartStore(); const useDivvice = useDevice(); const { setRefreshCart } = useProductCartContext() const [isTop, setIsTop] = useState(true); @@ -101,6 +101,31 @@ const CartPage = () => { return cart.products.every(item => item.selected); }, [cart]); + + useEffect(() => { + const updateCartItems = async () => { + if (typeof auth === 'object' && cart) { + const upsertPromises = cart.products.map(item => + upsertUserCart({ + userId: auth.id, + type: item.cart_type, + id: item.id, + qty: item.quantity, + selected: item.selected + }) + ); + try { + await Promise.all(upsertPromises); + await loadCart(auth.id); + } catch (error) { + console.error('Failed to update cart items:', error); + } + } + }; + + updateCartItems(); + }, [hasChanged]); + const handleCheckout = () => { router.push('/shop/checkout'); } @@ -151,7 +176,7 @@ const CartPage = () => { return ( <> -
+
Keranjang Belanja
@@ -169,7 +194,7 @@ const CartPage = () => { /> )}

- {hasSelectedAll ? "Unchek all" : "Select all"} + {hasSelectedAll ? "Uncheck all" : "Select all"}

@@ -183,7 +208,7 @@ const CartPage = () => { variant='outline' colorScheme='red' w='full' - isDisabled={!hasSelected || hasSelectNoPrice} + isDisabled={!hasSelected} onClick={handleDelete} > {isLoadDelete && } @@ -290,4 +315,4 @@ const CartPage = () => { ); }; -export default CartPage; +export default CartPage; \ No newline at end of file -- cgit v1.2.3 From 702b5d9b6e215ad812fadaff3325e1e6164d3b24 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 2 Sep 2024 10:54:00 +0700 Subject: update pop up tambah keranjang --- src-migrate/pages/api/product-variant/[id].tsx | 1 + 1 file changed, 1 insertion(+) (limited to 'src-migrate/pages') diff --git a/src-migrate/pages/api/product-variant/[id].tsx b/src-migrate/pages/api/product-variant/[id].tsx index 955fde6a..2c46ac89 100644 --- a/src-migrate/pages/api/product-variant/[id].tsx +++ b/src-migrate/pages/api/product-variant/[id].tsx @@ -38,6 +38,7 @@ const map = async (variant: any, price_tier: string) => { data.name = variant.name_s data.default_code = variant.default_code_s data.price = { discount_percentage: 0, price, price_discount: price } + data.manufacture = {manufacture_name: variant.manufacture_name_s, manufacture_id:variant.manufacture_id_i} return data } -- cgit v1.2.3