diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-08-03 13:33:59 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-08-03 13:33:59 +0700 |
| commit | 865f509a8b45c6db195661f35417623572d33cea (patch) | |
| tree | b97795e1afe6e5af045915a30df58d7ac92daf23 /src-migrate/modules/cart/stores/useCartStore.ts | |
| parent | 4e25a60e9c3cf93cc1faf77a5bf1ad7e6f0555ec (diff) | |
<iman> update unchek cart
Diffstat (limited to 'src-migrate/modules/cart/stores/useCartStore.ts')
| -rw-r--r-- | src-migrate/modules/cart/stores/useCartStore.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts index 3d9a0aed..3b50ec32 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) => { |
