asv-hlps-market 1.0.40 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/auths/auth-role.d.ts +12 -0
- package/lib/cjs/auths/auth-role.js +15 -0
- package/lib/cjs/shopping/hlpShopping.d.ts +1 -1
- package/lib/cjs/shopping/shoppingStore.d.ts +34 -0
- package/lib/cjs/shopping/shoppingStore.js +112 -0
- package/lib/esm/auths/auth-role.d.ts +12 -0
- package/lib/esm/auths/auth-role.js +12 -0
- package/lib/esm/shopping/hlpShopping.d.ts +1 -1
- package/lib/esm/shopping/shoppingStore.d.ts +34 -0
- package/lib/esm/shopping/shoppingStore.js +96 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SADM: string[];
|
|
2
|
+
export declare const CEO: string[];
|
|
3
|
+
export declare const ADM: string[];
|
|
4
|
+
export declare const COMPTA: string[];
|
|
5
|
+
export declare const CAISSE: string[];
|
|
6
|
+
export declare const COMPTA_CAISSE: string[];
|
|
7
|
+
export declare const TLM_COM: string[];
|
|
8
|
+
export declare const COM: string[];
|
|
9
|
+
export declare const RCM: string[];
|
|
10
|
+
export declare const CHA: string[];
|
|
11
|
+
export declare const SEC: string[];
|
|
12
|
+
export declare const VISITOR: string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VISITOR = exports.SEC = exports.CHA = exports.RCM = exports.COM = exports.TLM_COM = exports.COMPTA_CAISSE = exports.CAISSE = exports.COMPTA = exports.ADM = exports.CEO = exports.SADM = void 0;
|
|
4
|
+
exports.SADM = ['sadm'];
|
|
5
|
+
exports.CEO = ['ceo', ...exports.SADM];
|
|
6
|
+
exports.ADM = ['adm', ...exports.CEO];
|
|
7
|
+
exports.COMPTA = ['cpt', 'acp'];
|
|
8
|
+
exports.CAISSE = ['cai', 'ceo', ...exports.ADM];
|
|
9
|
+
exports.COMPTA_CAISSE = ['cai', 'ceo', ...exports.COMPTA, ...exports.ADM];
|
|
10
|
+
exports.TLM_COM = ['tlm', 'com', ...exports.ADM];
|
|
11
|
+
exports.COM = ['com', 'rcm'];
|
|
12
|
+
exports.RCM = ['rcm'];
|
|
13
|
+
exports.CHA = ['cha'];
|
|
14
|
+
exports.SEC = ['sec'];
|
|
15
|
+
exports.VISITOR = ['vip'];
|
|
@@ -4,7 +4,7 @@ import CartItem from "./models/CartItem";
|
|
|
4
4
|
declare class HlpShopping {
|
|
5
5
|
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
6
|
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts
|
|
7
|
+
private calculateStockOrQtityLimitCounts;
|
|
8
8
|
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
9
|
getPrice: (item: CartItem) => number;
|
|
10
10
|
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Product from "../products/models/Product";
|
|
2
|
+
import CartItem from "./models/CartItem";
|
|
3
|
+
export interface ShoppingStore {
|
|
4
|
+
cartItems: CartItem[];
|
|
5
|
+
isProductInCart: boolean;
|
|
6
|
+
actions: {
|
|
7
|
+
addProductToCart: (val: Product) => void;
|
|
8
|
+
removeProductFromCart: (productId: number) => void;
|
|
9
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
10
|
+
checkProductInCart: (productId: number) => void;
|
|
11
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
12
|
+
resetAllProductsInCart: () => void;
|
|
13
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare const updateProductQtity: (cartItems: CartItem[], productId: number, updateType: "increase" | "decrease") => CartItem[];
|
|
17
|
+
export declare const updateProductSpePrice: (cartItems: CartItem[], productId: number, spePrice: number) => CartItem[];
|
|
18
|
+
export declare const increaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
19
|
+
export declare const removeProductFromCart: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
20
|
+
export declare const decreaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
21
|
+
export declare const useShoppingStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ShoppingStore>>;
|
|
22
|
+
export declare const useShoppingActions: () => {
|
|
23
|
+
addProductToCart: (val: Product) => void;
|
|
24
|
+
removeProductFromCart: (productId: number) => void;
|
|
25
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
26
|
+
checkProductInCart: (productId: number) => void;
|
|
27
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
28
|
+
resetAllProductsInCart: () => void;
|
|
29
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const useCartItems: () => CartItem[];
|
|
32
|
+
export declare const useCartItemsCount: () => number;
|
|
33
|
+
export declare const useCartItemQtityById: (productId: number | undefined) => number;
|
|
34
|
+
export declare const isInCart: (productId: number) => CartItem;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.isInCart = exports.useCartItemQtityById = exports.useCartItemsCount = exports.useCartItems = exports.useShoppingActions = exports.useShoppingStore = exports.decreaseCartItemQtity = exports.removeProductFromCart = exports.increaseCartItemQtity = exports.updateProductSpePrice = exports.updateProductQtity = void 0;
|
|
16
|
+
const zustand_1 = require("zustand");
|
|
17
|
+
const shallow_1 = require("zustand/react/shallow");
|
|
18
|
+
const hlpShopping_1 = __importDefault(require("./hlpShopping"));
|
|
19
|
+
const updateProductQtity = (cartItems, productId, updateType) => {
|
|
20
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
21
|
+
if (item.product.id === productId) {
|
|
22
|
+
return Object.assign(Object.assign({}, item), { qtityOdr: updateType === "increase" ? item.qtityOdr + 1 : item.qtityOdr - 1 });
|
|
23
|
+
}
|
|
24
|
+
return item;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.updateProductQtity = updateProductQtity;
|
|
28
|
+
const updateProductSpePrice = (cartItems, productId, spePrice) => {
|
|
29
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
30
|
+
if (item.product.id === productId) {
|
|
31
|
+
return Object.assign(Object.assign({}, item), { specialPrice: spePrice });
|
|
32
|
+
}
|
|
33
|
+
return item;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.updateProductSpePrice = updateProductSpePrice;
|
|
37
|
+
const checkProductInCart = (cartItems, productId) => {
|
|
38
|
+
return cartItems.find((x) => x.product.id === productId) ? true : false;
|
|
39
|
+
};
|
|
40
|
+
const increaseCartItemQtity = (cartItems, productId) => {
|
|
41
|
+
return (0, exports.updateProductQtity)(cartItems, productId, "increase");
|
|
42
|
+
};
|
|
43
|
+
exports.increaseCartItemQtity = increaseCartItemQtity;
|
|
44
|
+
const removeProductFromCart = (cartItems, productId) => {
|
|
45
|
+
return cartItems.filter((item) => item.product.id !== productId);
|
|
46
|
+
};
|
|
47
|
+
exports.removeProductFromCart = removeProductFromCart;
|
|
48
|
+
const decreaseCartItemQtity = (cartItems, productId) => {
|
|
49
|
+
var _a;
|
|
50
|
+
const ifQtity = ((_a = cartItems.find((x) => x.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr) === 1;
|
|
51
|
+
if (ifQtity) {
|
|
52
|
+
return (0, exports.removeProductFromCart)(cartItems, productId);
|
|
53
|
+
}
|
|
54
|
+
return (0, exports.updateProductQtity)(cartItems, productId, "decrease");
|
|
55
|
+
};
|
|
56
|
+
exports.decreaseCartItemQtity = decreaseCartItemQtity;
|
|
57
|
+
exports.useShoppingStore = (0, zustand_1.create)((set, get) => ({
|
|
58
|
+
cartItems: [],
|
|
59
|
+
isProductInCart: false,
|
|
60
|
+
actions: {
|
|
61
|
+
// addProductToCart: (product) =>
|
|
62
|
+
// set({
|
|
63
|
+
// cartItems: !get()?.cartItems?.find((x) => x.product.id === product.id)
|
|
64
|
+
// ? [...get()?.cartItems, { product: product, qtityOdr: 1 }]
|
|
65
|
+
// : increaseCartItemQtity([...get()?.cartItems], product?.id),
|
|
66
|
+
// }),
|
|
67
|
+
addProductToCart: (product) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
return set({
|
|
70
|
+
cartItems: yield hlpShopping_1.default.addToCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, product, 1),
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
increaseCartItemQtity: (productId) => {
|
|
74
|
+
var _a;
|
|
75
|
+
set({
|
|
76
|
+
cartItems: (0, exports.increaseCartItemQtity)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
decreaseCartItemQtity: (productId) => {
|
|
80
|
+
var _a;
|
|
81
|
+
set({
|
|
82
|
+
cartItems: (0, exports.decreaseCartItemQtity)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
updateSpePrice: (productId, price) => {
|
|
86
|
+
var _a;
|
|
87
|
+
set({
|
|
88
|
+
cartItems: (0, exports.updateProductSpePrice)((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId, price),
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
checkProductInCart: (productId) => {
|
|
92
|
+
var _a;
|
|
93
|
+
set({
|
|
94
|
+
isProductInCart: checkProductInCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
removeProductFromCart: (productId) => set({
|
|
98
|
+
cartItems: [...get().cartItems.filter((item) => item.product.id !== productId)],
|
|
99
|
+
}),
|
|
100
|
+
resetAllProductsInCart: () => set({ cartItems: [] }),
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
const useShoppingActions = () => (0, exports.useShoppingStore)((state) => state.actions);
|
|
104
|
+
exports.useShoppingActions = useShoppingActions;
|
|
105
|
+
const useCartItems = () => (0, exports.useShoppingStore)((0, shallow_1.useShallow)((state) => state.cartItems));
|
|
106
|
+
exports.useCartItems = useCartItems;
|
|
107
|
+
const useCartItemsCount = () => (0, exports.useShoppingStore)((state) => state.cartItems.length);
|
|
108
|
+
exports.useCartItemsCount = useCartItemsCount;
|
|
109
|
+
const useCartItemQtityById = (productId) => (0, exports.useShoppingStore)((state) => { var _a; return (_a = state.cartItems.find((item) => item.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr; });
|
|
110
|
+
exports.useCartItemQtityById = useCartItemQtityById;
|
|
111
|
+
const isInCart = (productId) => (0, exports.useCartItems)().find((x) => x.product.id === productId);
|
|
112
|
+
exports.isInCart = isInCart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SADM: string[];
|
|
2
|
+
export declare const CEO: string[];
|
|
3
|
+
export declare const ADM: string[];
|
|
4
|
+
export declare const COMPTA: string[];
|
|
5
|
+
export declare const CAISSE: string[];
|
|
6
|
+
export declare const COMPTA_CAISSE: string[];
|
|
7
|
+
export declare const TLM_COM: string[];
|
|
8
|
+
export declare const COM: string[];
|
|
9
|
+
export declare const RCM: string[];
|
|
10
|
+
export declare const CHA: string[];
|
|
11
|
+
export declare const SEC: string[];
|
|
12
|
+
export declare const VISITOR: string[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const SADM = ['sadm'];
|
|
2
|
+
export const CEO = ['ceo', ...SADM];
|
|
3
|
+
export const ADM = ['adm', ...CEO];
|
|
4
|
+
export const COMPTA = ['cpt', 'acp'];
|
|
5
|
+
export const CAISSE = ['cai', 'ceo', ...ADM];
|
|
6
|
+
export const COMPTA_CAISSE = ['cai', 'ceo', ...COMPTA, ...ADM];
|
|
7
|
+
export const TLM_COM = ['tlm', 'com', ...ADM];
|
|
8
|
+
export const COM = ['com', 'rcm'];
|
|
9
|
+
export const RCM = ['rcm'];
|
|
10
|
+
export const CHA = ['cha'];
|
|
11
|
+
export const SEC = ['sec'];
|
|
12
|
+
export const VISITOR = ['vip'];
|
|
@@ -4,7 +4,7 @@ import CartItem from "./models/CartItem";
|
|
|
4
4
|
declare class HlpShopping {
|
|
5
5
|
addToCart: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
6
6
|
updateCartQtity: (cartItems: CartItem[], product: Product, qtity: number) => Promise<CartItem[]>;
|
|
7
|
-
calculateStockOrQtityLimitCounts
|
|
7
|
+
private calculateStockOrQtityLimitCounts;
|
|
8
8
|
getTotalAmount: (cartItems: CartItem[], client: User) => number;
|
|
9
9
|
getPrice: (item: CartItem) => number;
|
|
10
10
|
getAddShopLabel: (marketCode: string, status?: "edit") => "Ajouter une agence" | "modifier l'agence" | "Ajouter un shop" | "Modifier le shop";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Product from "../products/models/Product";
|
|
2
|
+
import CartItem from "./models/CartItem";
|
|
3
|
+
export interface ShoppingStore {
|
|
4
|
+
cartItems: CartItem[];
|
|
5
|
+
isProductInCart: boolean;
|
|
6
|
+
actions: {
|
|
7
|
+
addProductToCart: (val: Product) => void;
|
|
8
|
+
removeProductFromCart: (productId: number) => void;
|
|
9
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
10
|
+
checkProductInCart: (productId: number) => void;
|
|
11
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
12
|
+
resetAllProductsInCart: () => void;
|
|
13
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare const updateProductQtity: (cartItems: CartItem[], productId: number, updateType: "increase" | "decrease") => CartItem[];
|
|
17
|
+
export declare const updateProductSpePrice: (cartItems: CartItem[], productId: number, spePrice: number) => CartItem[];
|
|
18
|
+
export declare const increaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
19
|
+
export declare const removeProductFromCart: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
20
|
+
export declare const decreaseCartItemQtity: (cartItems: CartItem[], productId: number) => CartItem[];
|
|
21
|
+
export declare const useShoppingStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ShoppingStore>>;
|
|
22
|
+
export declare const useShoppingActions: () => {
|
|
23
|
+
addProductToCart: (val: Product) => void;
|
|
24
|
+
removeProductFromCart: (productId: number) => void;
|
|
25
|
+
increaseCartItemQtity: (productId: number) => void;
|
|
26
|
+
checkProductInCart: (productId: number) => void;
|
|
27
|
+
decreaseCartItemQtity: (productId: number) => void;
|
|
28
|
+
resetAllProductsInCart: () => void;
|
|
29
|
+
updateSpePrice: (productId: number, price: number) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare const useCartItems: () => CartItem[];
|
|
32
|
+
export declare const useCartItemsCount: () => number;
|
|
33
|
+
export declare const useCartItemQtityById: (productId: number | undefined) => number;
|
|
34
|
+
export declare const isInCart: (productId: number) => CartItem;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { create } from "zustand";
|
|
11
|
+
import { useShallow } from "zustand/react/shallow";
|
|
12
|
+
import hlpShopping from "./hlpShopping";
|
|
13
|
+
export const updateProductQtity = (cartItems, productId, updateType) => {
|
|
14
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
15
|
+
if (item.product.id === productId) {
|
|
16
|
+
return Object.assign(Object.assign({}, item), { qtityOdr: updateType === "increase" ? item.qtityOdr + 1 : item.qtityOdr - 1 });
|
|
17
|
+
}
|
|
18
|
+
return item;
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const updateProductSpePrice = (cartItems, productId, spePrice) => {
|
|
22
|
+
return cartItems === null || cartItems === void 0 ? void 0 : cartItems.map((item) => {
|
|
23
|
+
if (item.product.id === productId) {
|
|
24
|
+
return Object.assign(Object.assign({}, item), { specialPrice: spePrice });
|
|
25
|
+
}
|
|
26
|
+
return item;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const checkProductInCart = (cartItems, productId) => {
|
|
30
|
+
return cartItems.find((x) => x.product.id === productId) ? true : false;
|
|
31
|
+
};
|
|
32
|
+
export const increaseCartItemQtity = (cartItems, productId) => {
|
|
33
|
+
return updateProductQtity(cartItems, productId, "increase");
|
|
34
|
+
};
|
|
35
|
+
export const removeProductFromCart = (cartItems, productId) => {
|
|
36
|
+
return cartItems.filter((item) => item.product.id !== productId);
|
|
37
|
+
};
|
|
38
|
+
export const decreaseCartItemQtity = (cartItems, productId) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const ifQtity = ((_a = cartItems.find((x) => x.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr) === 1;
|
|
41
|
+
if (ifQtity) {
|
|
42
|
+
return removeProductFromCart(cartItems, productId);
|
|
43
|
+
}
|
|
44
|
+
return updateProductQtity(cartItems, productId, "decrease");
|
|
45
|
+
};
|
|
46
|
+
export const useShoppingStore = create((set, get) => ({
|
|
47
|
+
cartItems: [],
|
|
48
|
+
isProductInCart: false,
|
|
49
|
+
actions: {
|
|
50
|
+
// addProductToCart: (product) =>
|
|
51
|
+
// set({
|
|
52
|
+
// cartItems: !get()?.cartItems?.find((x) => x.product.id === product.id)
|
|
53
|
+
// ? [...get()?.cartItems, { product: product, qtityOdr: 1 }]
|
|
54
|
+
// : increaseCartItemQtity([...get()?.cartItems], product?.id),
|
|
55
|
+
// }),
|
|
56
|
+
addProductToCart: (product) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
return set({
|
|
59
|
+
cartItems: yield hlpShopping.addToCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, product, 1),
|
|
60
|
+
});
|
|
61
|
+
}),
|
|
62
|
+
increaseCartItemQtity: (productId) => {
|
|
63
|
+
var _a;
|
|
64
|
+
set({
|
|
65
|
+
cartItems: increaseCartItemQtity((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
decreaseCartItemQtity: (productId) => {
|
|
69
|
+
var _a;
|
|
70
|
+
set({
|
|
71
|
+
cartItems: decreaseCartItemQtity((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
updateSpePrice: (productId, price) => {
|
|
75
|
+
var _a;
|
|
76
|
+
set({
|
|
77
|
+
cartItems: updateProductSpePrice((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId, price),
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
checkProductInCart: (productId) => {
|
|
81
|
+
var _a;
|
|
82
|
+
set({
|
|
83
|
+
isProductInCart: checkProductInCart((_a = get()) === null || _a === void 0 ? void 0 : _a.cartItems, productId),
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
removeProductFromCart: (productId) => set({
|
|
87
|
+
cartItems: [...get().cartItems.filter((item) => item.product.id !== productId)],
|
|
88
|
+
}),
|
|
89
|
+
resetAllProductsInCart: () => set({ cartItems: [] }),
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
export const useShoppingActions = () => useShoppingStore((state) => state.actions);
|
|
93
|
+
export const useCartItems = () => useShoppingStore(useShallow((state) => state.cartItems));
|
|
94
|
+
export const useCartItemsCount = () => useShoppingStore((state) => state.cartItems.length);
|
|
95
|
+
export const useCartItemQtityById = (productId) => useShoppingStore((state) => { var _a; return (_a = state.cartItems.find((item) => item.product.id === productId)) === null || _a === void 0 ? void 0 : _a.qtityOdr; });
|
|
96
|
+
export const isInCart = (productId) => useCartItems().find((x) => x.product.id === productId);
|