@fctc/interface-logic 1.7.5 → 1.7.7

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.
@@ -1,3 +1,623 @@
1
+ // src/store/index.ts
2
+ import { useDispatch, useSelector } from "react-redux";
3
+
4
+ // src/store/reducers/breadcrums-slice/index.ts
5
+ import { createSlice } from "@reduxjs/toolkit";
6
+ var initialState = {
7
+ breadCrumbs: []
8
+ };
9
+ var breadcrumbsSlice = createSlice({
10
+ name: "breadcrumbs",
11
+ initialState,
12
+ reducers: {
13
+ setBreadCrumbs: (state, action) => {
14
+ state.breadCrumbs = [...state.breadCrumbs, action.payload];
15
+ }
16
+ }
17
+ });
18
+ var { setBreadCrumbs } = breadcrumbsSlice.actions;
19
+ var breadcrums_slice_default = breadcrumbsSlice.reducer;
20
+
21
+ // src/store/reducers/env-slice/index.ts
22
+ import { createSlice as createSlice2 } from "@reduxjs/toolkit";
23
+ var initialState2 = {
24
+ baseUrl: "",
25
+ companies: [],
26
+ user: {},
27
+ db: "",
28
+ refreshTokenEndpoint: "",
29
+ config: {
30
+ grantType: "",
31
+ clientId: "",
32
+ clientSecret: "",
33
+ redirectUri: ""
34
+ },
35
+ envFile: null,
36
+ defaultCompany: {
37
+ id: null,
38
+ logo: "",
39
+ secondary_color: "",
40
+ primary_color: ""
41
+ },
42
+ context: {
43
+ uid: null,
44
+ allowed_company_ids: [],
45
+ lang: "vi_VN",
46
+ tz: "Asia/Saigon"
47
+ }
48
+ };
49
+ var envSlice = createSlice2({
50
+ name: "env",
51
+ initialState: initialState2,
52
+ reducers: {
53
+ setEnv: (state, action) => {
54
+ Object.assign(state, action.payload);
55
+ },
56
+ setUid: (state, action) => {
57
+ state.context.uid = action.payload;
58
+ },
59
+ setAllowCompanies: (state, action) => {
60
+ state.context.allowed_company_ids = action.payload;
61
+ },
62
+ setCompanies: (state, action) => {
63
+ state.companies = action.payload;
64
+ },
65
+ setDefaultCompany: (state, action) => {
66
+ state.defaultCompany = action.payload;
67
+ },
68
+ setLang: (state, action) => {
69
+ state.context.lang = action.payload;
70
+ },
71
+ setUser: (state, action) => {
72
+ state.user = action.payload;
73
+ },
74
+ setConfig: (state, action) => {
75
+ state.config = action.payload;
76
+ },
77
+ setEnvFile: (state, action) => {
78
+ state.envFile = action.payload;
79
+ }
80
+ }
81
+ });
82
+ var {
83
+ setEnv,
84
+ setUid,
85
+ setLang,
86
+ setAllowCompanies,
87
+ setCompanies,
88
+ setDefaultCompany,
89
+ setUser,
90
+ setConfig,
91
+ setEnvFile
92
+ } = envSlice.actions;
93
+ var env_slice_default = envSlice.reducer;
94
+
95
+ // src/store/reducers/excel-slice/index.ts
96
+ import { createSlice as createSlice3 } from "@reduxjs/toolkit";
97
+ var initialState3 = {
98
+ dataParse: null,
99
+ idFile: null,
100
+ isFileLoaded: false,
101
+ loadingImport: false,
102
+ selectedFile: null,
103
+ errorData: null
104
+ };
105
+ var excelSlice = createSlice3({
106
+ name: "excel",
107
+ initialState: initialState3,
108
+ reducers: {
109
+ setDataParse: (state, action) => {
110
+ state.dataParse = action.payload;
111
+ },
112
+ setIdFile: (state, action) => {
113
+ state.idFile = action.payload;
114
+ },
115
+ setIsFileLoaded: (state, action) => {
116
+ state.isFileLoaded = action.payload;
117
+ },
118
+ setLoadingImport: (state, action) => {
119
+ state.loadingImport = action.payload;
120
+ },
121
+ setSelectedFile: (state, action) => {
122
+ state.selectedFile = action.payload;
123
+ },
124
+ setErrorData: (state, action) => {
125
+ state.errorData = action.payload;
126
+ }
127
+ }
128
+ });
129
+ var {
130
+ setDataParse,
131
+ setIdFile,
132
+ setIsFileLoaded,
133
+ setLoadingImport,
134
+ setSelectedFile,
135
+ setErrorData
136
+ } = excelSlice.actions;
137
+ var excel_slice_default = excelSlice.reducer;
138
+
139
+ // src/store/reducers/form-slice/index.ts
140
+ import { createSlice as createSlice4 } from "@reduxjs/toolkit";
141
+ var initialState4 = {
142
+ viewDataStore: {},
143
+ isShowingModalDetail: false,
144
+ isShowModalTranslate: false,
145
+ formSubmitComponent: {},
146
+ fieldTranslation: null,
147
+ listSubject: {},
148
+ dataUser: {}
149
+ };
150
+ var formSlice = createSlice4({
151
+ name: "form",
152
+ initialState: initialState4,
153
+ reducers: {
154
+ setViewDataStore: (state, action) => {
155
+ state.viewDataStore = action.payload;
156
+ },
157
+ setIsShowingModalDetail: (state, action) => {
158
+ state.isShowingModalDetail = action.payload;
159
+ },
160
+ setIsShowModalTranslate: (state, action) => {
161
+ state.isShowModalTranslate = action.payload;
162
+ },
163
+ setFormSubmitComponent: (state, action) => {
164
+ state.formSubmitComponent[action.payload.key] = action.payload.component;
165
+ },
166
+ setFieldTranslate: (state, action) => {
167
+ state.fieldTranslation = action.payload;
168
+ },
169
+ setListSubject: (state, action) => {
170
+ state.listSubject = action.payload;
171
+ },
172
+ setDataUser: (state, action) => {
173
+ state.dataUser = action.payload;
174
+ }
175
+ }
176
+ });
177
+ var {
178
+ setViewDataStore,
179
+ setIsShowingModalDetail,
180
+ setIsShowModalTranslate,
181
+ setFormSubmitComponent,
182
+ setFieldTranslate,
183
+ setListSubject,
184
+ setDataUser
185
+ } = formSlice.actions;
186
+ var form_slice_default = formSlice.reducer;
187
+
188
+ // src/store/reducers/header-slice/index.ts
189
+ import { createSlice as createSlice5 } from "@reduxjs/toolkit";
190
+ var headerSlice = createSlice5({
191
+ name: "header",
192
+ initialState: {
193
+ value: { allowedCompanyIds: [] }
194
+ },
195
+ reducers: {
196
+ setHeader: (state, action) => {
197
+ state.value = { ...state.value, ...action.payload };
198
+ },
199
+ setAllowedCompanyIds: (state, action) => {
200
+ state.value.allowedCompanyIds = action.payload;
201
+ }
202
+ }
203
+ });
204
+ var { setAllowedCompanyIds, setHeader } = headerSlice.actions;
205
+ var header_slice_default = headerSlice.reducer;
206
+
207
+ // src/store/reducers/list-slice/index.ts
208
+ import { createSlice as createSlice6 } from "@reduxjs/toolkit";
209
+ var initialState5 = {
210
+ pageLimit: 10,
211
+ fields: {},
212
+ order: "",
213
+ selectedRowKeys: [],
214
+ selectedRadioKey: 0,
215
+ indexRowTableModal: -2,
216
+ isUpdateTableModal: false,
217
+ footerGroupTable: {},
218
+ transferDetail: null,
219
+ page: 0,
220
+ domainTable: []
221
+ };
222
+ var listSlice = createSlice6({
223
+ name: "list",
224
+ initialState: initialState5,
225
+ reducers: {
226
+ setPageLimit: (state, action) => {
227
+ state.pageLimit = action.payload;
228
+ },
229
+ setFields: (state, action) => {
230
+ state.fields = action.payload;
231
+ },
232
+ setOrder: (state, action) => {
233
+ state.order = action.payload;
234
+ },
235
+ setSelectedRowKeys: (state, action) => {
236
+ state.selectedRowKeys = action.payload;
237
+ },
238
+ setSelectedRadioKey: (state, action) => {
239
+ state.selectedRadioKey = action.payload;
240
+ },
241
+ setIndexRowTableModal: (state, action) => {
242
+ state.indexRowTableModal = action.payload;
243
+ },
244
+ setTransferDetail: (state, action) => {
245
+ state.transferDetail = action.payload;
246
+ },
247
+ setIsUpdateTableModal: (state, action) => {
248
+ state.isUpdateTableModal = action.payload;
249
+ },
250
+ setPage: (state, action) => {
251
+ state.page = action.payload;
252
+ },
253
+ setDomainTable: (state, action) => {
254
+ state.domainTable = action.payload;
255
+ }
256
+ }
257
+ });
258
+ var {
259
+ setPageLimit,
260
+ setFields,
261
+ setOrder,
262
+ setSelectedRowKeys,
263
+ setIndexRowTableModal,
264
+ setIsUpdateTableModal,
265
+ setPage,
266
+ setSelectedRadioKey,
267
+ setTransferDetail,
268
+ setDomainTable
269
+ } = listSlice.actions;
270
+ var list_slice_default = listSlice.reducer;
271
+
272
+ // src/store/reducers/login-slice/index.ts
273
+ import { createSlice as createSlice7 } from "@reduxjs/toolkit";
274
+ var initialState6 = {
275
+ db: "",
276
+ redirectTo: "/",
277
+ forgotPasswordUrl: "/"
278
+ };
279
+ var loginSlice = createSlice7({
280
+ name: "login",
281
+ initialState: initialState6,
282
+ reducers: {
283
+ setDb: (state, action) => {
284
+ state.db = action.payload;
285
+ },
286
+ setRedirectTo: (state, action) => {
287
+ state.redirectTo = action.payload;
288
+ },
289
+ setForgotPasswordUrl: (state, action) => {
290
+ state.forgotPasswordUrl = action.payload;
291
+ }
292
+ }
293
+ });
294
+ var { setDb, setRedirectTo, setForgotPasswordUrl } = loginSlice.actions;
295
+ var login_slice_default = loginSlice.reducer;
296
+
297
+ // src/store/reducers/navbar-slice/index.ts
298
+ import { createSlice as createSlice8 } from "@reduxjs/toolkit";
299
+ var initialState7 = {
300
+ menuFocus: {},
301
+ menuAction: {},
302
+ navbarWidth: 250,
303
+ menuList: []
304
+ };
305
+ var navbarSlice = createSlice8({
306
+ name: "navbar",
307
+ initialState: initialState7,
308
+ reducers: {
309
+ setMenuFocus: (state, action) => {
310
+ state.menuFocus = action.payload;
311
+ },
312
+ setMenuFocusAction: (state, action) => {
313
+ state.menuAction = action.payload;
314
+ },
315
+ setNavbarWidth: (state, action) => {
316
+ state.navbarWidth = action.payload;
317
+ },
318
+ setMenuList: (state, action) => {
319
+ state.menuList = action.payload;
320
+ }
321
+ }
322
+ });
323
+ var { setMenuFocus, setMenuFocusAction, setNavbarWidth, setMenuList } = navbarSlice.actions;
324
+ var navbar_slice_default = navbarSlice.reducer;
325
+
326
+ // src/store/reducers/profile-slice/index.ts
327
+ import { createSlice as createSlice9 } from "@reduxjs/toolkit";
328
+ var initialState8 = {
329
+ profile: {}
330
+ };
331
+ var profileSlice = createSlice9({
332
+ name: "profile",
333
+ initialState: initialState8,
334
+ reducers: {
335
+ setProfile: (state, action) => {
336
+ state.profile = action.payload;
337
+ }
338
+ }
339
+ });
340
+ var { setProfile } = profileSlice.actions;
341
+ var profile_slice_default = profileSlice.reducer;
342
+
343
+ // src/store/reducers/search-slice/index.ts
344
+ import { createSlice as createSlice10 } from "@reduxjs/toolkit";
345
+ var initialState9 = {
346
+ groupByDomain: null,
347
+ searchBy: [],
348
+ searchString: "",
349
+ hoveredIndexSearchList: null,
350
+ selectedTags: [],
351
+ firstDomain: null,
352
+ searchMap: {},
353
+ filterBy: [],
354
+ groupBy: []
355
+ };
356
+ var searchSlice = createSlice10({
357
+ name: "search",
358
+ initialState: initialState9,
359
+ reducers: {
360
+ setGroupByDomain: (state, action) => {
361
+ state.groupByDomain = action.payload;
362
+ },
363
+ setSearchBy: (state, action) => {
364
+ state.searchBy = action.payload;
365
+ },
366
+ setSearchString: (state, action) => {
367
+ state.searchString = action.payload;
368
+ },
369
+ setHoveredIndexSearchList: (state, action) => {
370
+ state.hoveredIndexSearchList = action.payload;
371
+ },
372
+ setSelectedTags: (state, action) => {
373
+ state.selectedTags = action.payload;
374
+ },
375
+ setFirstDomain: (state, action) => {
376
+ state.firstDomain = action.payload;
377
+ },
378
+ setFilterBy: (state, action) => {
379
+ state.filterBy = action.payload;
380
+ },
381
+ setGroupBy: (state, action) => {
382
+ state.groupBy = action.payload;
383
+ },
384
+ setSearchMap: (state, action) => {
385
+ state.searchMap = action.payload;
386
+ },
387
+ updateSearchMap: (state, action) => {
388
+ if (!state.searchMap[action.payload.key]) {
389
+ state.searchMap[action.payload.key] = [];
390
+ }
391
+ state.searchMap[action.payload.key].push(action.payload.value);
392
+ },
393
+ removeKeyFromSearchMap: (state, action) => {
394
+ const { key, item } = action.payload;
395
+ const values = state.searchMap[key];
396
+ if (!values) return;
397
+ if (item) {
398
+ const filtered = values.filter((value) => value.name !== item.name);
399
+ if (filtered.length > 0) {
400
+ state.searchMap[key] = filtered;
401
+ } else {
402
+ delete state.searchMap[key];
403
+ }
404
+ } else {
405
+ delete state.searchMap[key];
406
+ }
407
+ },
408
+ clearSearchMap: (state) => {
409
+ state.searchMap = {};
410
+ }
411
+ }
412
+ });
413
+ var {
414
+ setGroupByDomain,
415
+ setSelectedTags,
416
+ setSearchString,
417
+ setHoveredIndexSearchList,
418
+ setFirstDomain,
419
+ setSearchBy,
420
+ setFilterBy,
421
+ setSearchMap,
422
+ updateSearchMap,
423
+ removeKeyFromSearchMap,
424
+ setGroupBy,
425
+ clearSearchMap
426
+ } = searchSlice.actions;
427
+ var search_slice_default = searchSlice.reducer;
428
+
429
+ // src/store/store.ts
430
+ import { configureStore } from "@reduxjs/toolkit";
431
+
432
+ // node_modules/redux/dist/redux.mjs
433
+ function formatProdErrorMessage(code) {
434
+ return `Minified Redux error #${code}; visit https://redux.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
435
+ }
436
+ var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
437
+ var ActionTypes = {
438
+ INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
439
+ REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
440
+ PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
441
+ };
442
+ var actionTypes_default = ActionTypes;
443
+ function isPlainObject(obj) {
444
+ if (typeof obj !== "object" || obj === null)
445
+ return false;
446
+ let proto = obj;
447
+ while (Object.getPrototypeOf(proto) !== null) {
448
+ proto = Object.getPrototypeOf(proto);
449
+ }
450
+ return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
451
+ }
452
+ function miniKindOf(val) {
453
+ if (val === void 0)
454
+ return "undefined";
455
+ if (val === null)
456
+ return "null";
457
+ const type = typeof val;
458
+ switch (type) {
459
+ case "boolean":
460
+ case "string":
461
+ case "number":
462
+ case "symbol":
463
+ case "function": {
464
+ return type;
465
+ }
466
+ }
467
+ if (Array.isArray(val))
468
+ return "array";
469
+ if (isDate(val))
470
+ return "date";
471
+ if (isError(val))
472
+ return "error";
473
+ const constructorName = ctorName(val);
474
+ switch (constructorName) {
475
+ case "Symbol":
476
+ case "Promise":
477
+ case "WeakMap":
478
+ case "WeakSet":
479
+ case "Map":
480
+ case "Set":
481
+ return constructorName;
482
+ }
483
+ return Object.prototype.toString.call(val).slice(8, -1).toLowerCase().replace(/\s/g, "");
484
+ }
485
+ function ctorName(val) {
486
+ return typeof val.constructor === "function" ? val.constructor.name : null;
487
+ }
488
+ function isError(val) {
489
+ return val instanceof Error || typeof val.message === "string" && val.constructor && typeof val.constructor.stackTraceLimit === "number";
490
+ }
491
+ function isDate(val) {
492
+ if (val instanceof Date)
493
+ return true;
494
+ return typeof val.toDateString === "function" && typeof val.getDate === "function" && typeof val.setDate === "function";
495
+ }
496
+ function kindOf(val) {
497
+ let typeOfVal = typeof val;
498
+ if (process.env.NODE_ENV !== "production") {
499
+ typeOfVal = miniKindOf(val);
500
+ }
501
+ return typeOfVal;
502
+ }
503
+ function warning(message) {
504
+ if (typeof console !== "undefined" && typeof console.error === "function") {
505
+ console.error(message);
506
+ }
507
+ try {
508
+ throw new Error(message);
509
+ } catch (e) {
510
+ }
511
+ }
512
+ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
513
+ const reducerKeys = Object.keys(reducers);
514
+ const argumentName = action && action.type === actionTypes_default.INIT ? "preloadedState argument passed to createStore" : "previous state received by the reducer";
515
+ if (reducerKeys.length === 0) {
516
+ return "Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.";
517
+ }
518
+ if (!isPlainObject(inputState)) {
519
+ return `The ${argumentName} has unexpected type of "${kindOf(inputState)}". Expected argument to be an object with the following keys: "${reducerKeys.join('", "')}"`;
520
+ }
521
+ const unexpectedKeys = Object.keys(inputState).filter((key) => !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key]);
522
+ unexpectedKeys.forEach((key) => {
523
+ unexpectedKeyCache[key] = true;
524
+ });
525
+ if (action && action.type === actionTypes_default.REPLACE)
526
+ return;
527
+ if (unexpectedKeys.length > 0) {
528
+ return `Unexpected ${unexpectedKeys.length > 1 ? "keys" : "key"} "${unexpectedKeys.join('", "')}" found in ${argumentName}. Expected to find one of the known reducer keys instead: "${reducerKeys.join('", "')}". Unexpected keys will be ignored.`;
529
+ }
530
+ }
531
+ function assertReducerShape(reducers) {
532
+ Object.keys(reducers).forEach((key) => {
533
+ const reducer = reducers[key];
534
+ const initialState10 = reducer(void 0, {
535
+ type: actionTypes_default.INIT
536
+ });
537
+ if (typeof initialState10 === "undefined") {
538
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : `The slice reducer for key "${key}" returned undefined during initialization. If the state passed to the reducer is undefined, you must explicitly return the initial state. The initial state may not be undefined. If you don't want to set a value for this reducer, you can use null instead of undefined.`);
539
+ }
540
+ if (typeof reducer(void 0, {
541
+ type: actionTypes_default.PROBE_UNKNOWN_ACTION()
542
+ }) === "undefined") {
543
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : `The slice reducer for key "${key}" returned undefined when probed with a random type. Don't try to handle '${actionTypes_default.INIT}' or other actions in "redux/*" namespace. They are considered private. Instead, you must return the current state for any unknown actions, unless it is undefined, in which case you must return the initial state, regardless of the action type. The initial state may not be undefined, but can be null.`);
544
+ }
545
+ });
546
+ }
547
+ function combineReducers(reducers) {
548
+ const reducerKeys = Object.keys(reducers);
549
+ const finalReducers = {};
550
+ for (let i = 0; i < reducerKeys.length; i++) {
551
+ const key = reducerKeys[i];
552
+ if (process.env.NODE_ENV !== "production") {
553
+ if (typeof reducers[key] === "undefined") {
554
+ warning(`No reducer provided for key "${key}"`);
555
+ }
556
+ }
557
+ if (typeof reducers[key] === "function") {
558
+ finalReducers[key] = reducers[key];
559
+ }
560
+ }
561
+ const finalReducerKeys = Object.keys(finalReducers);
562
+ let unexpectedKeyCache;
563
+ if (process.env.NODE_ENV !== "production") {
564
+ unexpectedKeyCache = {};
565
+ }
566
+ let shapeAssertionError;
567
+ try {
568
+ assertReducerShape(finalReducers);
569
+ } catch (e) {
570
+ shapeAssertionError = e;
571
+ }
572
+ return function combination(state = {}, action) {
573
+ if (shapeAssertionError) {
574
+ throw shapeAssertionError;
575
+ }
576
+ if (process.env.NODE_ENV !== "production") {
577
+ const warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
578
+ if (warningMessage) {
579
+ warning(warningMessage);
580
+ }
581
+ }
582
+ let hasChanged = false;
583
+ const nextState = {};
584
+ for (let i = 0; i < finalReducerKeys.length; i++) {
585
+ const key = finalReducerKeys[i];
586
+ const reducer = finalReducers[key];
587
+ const previousStateForKey = state[key];
588
+ const nextStateForKey = reducer(previousStateForKey, action);
589
+ if (typeof nextStateForKey === "undefined") {
590
+ const actionType = action && action.type;
591
+ throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : `When called with an action of type ${actionType ? `"${String(actionType)}"` : "(unknown type)"}, the slice reducer for key "${key}" returned undefined. To ignore an action, you must explicitly return the previous state. If you want this reducer to hold no value, you can return null instead of undefined.`);
592
+ }
593
+ nextState[key] = nextStateForKey;
594
+ hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
595
+ }
596
+ hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
597
+ return hasChanged ? nextState : state;
598
+ };
599
+ }
600
+
601
+ // src/store/store.ts
602
+ var rootReducer = combineReducers({
603
+ env: env_slice_default,
604
+ header: header_slice_default,
605
+ navbar: navbar_slice_default,
606
+ list: list_slice_default,
607
+ search: search_slice_default,
608
+ form: form_slice_default,
609
+ breadcrumbs: breadcrums_slice_default,
610
+ login: login_slice_default,
611
+ excel: excel_slice_default,
612
+ profile: profile_slice_default
613
+ });
614
+ var envStore = configureStore({
615
+ reducer: rootReducer,
616
+ middleware: (getDefaultMiddleware) => getDefaultMiddleware({
617
+ serializableCheck: false
618
+ })
619
+ });
620
+
1
621
  // src/configs/axios-client.ts
