summaryrefslogtreecommitdiff
path: root/src-migrate/modules/cart/stores
diff options
context:
space:
mode:
authorIT Fixcomart <it@fixcomart.co.id>2024-08-07 02:59:42 +0000
committerIT Fixcomart <it@fixcomart.co.id>2024-08-07 02:59:42 +0000
commitc26e511923265385bf5c3060de23c7e61912992c (patch)
treed38dd71d52eebe5ea428ae73ed6b2f4f52301891 /src-migrate/modules/cart/stores
parentd96c0885db3a1aa0c4c7ceb0d2ab7d64d99f67f6 (diff)
parent213b4444c48896f24dd6803a9db2ae58af5b0391 (diff)
Merged in Feature/iman-unchek-cart (pull request #217)
Feature/iman unchek cart
Diffstat (limited to 'src-migrate/modules/cart/stores')
-rw-r--r--src-migrate/modules/cart/stores/useCartStore.ts12
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) => {