addio-ecomm-sdk 1.3.76 → 1.3.78
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/dist/index.js +1066 -1647
- package/dist/index.js.map +1 -1
- package/dist/lib/constants/components/CreditCardInput.js +22 -36
- package/dist/lib/constants/components/CreditCardInput.js.map +1 -1
- package/dist/lib/constants/components/Snackbar.js +10 -20
- package/dist/lib/constants/components/Snackbar.js.map +1 -1
- package/dist/lib/constants/contexts/CartContext/CartContextProvider.js +566 -906
- package/dist/lib/constants/contexts/CartContext/CartContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/CartContext/index.js +34 -114
- package/dist/lib/constants/contexts/CartContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/DataContext/DataContextProvider.js +103 -234
- package/dist/lib/constants/contexts/DataContext/DataContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/DataContext/index.js +22 -62
- package/dist/lib/constants/contexts/DataContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/LogContext/LogContextProvider.js +24 -87
- package/dist/lib/constants/contexts/LogContext/LogContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/LogContext/index.js +4 -42
- package/dist/lib/constants/contexts/LogContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.js +16 -31
- package/dist/lib/constants/contexts/ModalContext/ModalContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/ModalContext/index.js +11 -13
- package/dist/lib/constants/contexts/ModalContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/SDKContext/SDKProvider.js +14 -70
- package/dist/lib/constants/contexts/SDKContext/SDKProvider.js.map +1 -1
- package/dist/lib/constants/contexts/SDKContext/index.js +1 -1
- package/dist/lib/constants/contexts/SDKContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.js +3 -3
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContext.js.map +1 -1
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.js +17 -31
- package/dist/lib/constants/contexts/SnackbarContext/SnackbarContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.d.ts +2 -0
- package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.js +2 -2
- package/dist/lib/constants/contexts/SnackbarContext/interfaces/ISnackbarContext.js.map +1 -1
- package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.js +51 -118
- package/dist/lib/constants/contexts/StockNotifContext/StockNotifContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/StockNotifContext/index.js +3 -3
- package/dist/lib/constants/contexts/StockNotifContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/UserContext/UserContextProvider.js +240 -397
- package/dist/lib/constants/contexts/UserContext/UserContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/UserContext/index.js +15 -69
- package/dist/lib/constants/contexts/UserContext/index.js.map +1 -1
- package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.js +157 -253
- package/dist/lib/constants/contexts/WishlistContext/WishlistContextProvider.js.map +1 -1
- package/dist/lib/constants/contexts/WishlistContext/index.js +4 -4
- package/dist/lib/constants/contexts/WishlistContext/index.js.map +1 -1
- package/dist/lib/constants/hooks/useCart.js +3 -3
- package/dist/lib/constants/hooks/useCart.js.map +1 -1
- package/dist/lib/constants/hooks/useData.js +3 -3
- package/dist/lib/constants/hooks/useData.js.map +1 -1
- package/dist/lib/constants/hooks/useLogs.js +3 -3
- package/dist/lib/constants/hooks/useLogs.js.map +1 -1
- package/dist/lib/constants/hooks/useModal.js +3 -3
- package/dist/lib/constants/hooks/useModal.js.map +1 -1
- package/dist/lib/constants/hooks/useSDK.js +3 -3
- package/dist/lib/constants/hooks/useSDK.js.map +1 -1
- package/dist/lib/constants/hooks/useSnackbar.js +3 -3
- package/dist/lib/constants/hooks/useSnackbar.js.map +1 -1
- package/dist/lib/constants/hooks/useStockNotif.js +3 -3
- package/dist/lib/constants/hooks/useStockNotif.js.map +1 -1
- package/dist/lib/constants/hooks/useUser.js +3 -3
- package/dist/lib/constants/hooks/useUser.js.map +1 -1
- package/dist/lib/constants/hooks/useWishlist.js +3 -3
- package/dist/lib/constants/hooks/useWishlist.js.map +1 -1
- package/dist/lib/models/image/index.js +5 -10
- package/dist/lib/models/image/index.js.map +1 -1
- package/dist/lib/models/stockNotification/index.js +58 -118
- package/dist/lib/models/stockNotification/index.js.map +1 -1
- package/dist/lib/models/wishlist/index.js +73 -142
- package/dist/lib/models/wishlist/index.js.map +1 -1
- package/dist/utils/algolia.js +27 -73
- package/dist/utils/algolia.js.map +1 -1
- package/dist/utils/analytics.js +68 -79
- package/dist/utils/analytics.js.map +1 -1
- package/dist/utils/cart.js +10 -11
- package/dist/utils/cart.js.map +1 -1
- package/dist/utils/contentful.js +31 -104
- package/dist/utils/contentful.js.map +1 -1
- package/dist/utils/functions.js +54 -71
- package/dist/utils/functions.js.map +1 -1
- package/dist/utils/getSDK.js +12 -70
- package/dist/utils/getSDK.js.map +1 -1
- package/dist/utils/initStoreData.js +12 -57
- package/dist/utils/initStoreData.js.map +1 -1
- package/dist/utils/larivieremeunier.js +1 -1
- package/dist/utils/larivieremeunier.js.map +1 -1
- package/dist/utils/technosupply.js +1 -1
- package/dist/utils/technosupply.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,331 +22,205 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
27
|
};
|
|
75
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
switch (_a.label) {
|
|
171
|
-
case 0:
|
|
172
|
-
if (!!!sdk)
|
|
173
|
-
return [2, 'sdk_not_defined'];
|
|
174
|
-
_a.label = 1;
|
|
175
|
-
case 1:
|
|
176
|
-
_a.trys.push([1, 3, , 4]);
|
|
177
|
-
return [4, sdk.user.getOrder(orderID, token)];
|
|
178
|
-
case 2:
|
|
179
|
-
order = _a.sent();
|
|
180
|
-
return [2, order];
|
|
181
|
-
case 3:
|
|
182
|
-
err_1 = _a.sent();
|
|
183
|
-
return [2, 'error'];
|
|
184
|
-
case 4: return [2];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}); };
|
|
188
|
-
var changePassword = function (currentPassword, newPassword) { return __awaiter(void 0, void 0, void 0, function () {
|
|
189
|
-
var err_2;
|
|
190
|
-
return __generator(this, function (_a) {
|
|
191
|
-
switch (_a.label) {
|
|
192
|
-
case 0:
|
|
193
|
-
if (!!!sdk)
|
|
194
|
-
return [2, 'sdk_not_defined'];
|
|
195
|
-
_a.label = 1;
|
|
196
|
-
case 1:
|
|
197
|
-
_a.trys.push([1, 3, , 4]);
|
|
198
|
-
return [4, sdk.user.changePassword(currentPassword, newPassword)];
|
|
199
|
-
case 2: return [2, _a.sent()];
|
|
200
|
-
case 3:
|
|
201
|
-
err_2 = _a.sent();
|
|
202
|
-
return [2, err_2];
|
|
203
|
-
case 4: return [2];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}); };
|
|
207
|
-
var changeProfilePicture = function (base64) { return __awaiter(void 0, void 0, void 0, function () {
|
|
208
|
-
var upload_1, err_3;
|
|
209
|
-
return __generator(this, function (_a) {
|
|
210
|
-
switch (_a.label) {
|
|
211
|
-
case 0:
|
|
212
|
-
if (!!!sdk)
|
|
213
|
-
return [2, 'sdk_not_defined'];
|
|
214
|
-
_a.label = 1;
|
|
215
|
-
case 1:
|
|
216
|
-
_a.trys.push([1, 3, , 4]);
|
|
217
|
-
return [4, sdk.user.changeProfilePicture(base64)];
|
|
218
|
-
case 2:
|
|
219
|
-
upload_1 = _a.sent();
|
|
220
|
-
setState(function (prevState) {
|
|
221
|
-
if (prevState.userData) {
|
|
222
|
-
return __assign(__assign({}, prevState), { userData: __assign(__assign({}, prevState.userData), { basic_info: __assign(__assign({}, prevState.userData.basic_info), { customer_image: upload_1 === "Can't upload image." || upload_1 === 'done' ? undefined : upload_1 }) }) });
|
|
223
|
-
}
|
|
224
|
-
return prevState;
|
|
225
|
-
});
|
|
226
|
-
return [2, upload_1];
|
|
227
|
-
case 3:
|
|
228
|
-
err_3 = _a.sent();
|
|
229
|
-
return [2, err_3];
|
|
230
|
-
case 4: return [2];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}); };
|
|
234
|
-
var setCustomPriceList = function (list) {
|
|
235
|
-
setState(function (prevState) { return (__assign(__assign({}, prevState), { customPriceList: list, fetchCustomPrices: false })); });
|
|
29
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
|
+
const react_1 = require("react");
|
|
31
|
+
const index_1 = __importStar(require("./index"));
|
|
32
|
+
const useSDK_1 = __importDefault(require("../../hooks/useSDK"));
|
|
33
|
+
const moment_1 = __importDefault(require("moment"));
|
|
34
|
+
const functions_1 = require("../../../../utils/functions");
|
|
35
|
+
const UserContextProvider = ({ children }) => {
|
|
36
|
+
const sdk = (0, useSDK_1.default)();
|
|
37
|
+
const setUserLoggedIn = async (userData) => {
|
|
38
|
+
const isPro = !!userData.basic_info.customer_professionnal_info &&
|
|
39
|
+
!!userData.basic_info.customer_professionnal_info.proof_doc_value;
|
|
40
|
+
localStorage.setItem('userLogged', 'true');
|
|
41
|
+
if (!!isPro) {
|
|
42
|
+
localStorage.setItem('isPro', 'true');
|
|
43
|
+
}
|
|
44
|
+
const isClerk = localStorage.getItem('isClerk');
|
|
45
|
+
if (typeof window !== 'undefined' && !!isClerk) {
|
|
46
|
+
window.addEventListener('beforeunload', async (e) => {
|
|
47
|
+
if (!!!userData.temp_hash)
|
|
48
|
+
return;
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
const dialogText = '';
|
|
51
|
+
e.returnValue = dialogText;
|
|
52
|
+
return dialogText;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { isUserLoggedIn: true, userData: userData })));
|
|
56
|
+
};
|
|
57
|
+
const setUserLoggedOut = async (keepRepCart) => {
|
|
58
|
+
if (!!!sdk)
|
|
59
|
+
return;
|
|
60
|
+
if (!!state.userData && state.userData.temp_hash && !!!keepRepCart) {
|
|
61
|
+
await sdk.user.killRepCart(state.userData.temp_hash);
|
|
62
|
+
}
|
|
63
|
+
sdk.user.logout();
|
|
64
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { isUserLoggedIn: false, isPro: false, customPriceList: undefined, userData: null, resetUserData: true })));
|
|
65
|
+
};
|
|
66
|
+
const setUserPreferedStore = async (storeId) => {
|
|
67
|
+
if (!!!state.userData)
|
|
68
|
+
return;
|
|
69
|
+
await saveUser(Object.assign(Object.assign({}, state.userData), { prefered_store: storeId }));
|
|
70
|
+
};
|
|
71
|
+
const saveUser = async (customer) => {
|
|
72
|
+
if (!!!sdk)
|
|
73
|
+
return false;
|
|
74
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { userData: customer, isPro: !!customer.basic_info.customer_professionnal_info &&
|
|
75
|
+
!!customer.basic_info.customer_professionnal_info.professionnal_title })));
|
|
76
|
+
return await sdk.user.saveUser(customer);
|
|
77
|
+
};
|
|
78
|
+
const deleteUser = async () => {
|
|
79
|
+
if (!!!sdk)
|
|
80
|
+
return false;
|
|
81
|
+
return await sdk.user.deleteUser();
|
|
82
|
+
};
|
|
83
|
+
const getOrder = async (orderID, token) => {
|
|
84
|
+
if (!!!sdk)
|
|
85
|
+
return 'sdk_not_defined';
|
|
86
|
+
try {
|
|
87
|
+
const order = await sdk.user.getOrder(orderID, token);
|
|
88
|
+
return order;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
return 'error';
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const changePassword = async (currentPassword, newPassword) => {
|
|
95
|
+
if (!!!sdk)
|
|
96
|
+
return 'sdk_not_defined';
|
|
97
|
+
try {
|
|
98
|
+
return await sdk.user.changePassword(currentPassword, newPassword);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
return err;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const changeProfilePicture = async (base64) => {
|
|
105
|
+
if (!!!sdk)
|
|
106
|
+
return 'sdk_not_defined';
|
|
107
|
+
try {
|
|
108
|
+
const upload = await sdk.user.changeProfilePicture(base64);
|
|
109
|
+
setState((prevState) => {
|
|
110
|
+
if (prevState.userData) {
|
|
111
|
+
return Object.assign(Object.assign({}, prevState), { userData: Object.assign(Object.assign({}, prevState.userData), { basic_info: Object.assign(Object.assign({}, prevState.userData.basic_info), { customer_image: upload === "Can't upload image." || upload === 'done' ? undefined : upload }) }) });
|
|
112
|
+
}
|
|
113
|
+
return prevState;
|
|
114
|
+
});
|
|
115
|
+
return upload;
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
return err;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const setCustomPriceList = (list) => {
|
|
122
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { customPriceList: list, fetchCustomPrices: false })));
|
|
236
123
|
localStorage.setItem('customPriceList', JSON.stringify(list));
|
|
237
124
|
localStorage.setItem('lastCustomPriceFetch', (0, moment_1.default)().format('YYYY-MM-DD'));
|
|
238
125
|
};
|
|
239
|
-
|
|
240
|
-
setState(
|
|
126
|
+
const setLoaded = (value) => {
|
|
127
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { loaded: value })));
|
|
241
128
|
};
|
|
242
|
-
|
|
243
|
-
(0, react_1.useEffect)(
|
|
129
|
+
const [state, setState] = (0, react_1.useState)((0, index_1.getDefaultUserContext)());
|
|
130
|
+
(0, react_1.useEffect)(() => {
|
|
244
131
|
if (!!!sdk)
|
|
245
132
|
return;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
133
|
+
const userLoggedData = localStorage.getItem('userLogged');
|
|
134
|
+
const userIsPro = localStorage.getItem('isPro');
|
|
135
|
+
const isClerk = localStorage.getItem('isClerk');
|
|
136
|
+
const isLoggedIn = !!userLoggedData && JSON.parse(userLoggedData);
|
|
137
|
+
const isPro = !!userLoggedData && !!userIsPro && JSON.parse(userIsPro);
|
|
138
|
+
let newState = Object.assign({ isUserLoggedIn: !!!isClerk && !!isLoggedIn, isPro: !!!isClerk && !!isPro }, checkForCustomPriceList(!!userIsPro));
|
|
252
139
|
if (!!isClerk) {
|
|
253
140
|
localStorage.removeItem('isClerk');
|
|
254
141
|
}
|
|
255
|
-
return setState(
|
|
142
|
+
return setState((prevState) => (Object.assign(Object.assign(Object.assign({}, prevState), newState), { loaded: true })));
|
|
256
143
|
}, [sdk]);
|
|
257
|
-
(0, react_1.useEffect)(
|
|
144
|
+
(0, react_1.useEffect)(() => {
|
|
258
145
|
if (!!!state.fetchCustomPrices || !!!state.isPro || !!!state.userData || !!!sdk)
|
|
259
146
|
return;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
_a.label = 1;
|
|
269
|
-
case 1:
|
|
270
|
-
_a.trys.push([1, 3, , 4]);
|
|
271
|
-
return [4, sdk.user.fetchCustomPriceList(proUser)];
|
|
272
|
-
case 2:
|
|
273
|
-
newList = _a.sent();
|
|
274
|
-
if (!!newList) {
|
|
275
|
-
setCustomPriceList(newList);
|
|
276
|
-
}
|
|
277
|
-
return [3, 4];
|
|
278
|
-
case 3:
|
|
279
|
-
e_1 = _a.sent();
|
|
280
|
-
console.log('error on fetching customPrices from G2: ', e_1.toString());
|
|
281
|
-
setState(function (prevState) { return (__assign(__assign({}, prevState), { fetchCustomPrices: false, customPriceList: undefined })); });
|
|
282
|
-
return [3, 4];
|
|
283
|
-
case 4: return [2];
|
|
147
|
+
const fetchCustomPrices = async () => {
|
|
148
|
+
const proUser = !!state.userData && !!state.isPro ? state.userData.id : '';
|
|
149
|
+
if (!!!proUser)
|
|
150
|
+
return;
|
|
151
|
+
try {
|
|
152
|
+
const newList = await sdk.user.fetchCustomPriceList(proUser);
|
|
153
|
+
if (!!newList) {
|
|
154
|
+
setCustomPriceList(newList);
|
|
284
155
|
}
|
|
285
|
-
}
|
|
286
|
-
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
console.log('error on fetching customPrices from G2: ', e.toString());
|
|
159
|
+
setState((prevState) => (Object.assign(Object.assign({}, prevState), { fetchCustomPrices: false, customPriceList: undefined })));
|
|
160
|
+
}
|
|
161
|
+
};
|
|
287
162
|
fetchCustomPrices();
|
|
288
163
|
}, [sdk, state.fetchCustomPrices, state.isPro, state.userData]);
|
|
289
|
-
(0, react_1.useEffect)(
|
|
164
|
+
(0, react_1.useEffect)(() => {
|
|
290
165
|
if (!!!sdk)
|
|
291
166
|
return;
|
|
292
167
|
if (!state.isUserLoggedIn) {
|
|
293
168
|
return;
|
|
294
169
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
localStorage.removeItem('lastCustomPriceFetch');
|
|
310
|
-
}
|
|
311
|
-
return [2, setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { userData: null, isPro: false }), (!!prevState.customPriceList
|
|
312
|
-
? {
|
|
313
|
-
customPriceList: undefined
|
|
314
|
-
}
|
|
315
|
-
: {}))); })];
|
|
316
|
-
}
|
|
317
|
-
checkIsPro_1 = !!user.basic_info.customer_professionnal_info &&
|
|
318
|
-
!!user.basic_info.customer_professionnal_info.professionnal_title;
|
|
319
|
-
setState(function (prevState) { return (__assign(__assign(__assign({}, prevState), { userData: user, isPro: checkIsPro_1 }), checkForCustomPriceList(checkIsPro_1))); });
|
|
320
|
-
localStorage.setItem('isPro', JSON.stringify(checkIsPro_1));
|
|
321
|
-
if (!!!checkIsPro_1) {
|
|
322
|
-
localStorage.removeItem('foundInG2');
|
|
323
|
-
if (!!localStorage.getItem('customPriceList')) {
|
|
324
|
-
localStorage.removeItem('customPriceList');
|
|
325
|
-
localStorage.removeItem('lastCustomPriceFetch');
|
|
326
|
-
}
|
|
170
|
+
const getContent = async () => {
|
|
171
|
+
let user;
|
|
172
|
+
try {
|
|
173
|
+
user = (await sdk.user.getUser(!!localStorage.getItem('isClerk')));
|
|
174
|
+
if (!!!user) {
|
|
175
|
+
localStorage.setItem('isPro', JSON.stringify(false));
|
|
176
|
+
localStorage.removeItem('foundInG2');
|
|
177
|
+
if (!!localStorage.getItem('customPriceList')) {
|
|
178
|
+
localStorage.removeItem('customPriceList');
|
|
179
|
+
localStorage.removeItem('lastCustomPriceFetch');
|
|
180
|
+
}
|
|
181
|
+
return setState((prevState) => (Object.assign(Object.assign(Object.assign({}, prevState), { userData: null, isPro: false }), (!!prevState.customPriceList
|
|
182
|
+
? {
|
|
183
|
+
customPriceList: undefined
|
|
327
184
|
}
|
|
328
|
-
|
|
329
|
-
case 2:
|
|
330
|
-
err_4 = _a.sent();
|
|
331
|
-
if (!!!err_4.message) return [3, 4];
|
|
332
|
-
error = JSON.parse(err_4.message);
|
|
333
|
-
if (!(!!error && !!error.error)) return [3, 4];
|
|
334
|
-
return [4, setUserLoggedOut()];
|
|
335
|
-
case 3:
|
|
336
|
-
_a.sent();
|
|
337
|
-
_a.label = 4;
|
|
338
|
-
case 4: return [3, 5];
|
|
339
|
-
case 5: return [2];
|
|
185
|
+
: {}))));
|
|
340
186
|
}
|
|
341
|
-
|
|
342
|
-
|
|
187
|
+
const checkIsPro = !!user.basic_info.customer_professionnal_info &&
|
|
188
|
+
!!user.basic_info.customer_professionnal_info.professionnal_title;
|
|
189
|
+
setState((prevState) => (Object.assign(Object.assign(Object.assign({}, prevState), { userData: user, isPro: checkIsPro }), checkForCustomPriceList(checkIsPro))));
|
|
190
|
+
localStorage.setItem('isPro', JSON.stringify(checkIsPro));
|
|
191
|
+
if (!!!checkIsPro) {
|
|
192
|
+
localStorage.removeItem('foundInG2');
|
|
193
|
+
if (!!localStorage.getItem('customPriceList')) {
|
|
194
|
+
localStorage.removeItem('customPriceList');
|
|
195
|
+
localStorage.removeItem('lastCustomPriceFetch');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
if (!!err.message) {
|
|
201
|
+
const error = JSON.parse(err.message);
|
|
202
|
+
if (!!error && !!error.error) {
|
|
203
|
+
await setUserLoggedOut();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
343
208
|
getContent();
|
|
344
209
|
}, [sdk, state.isUserLoggedIn]);
|
|
345
|
-
(0, react_1.useEffect)(
|
|
346
|
-
return
|
|
210
|
+
(0, react_1.useEffect)(() => {
|
|
211
|
+
return () => {
|
|
347
212
|
if (typeof window !== 'undefined') {
|
|
348
|
-
window.removeEventListener('onbeforeunload',
|
|
349
|
-
return [2];
|
|
350
|
-
}); }); });
|
|
213
|
+
window.removeEventListener('onbeforeunload', async () => { });
|
|
351
214
|
}
|
|
352
215
|
};
|
|
353
216
|
}, []);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
217
|
+
const checkForCustomPriceList = (userIsPro) => {
|
|
218
|
+
const hasCustomPriceList = !!userIsPro && localStorage.getItem('customPriceList');
|
|
219
|
+
const lastCustomPriceFetch = !!userIsPro && localStorage.getItem('lastCustomPriceFetch');
|
|
220
|
+
const foundProInG2 = !!userIsPro && localStorage.getItem('foundInG2');
|
|
221
|
+
const lastFetchWasBefore = !!userIsPro &&
|
|
359
222
|
(!!!lastCustomPriceFetch || (!!lastCustomPriceFetch && (0, moment_1.default)().isAfter((0, moment_1.default)(lastCustomPriceFetch), 'day')));
|
|
360
|
-
|
|
223
|
+
let parsedJSONCustomPrices = [];
|
|
361
224
|
if (!!hasCustomPriceList) {
|
|
362
225
|
try {
|
|
363
226
|
parsedJSONCustomPrices = JSON.parse(hasCustomPriceList);
|
|
@@ -366,106 +229,86 @@ var UserContextProvider = function (_a) {
|
|
|
366
229
|
console.log(e.toString());
|
|
367
230
|
}
|
|
368
231
|
}
|
|
369
|
-
return
|
|
232
|
+
return Object.assign(Object.assign({}, (!!!lastFetchWasBefore && !!foundProInG2
|
|
370
233
|
? { customPriceList: parsedJSONCustomPrices }
|
|
371
234
|
: { customPriceList: undefined })), (!!lastFetchWasBefore && !!foundProInG2 ? { fetchCustomPrices: true } : {}));
|
|
372
235
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
'Content-Type': 'application/json',
|
|
406
|
-
'x-gng-ecomm-token': api.userToken
|
|
407
|
-
},
|
|
408
|
-
body: !!body ? JSON.stringify(body) : undefined
|
|
409
|
-
})];
|
|
410
|
-
case 1:
|
|
411
|
-
requestHistory = _a.sent();
|
|
412
|
-
return [4, requestHistory.json()];
|
|
413
|
-
case 2:
|
|
414
|
-
responseData = _a.sent();
|
|
415
|
-
if (responseData.status !== 200) {
|
|
416
|
-
errorStr = !!!responseData.error
|
|
417
|
-
? ''
|
|
418
|
-
: typeof responseData.error === 'string'
|
|
419
|
-
? responseData.error
|
|
420
|
-
: (0, functions_1.getStringByLang)(responseData.error, 'fr');
|
|
421
|
-
throw new Error('Error on history fetch: ' + errorStr);
|
|
422
|
-
}
|
|
423
|
-
return [2, responseData.data.history];
|
|
424
|
-
}
|
|
236
|
+
const getPromiseToPurchaseHistory = async (userId, filters) => {
|
|
237
|
+
if (!state.isPro)
|
|
238
|
+
throw new Error('Only the PRO users have a promise to purchase');
|
|
239
|
+
const api = !!sdk ? sdk.getAPIInfos() : null;
|
|
240
|
+
if (!!!api)
|
|
241
|
+
return;
|
|
242
|
+
if (!!!userId) {
|
|
243
|
+
if (!!state.userData && !!state.userData.id)
|
|
244
|
+
userId = state.userData.id;
|
|
245
|
+
else
|
|
246
|
+
throw new Error("Can't get user promise to purchase without userId");
|
|
247
|
+
}
|
|
248
|
+
let body = undefined;
|
|
249
|
+
if (!!filters) {
|
|
250
|
+
body = Object.assign(Object.assign({}, (!!filters.bankTypeId
|
|
251
|
+
? {
|
|
252
|
+
bank_type_id: filters.bankTypeId
|
|
253
|
+
}
|
|
254
|
+
: {})), (!!filters.unixDateRange
|
|
255
|
+
? {
|
|
256
|
+
unix_date_range: filters.unixDateRange
|
|
257
|
+
}
|
|
258
|
+
: {}));
|
|
259
|
+
}
|
|
260
|
+
const requestHistory = await fetch(`${api.api}/users/${userId}/promisestopurchase/history`, {
|
|
261
|
+
method: 'POST',
|
|
262
|
+
headers: {
|
|
263
|
+
Authorization: `Bearer ${api.token}`,
|
|
264
|
+
'Content-Type': 'application/json',
|
|
265
|
+
'x-gng-ecomm-token': api.userToken
|
|
266
|
+
},
|
|
267
|
+
body: !!body ? JSON.stringify(body) : undefined
|
|
425
268
|
});
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
responseData = _a.sent();
|
|
456
|
-
if (responseData.status !== 200) {
|
|
457
|
-
errorStr = !!!responseData.error
|
|
458
|
-
? ''
|
|
459
|
-
: typeof responseData.error === 'string'
|
|
460
|
-
? responseData.error
|
|
461
|
-
: (0, functions_1.getStringByLang)(responseData.error, 'fr');
|
|
462
|
-
throw new Error('Error on remainingAmounts fetch: ' + errorStr);
|
|
463
|
-
}
|
|
464
|
-
return [2, responseData.data.availableAmountsForBanks];
|
|
269
|
+
const responseData = await requestHistory.json();
|
|
270
|
+
if (responseData.status !== 200) {
|
|
271
|
+
const errorStr = !!!responseData.error
|
|
272
|
+
? ''
|
|
273
|
+
: typeof responseData.error === 'string'
|
|
274
|
+
? responseData.error
|
|
275
|
+
: (0, functions_1.getStringByLang)(responseData.error, 'fr');
|
|
276
|
+
throw new Error('Error on history fetch: ' + errorStr);
|
|
277
|
+
}
|
|
278
|
+
return responseData.data.history;
|
|
279
|
+
};
|
|
280
|
+
const getPromiseToPurchaseRemainingAmounts = async (userId) => {
|
|
281
|
+
if (!state.isPro)
|
|
282
|
+
throw new Error('Only the PRO users have a promise to purchase');
|
|
283
|
+
const api = !!sdk ? sdk.getAPIInfos() : null;
|
|
284
|
+
if (!!!api)
|
|
285
|
+
return;
|
|
286
|
+
if (!!!userId) {
|
|
287
|
+
if (!!state.userData && !!state.userData.id)
|
|
288
|
+
userId = state.userData.id;
|
|
289
|
+
else
|
|
290
|
+
throw new Error("Can't get remaining amounts for user without userId");
|
|
291
|
+
}
|
|
292
|
+
const requestHistory = await fetch(`${api.api}/users/${userId}/promisestopurchase/remainingAmounts`, {
|
|
293
|
+
method: 'GET',
|
|
294
|
+
headers: {
|
|
295
|
+
Authorization: `Bearer ${api.token}`,
|
|
296
|
+
'Content-Type': 'application/json',
|
|
297
|
+
'x-gng-ecomm-token': api.userToken
|
|
465
298
|
}
|
|
466
299
|
});
|
|
467
|
-
|
|
468
|
-
|
|
300
|
+
const responseData = await requestHistory.json();
|
|
301
|
+
if (responseData.status !== 200) {
|
|
302
|
+
const errorStr = !!!responseData.error
|
|
303
|
+
? ''
|
|
304
|
+
: typeof responseData.error === 'string'
|
|
305
|
+
? responseData.error
|
|
306
|
+
: (0, functions_1.getStringByLang)(responseData.error, 'fr');
|
|
307
|
+
throw new Error('Error on remainingAmounts fetch: ' + errorStr);
|
|
308
|
+
}
|
|
309
|
+
return responseData.data.availableAmountsForBanks;
|
|
310
|
+
};
|
|
311
|
+
return ((0, jsx_runtime_1.jsx)(index_1.default.Provider, Object.assign({ value: Object.assign(Object.assign({}, state), { setLoaded: setLoaded, setUserLoggedIn: setUserLoggedIn, setUserLoggedOut: setUserLoggedOut, saveUser: saveUser, deleteUser: deleteUser, getOrder: getOrder, changePassword: changePassword, changeProfilePicture: changeProfilePicture, setUserPreferedStore: setUserPreferedStore, setCustomPriceList: setCustomPriceList, getPromiseToPurchaseHistory: getPromiseToPurchaseHistory, getPromiseToPurchaseRemainingAmounts: getPromiseToPurchaseRemainingAmounts }) }, { children: children })));
|
|
469
312
|
};
|
|
470
313
|
exports.default = UserContextProvider;
|
|
471
314
|
//# sourceMappingURL=UserContextProvider.js.map
|