2
622
  import axios from "axios";
3
623
 
@@ -2193,19 +2813,16 @@ var axiosClient = {
2193
2813
  timeout: 5e4,
2194
2814
  paramsSerializer: (params) => new URLSearchParams(params).toString()
2195
2815
  });
2196
- instance.interceptors.request.use(
2197
- async (config2) => {
2198
- const useRefreshToken = config2.useRefreshToken;
2199
- const token = useRefreshToken ? await localStorage2.getRefreshToken() : await localStorage2.getAccessToken();
2200
- if (token) {
2201
- config2.headers["Authorization"] = "Bearer " + token;
2202
- }
2203
- return config2;
2204
- },
2205
- (error) => {
2206
- Promise.reject(error);
2816
+ instance.interceptors.request.use(async (config2) => {
2817
+ const { useRefreshToken, useActionToken, actionToken } = config2;
2818
+ if (useActionToken && actionToken) {
2819
+ config2.headers["Action-Token"] = actionToken;
2207
2820
  }
2208
- );
2821
+ const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
2822
+ const token = await getToken?.();
2823
+ if (token) config2.headers["Authorization"] = `Bearer ${token}`;
2824
+ return config2;
2825
+ }, Promise.reject);
2209
2826
  instance.interceptors.response.use(
2210
2827
  (response) => {
2211
2828
  return handleResponse(response);
@@ -2327,7 +2944,7 @@ var axiosClient = {
2327
2944
  return url + (db2 ? "?db=" + db2 : "");
2328
2945
  }
2329
2946
  const responseBody = (response) => response;
2330
- const requests = {
2947
+ const requests2 = {
2331
2948
  get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
2332
2949
  post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
2333
2950
  post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
@@ -2341,111 +2958,29 @@ var axiosClient = {
2341
2958
  patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
2342
2959
  delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
2343
2960
  };
2344
- return requests;
2961
+ return requests2;
2345
2962
  }
2346
2963
  };
2347
2964
 
2348
2965
  // src/environment/EnvStore.ts
2349
- var EnvStore = class _EnvStore {
2350
- static instance = null;
2351
- state = {};
2352
- localStorageUtils;
2353
- sessionStorageUtils;
2354
- constructor(localStorageUtils2, sessionStorageUtils2) {
2355
- this.localStorageUtils = localStorageUtils2;
2356
- this.sessionStorageUtils = sessionStorageUtils2;
2357
- }
2358
- static getInstance(localStorageUtils2, sessionStorageUtils2) {
2359
- if (!_EnvStore.instance) {
2360
- console.log("Creating new EnvStore instance");
2361
- _EnvStore.instance = new _EnvStore(localStorageUtils2, sessionStorageUtils2);
2362
- } else {
2363
- console.log("Returning existing EnvStore instance");
2364
- }
2365
- return _EnvStore.instance;
2366
- }
2367
- setupEnv(envConfig) {
2368
- this.state = {
2369
- ...this.state,
2370
- ...envConfig,
2371
- localStorageUtils: this.localStorageUtils,
2372
- sessionStorageUtils: this.sessionStorageUtils
2373
- };
2374
- console.log("Setting up env with config:", envConfig);
2375
- this.state.requests = axiosClient.init(this.state);
2376
- console.log("axiosClient.init result:", this.state.requests);
2377
- }
2378
- setUid(uid) {
2379
- this.state.uid = uid;
2380
- }
2381
- setLang(lang) {
2382
- this.state.lang = lang;
2383
- }
2384
- setAllowCompanies(allowCompanies) {
2385
- this.state.allowCompanies = allowCompanies;
2386
- }
2387
- setCompanies(companies) {
2388
- this.state.companies = companies;
2389
- }
2390
- setDefaultCompany(company) {
2391
- this.state.defaultCompany = company;
2392
- }
2393
- setUserInfo(userInfo) {
2394
- this.state.user = userInfo;
2395
- }
2396
- // Getters để truy cập trạng thái
2397
- get baseUrl() {
2398
- return this.state.baseUrl;
2399
- }
2400
- get requests() {
2401
- return this.state.requests;
2402
- }
2403
- get context() {
2404
- return this.state.context;
2405
- }
2406
- get defaultCompany() {
2407
- return this.state.defaultCompany;
2408
- }
2409
- get config() {
2410
- return this.state.config;
2411
- }
2412
- get companies() {
2413
- return this.state.companies;
2414
- }
2415
- get user() {
2416
- return this.state.user;
2417
- }
2418
- get db() {
2419
- return this.state.db;
2420
- }
2421
- get refreshTokenEndpoint() {
2422
- return this.state.refreshTokenEndpoint;
2423
- }
2424
- get uid() {
2425
- return this.state.uid;
2426
- }
2427
- get lang() {
2428
- return this.state.lang;
2429
- }
2430
- get allowCompanies() {
2431
- return this.state.allowCompanies;
2432
- }
2966
+ var requests = {
2967
+ get: async (url, headers) => ({}),
2968
+ post: async (url, body, headers) => ({}),
2969
+ post_excel: async (url, body, headers) => ({}),
2970
+ put: async (url, body, headers) => ({}),
2971
+ patch: async (url, body) => ({}),
2972
+ delete: async (url, body) => ({})
2433
2973
  };
2434
- function initEnv({
2435
- localStorageUtils: localStorageUtils2,
2436
- sessionStorageUtils: sessionStorageUtils2
2437
- }) {
2438
- return EnvStore.getInstance(localStorageUtils2, sessionStorageUtils2);
2974
+ function setupEnv(envConfig) {
2975
+ requests = axiosClient.init(envConfig);
2976
+ envStore.dispatch(setEnv(envConfig));
2977
+ return { ...envConfig, requests };
2439
2978
  }
2440
2979
  function getEnv() {
2441
- const instance = EnvStore.getInstance();
2442
- if (!instance) {
2443
- throw new Error("EnvStore has not been initialized \u2014 call initEnv() first");
2444
- }
2445
- return instance;
2980
+ const env = envStore.getState().env;
2981
+ return { ...env, requests };
2446
2982
  }
2447
2983
  export {
2448
- EnvStore,
2449
2984
  getEnv,
2450
- initEnv
2985
+ setupEnv
2451
2986
  };