summaryrefslogtreecommitdiff
path: root/src-migrate
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-31 09:51:26 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-31 09:51:26 +0700
commitae6033238a4e7765bce7cbe96a2662f3c00b67c1 (patch)
treeea6d365de76c4e9142822d16ecb8dec4d7f7426e /src-migrate
parentcf3bcd1f3d1e0649204a786e9532a099772dad85 (diff)
<iman> upadate new cart pop up
Diffstat (limited to 'src-migrate')
-rw-r--r--src-migrate/modules/cart/components/ItemAction.tsx5
-rw-r--r--src-migrate/modules/cart/stores/useCartStore.ts14
-rw-r--r--src-migrate/pages/shop/cart/index.tsx2
3 files changed, 16 insertions, 5 deletions
diff --git a/src-migrate/modules/cart/components/ItemAction.tsx b/src-migrate/modules/cart/components/ItemAction.tsx
index e73d507b..7220e362 100644
--- a/src-migrate/modules/cart/components/ItemAction.tsx
+++ b/src-migrate/modules/cart/components/ItemAction.tsx
@@ -11,7 +11,7 @@ import { deleteUserCart, upsertUserCart } from '~/services/cart'
import { useDebounce } from 'usehooks-ts'
import { useCartStore } from '../stores/useCartStore'
-
+import { useProductCartContext } from '@/contexts/ProductCartContext'
type Props = {
item: CartItem
@@ -19,7 +19,7 @@ type Props = {
const CartItemAction = ({ item }: Props) => {
const auth = getAuth()
-
+ const { setRefreshCart } = useProductCartContext()
const [isLoadDelete, setIsLoadDelete] = useState<boolean>(false)
const [isLoadQuantity, setIsLoadQuantity] = useState<boolean>(false)
@@ -36,6 +36,7 @@ const CartItemAction = ({ item }: Props) => {
await deleteUserCart(auth.id, [item.cart_id])
await loadCart(auth.id)
setIsLoadDelete(false)
+ setRefreshCart(true)
}
const decreaseQty = () => { setQuantity((quantity) => quantity -= 1) }
diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts
index 3d9a0aed..aad39a30 100644
--- a/src-migrate/modules/cart/stores/useCartStore.ts
+++ b/src-migrate/modules/cart/stores/useCartStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand';
-import { CartProps } from '~/types/cart';
+import { CartItem, CartProps } from '~/types/cart';
import { getUserCart } from '~/services/cart';
type State = {
@@ -16,6 +16,7 @@ type State = {
type Action = {
loadCart: (userId: number) => Promise<void>;
+ updateCartItem: (updateCart: CartProps) => void;
};
export const useCartStore = create<State & Action>((set, get) => ({
@@ -39,6 +40,15 @@ export const useCartStore = create<State & Action>((set, get) => ({
const summary = computeSummary(cart);
set({ summary });
},
+ updateCartItem: (updatedCart) => {
+ const cart = get().cart;
+ if (!cart) return;
+
+ set({ cart: updatedCart });
+ const summary = computeSummary(updatedCart);
+ set({ summary });
+ },
+
}));
const computeSummary = (cart: CartProps) => {
@@ -61,4 +71,4 @@ const computeSummary = (cart: CartProps) => {
let grandTotal = total + tax;
return { subtotal, discount, total, tax, grandTotal };
-};
+}; \ No newline at end of file
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<boolean>(false)
const [isLoadDelete, setIsLoadDelete] = useState<boolean>(false)
- const { loadCart, cart, summary, } = useCartStore();
+ const { loadCart, cart, summary, updateCartItem} = useCartStore();
const useDivvice = useDevice();
const { setRefreshCart } = useProductCartContext()
const [isTop, setIsTop] = useState(true);