diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-31 09:51:26 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-31 09:51:26 +0700 |
| commit | ae6033238a4e7765bce7cbe96a2662f3c00b67c1 (patch) | |
| tree | ea6d365de76c4e9142822d16ecb8dec4d7f7426e /src-migrate/modules/cart/stores | |
| parent | cf3bcd1f3d1e0649204a786e9532a099772dad85 (diff) | |
<iman> upadate new cart pop up
Diffstat (limited to 'src-migrate/modules/cart/stores')
| -rw-r--r-- | src-migrate/modules/cart/stores/useCartStore.ts | 14 |
1 files changed, 12 insertions, 2 deletions
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 |
