@appcorp/stellar-solutions-modules 0.1.68 → 0.1.70
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/constants.d.ts +8 -0
- package/constants.js +11 -0
- package/global-modules/bank/cache.d.ts +23 -0
- package/global-modules/bank/cache.js +45 -0
- package/global-modules/bank/context.js +89 -6
- package/global-modules/branch/cache.d.ts +23 -0
- package/global-modules/branch/cache.js +45 -0
- package/global-modules/branch/context.js +89 -5
- package/global-modules/currency/cache.d.ts +23 -0
- package/global-modules/currency/cache.js +47 -0
- package/global-modules/currency/context.js +89 -5
- package/global-modules/payment-mode/cache.d.ts +23 -0
- package/global-modules/payment-mode/cache.js +49 -0
- package/global-modules/payment-mode/context.js +89 -5
- package/global-modules/preferences/cache.d.ts +23 -0
- package/global-modules/preferences/cache.js +47 -0
- package/global-modules/preferences/context.js +97 -51
- package/global-modules/preferences/types.d.ts +0 -1
- package/global-modules/tax/cache.d.ts +23 -0
- package/global-modules/tax/cache.js +45 -0
- package/global-modules/tax/context.js +105 -5
- package/i18n/routing.d.ts +1 -1
- package/package.json +6 -6
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LS_KEYS = void 0;
|
|
4
|
+
exports.LS_KEYS = {
|
|
5
|
+
BANKS: "banks_cache",
|
|
6
|
+
CURRENCIES: "currencies_cache",
|
|
7
|
+
PAYMENT_MODES: "payment_modes_cache",
|
|
8
|
+
PREFERENCES: "preferences_cache",
|
|
9
|
+
BRANCHES: "branches_cache",
|
|
10
|
+
TAXES: "taxes_cache",
|
|
11
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bank Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for banks using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { BankTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedBanksSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: BankTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedBanks: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: BankTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedBankById: (bankId: string) => BankTypeBE | null;
|
|
18
|
+
export declare const invalidateBanksCache: () => void;
|
|
19
|
+
export declare const preloadBanks: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: BankTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isBanksCacheStale: () => boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bank Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for banks using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isBanksCacheStale = exports.preloadBanks = exports.invalidateBanksCache = exports.getCachedBankById = exports.getCachedBanks = exports.getCachedBanksSync = void 0;
|
|
9
|
+
var constants_1 = require("@/constants");
|
|
10
|
+
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
11
|
+
var constants_2 = require("./constants");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// CACHE CONFIGURATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
var BANK_CACHE_CONFIG = {
|
|
16
|
+
apiUrl: constants_2.BANK_API_ROUTES.BANKS,
|
|
17
|
+
cacheKey: constants_1.LS_KEYS.BANKS,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// BANK-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedBanksSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.BANKS);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedBanksSync = getCachedBanksSync;
|
|
26
|
+
var getCachedBanks = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: BANK_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedBanks = getCachedBanks;
|
|
34
|
+
var getCachedBankById = function (bankId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.BANKS, bankId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedBankById = getCachedBankById;
|
|
38
|
+
var invalidateBanksCache = function () { return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.BANKS); };
|
|
39
|
+
exports.invalidateBanksCache = invalidateBanksCache;
|
|
40
|
+
var preloadBanks = function () {
|
|
41
|
+
return (0, util_functions_1.preloadCache)(BANK_CACHE_CONFIG);
|
|
42
|
+
};
|
|
43
|
+
exports.preloadBanks = preloadBanks;
|
|
44
|
+
var isBanksCacheStale = function () { return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.BANKS); };
|
|
45
|
+
exports.isBanksCacheStale = isBanksCacheStale;
|
|
@@ -75,6 +75,42 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
75
75
|
return result;
|
|
76
76
|
};
|
|
77
77
|
})();
|
|
78
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
79
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
82
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
83
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
84
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
88
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
89
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
90
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
93
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
94
|
+
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;
|
|
95
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
96
|
+
switch (op[0]) {
|
|
97
|
+
case 0: case 1: t = op; break;
|
|
98
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
99
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
100
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
101
|
+
default:
|
|
102
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
103
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
104
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
105
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
106
|
+
if (t[2]) _.ops.pop();
|
|
107
|
+
_.trys.pop(); continue;
|
|
108
|
+
}
|
|
109
|
+
op = body.call(thisArg, _);
|
|
110
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
111
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
78
114
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
115
|
exports.useBankStateContext = exports.BankStateContextProvider = exports.BankStateContext = void 0;
|
|
80
116
|
var react_1 = __importStar(require("react"));
|
|
@@ -87,6 +123,7 @@ var reducer_1 = require("./reducer");
|
|
|
87
123
|
var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
|
|
88
124
|
var types_1 = require("./types");
|
|
89
125
|
var validate_1 = require("./validate");
|
|
126
|
+
var cache_1 = require("./cache");
|
|
90
127
|
// ============================================================================
|
|
91
128
|
// MAIN HOOK
|
|
92
129
|
// ============================================================================
|
|
@@ -179,6 +216,8 @@ var useBankState = function () {
|
|
|
179
216
|
}
|
|
180
217
|
if (data) {
|
|
181
218
|
showSuccessToast(t("messagesBankUpdated"));
|
|
219
|
+
// Invalidate cache to force fresh data on next fetch
|
|
220
|
+
(0, cache_1.invalidateBanksCache)();
|
|
182
221
|
dispatch({
|
|
183
222
|
type: actions_1.BANK_ACTION_TYPES.RESET_FORM,
|
|
184
223
|
});
|
|
@@ -194,11 +233,13 @@ var useBankState = function () {
|
|
|
194
233
|
var deleteCallback = (0, react_1.useCallback)(function (_a) {
|
|
195
234
|
var data = _a.data, error = _a.error;
|
|
196
235
|
if (error) {
|
|
197
|
-
showErrorToast(
|
|
236
|
+
showErrorToast(t("messagesNetworkError"));
|
|
198
237
|
return;
|
|
199
238
|
}
|
|
200
239
|
if (data) {
|
|
201
240
|
showSuccessToast(t("messagesBankDeleted"));
|
|
241
|
+
// Invalidate cache to force fresh data on next fetch
|
|
242
|
+
(0, cache_1.invalidateBanksCache)();
|
|
202
243
|
dispatch({
|
|
203
244
|
type: actions_1.BANK_ACTION_TYPES.RESET_FORM,
|
|
204
245
|
});
|
|
@@ -234,14 +275,56 @@ var useBankState = function () {
|
|
|
234
275
|
updateCallback: updateCallback,
|
|
235
276
|
updateDeps: [state],
|
|
236
277
|
updateParams: updateParams,
|
|
237
|
-
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
278
|
+
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
|
|
238
279
|
// ---------------------------------------------------------------------------
|
|
239
|
-
// EFFECTS
|
|
280
|
+
// EFFECTS
|
|
240
281
|
// ---------------------------------------------------------------------------
|
|
282
|
+
/**
|
|
283
|
+
* Cache loading effect
|
|
284
|
+
*
|
|
285
|
+
* Loads banks from cache for instant UI feedback.
|
|
286
|
+
* Falls back to API if cache miss occurs.
|
|
287
|
+
*
|
|
288
|
+
* Triggers on:
|
|
289
|
+
* - debouncedQuery change (search)
|
|
290
|
+
* - currentPage change (pagination)
|
|
291
|
+
* - pageLimit change (items per page)
|
|
292
|
+
*
|
|
293
|
+
* Implementation:
|
|
294
|
+
* - Fetches from cache asynchronously
|
|
295
|
+
* - Slices data for client-side pagination
|
|
296
|
+
* - Updates count for pagination controls
|
|
297
|
+
* - Handles errors with toast notifications
|
|
298
|
+
*/
|
|
241
299
|
(0, react_1.useEffect)(function () {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
300
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
301
|
+
var _a, count, items, error_1;
|
|
302
|
+
return __generator(this, function (_b) {
|
|
303
|
+
switch (_b.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
_b.trys.push([0, 2, , 3]);
|
|
306
|
+
return [4 /*yield*/, (0, cache_1.getCachedBanks)({
|
|
307
|
+
params: listParams,
|
|
308
|
+
})];
|
|
309
|
+
case 1:
|
|
310
|
+
_a = _b.sent(), count = _a.count, items = _a.items;
|
|
311
|
+
dispatch({
|
|
312
|
+
type: actions_1.BANK_ACTION_TYPES.SET_BANKS,
|
|
313
|
+
payload: { banks: items },
|
|
314
|
+
});
|
|
315
|
+
dispatch({
|
|
316
|
+
type: actions_1.BANK_ACTION_TYPES.SET_COUNT,
|
|
317
|
+
payload: { count: count },
|
|
318
|
+
});
|
|
319
|
+
return [3 /*break*/, 3];
|
|
320
|
+
case 2:
|
|
321
|
+
error_1 = _b.sent();
|
|
322
|
+
return [3 /*break*/, 3];
|
|
323
|
+
case 3: return [2 /*return*/];
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}); })();
|
|
327
|
+
}, [listParams]);
|
|
245
328
|
// ---------------------------------------------------------------------------
|
|
246
329
|
// DRAWER & MODAL HANDLERS
|
|
247
330
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branch Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for branches using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { BranchTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedBranchesSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: BranchTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedBranches: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: BranchTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedBranchById: (branchId: string) => BranchTypeBE | null;
|
|
18
|
+
export declare const invalidateBranchesCache: () => void;
|
|
19
|
+
export declare const preloadBranches: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: BranchTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isBranchesCacheStale: () => boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Branch Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for branches using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isBranchesCacheStale = exports.preloadBranches = exports.invalidateBranchesCache = exports.getCachedBranchById = exports.getCachedBranches = exports.getCachedBranchesSync = void 0;
|
|
9
|
+
var constants_1 = require("@/constants");
|
|
10
|
+
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
11
|
+
var constants_2 = require("./constants");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// CACHE CONFIGURATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
var BRANCH_CACHE_CONFIG = {
|
|
16
|
+
apiUrl: constants_2.BRANCH_API_ROUTES.BRANCHES,
|
|
17
|
+
cacheKey: constants_1.LS_KEYS.BRANCHES,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// BRANCH-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedBranchesSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.BRANCHES);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedBranchesSync = getCachedBranchesSync;
|
|
26
|
+
var getCachedBranches = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: BRANCH_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedBranches = getCachedBranches;
|
|
34
|
+
var getCachedBranchById = function (branchId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.BRANCHES, branchId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedBranchById = getCachedBranchById;
|
|
38
|
+
var invalidateBranchesCache = function () { return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.BRANCHES); };
|
|
39
|
+
exports.invalidateBranchesCache = invalidateBranchesCache;
|
|
40
|
+
var preloadBranches = function () {
|
|
41
|
+
return (0, util_functions_1.preloadCache)(BRANCH_CACHE_CONFIG);
|
|
42
|
+
};
|
|
43
|
+
exports.preloadBranches = preloadBranches;
|
|
44
|
+
var isBranchesCacheStale = function () { return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.BRANCHES); };
|
|
45
|
+
exports.isBranchesCacheStale = isBranchesCacheStale;
|
|
@@ -75,6 +75,42 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
75
75
|
return result;
|
|
76
76
|
};
|
|
77
77
|
})();
|
|
78
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
79
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
82
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
83
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
84
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
88
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
89
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
90
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
93
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
94
|
+
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;
|
|
95
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
96
|
+
switch (op[0]) {
|
|
97
|
+
case 0: case 1: t = op; break;
|
|
98
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
99
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
100
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
101
|
+
default:
|
|
102
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
103
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
104
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
105
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
106
|
+
if (t[2]) _.ops.pop();
|
|
107
|
+
_.trys.pop(); continue;
|
|
108
|
+
}
|
|
109
|
+
op = body.call(thisArg, _);
|
|
110
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
111
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
78
114
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
115
|
exports.useBranchStateContext = exports.BranchStateContextProvider = exports.BranchStateContext = void 0;
|
|
80
116
|
var react_1 = __importStar(require("react"));
|
|
@@ -88,6 +124,7 @@ var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
|
|
|
88
124
|
var types_1 = require("./types");
|
|
89
125
|
var validate_1 = require("./validate");
|
|
90
126
|
var context_1 = require("../preferences/context");
|
|
127
|
+
var cache_1 = require("./cache");
|
|
91
128
|
// ============================================================================
|
|
92
129
|
// MAIN HOOK
|
|
93
130
|
// ============================================================================
|
|
@@ -182,6 +219,8 @@ var useBranchState = function () {
|
|
|
182
219
|
}
|
|
183
220
|
if (data) {
|
|
184
221
|
showSuccessToast(t("messagesBranchUpdated"));
|
|
222
|
+
// Invalidate cache to force fresh data on next fetch
|
|
223
|
+
(0, cache_1.invalidateBranchesCache)();
|
|
185
224
|
dispatch({
|
|
186
225
|
type: actions_1.BRANCH_ACTION_TYPES.RESET_FORM,
|
|
187
226
|
});
|
|
@@ -217,6 +256,8 @@ var useBranchState = function () {
|
|
|
217
256
|
}
|
|
218
257
|
if (data) {
|
|
219
258
|
showSuccessToast(t("messagesBranchDeleted"));
|
|
259
|
+
// Invalidate cache to force fresh data on next fetch
|
|
260
|
+
(0, cache_1.invalidateBranchesCache)();
|
|
220
261
|
dispatch({
|
|
221
262
|
type: actions_1.BRANCH_ACTION_TYPES.RESET_FORM,
|
|
222
263
|
});
|
|
@@ -239,14 +280,57 @@ var useBranchState = function () {
|
|
|
239
280
|
updateCallback: updateCallback,
|
|
240
281
|
updateDeps: [state],
|
|
241
282
|
updateParams: updateParams,
|
|
242
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
283
|
+
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
|
|
243
284
|
// ---------------------------------------------------------------------------
|
|
244
|
-
// EFFECTS
|
|
285
|
+
// EFFECTS
|
|
245
286
|
// ---------------------------------------------------------------------------
|
|
287
|
+
/**
|
|
288
|
+
* Cache loading effect
|
|
289
|
+
*
|
|
290
|
+
* Loads branches from cache for instant UI feedback.
|
|
291
|
+
* Falls back to API if cache miss occurs.
|
|
292
|
+
*
|
|
293
|
+
* Triggers on:
|
|
294
|
+
* - debouncedQuery change (search)
|
|
295
|
+
* - currentPage change (pagination)
|
|
296
|
+
* - pageLimit change (items per page)
|
|
297
|
+
*
|
|
298
|
+
* Implementation:
|
|
299
|
+
* - Fetches from cache asynchronously
|
|
300
|
+
* - Applies client-side search filtering
|
|
301
|
+
* - Slices data for client-side pagination
|
|
302
|
+
* - Updates count for pagination controls
|
|
303
|
+
* - Handles errors with toast notifications
|
|
304
|
+
*/
|
|
246
305
|
(0, react_1.useEffect)(function () {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
306
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
307
|
+
var _a, count, items, error_1;
|
|
308
|
+
return __generator(this, function (_b) {
|
|
309
|
+
switch (_b.label) {
|
|
310
|
+
case 0:
|
|
311
|
+
_b.trys.push([0, 2, , 3]);
|
|
312
|
+
return [4 /*yield*/, (0, cache_1.getCachedBranches)({
|
|
313
|
+
params: listParams,
|
|
314
|
+
})];
|
|
315
|
+
case 1:
|
|
316
|
+
_a = _b.sent(), count = _a.count, items = _a.items;
|
|
317
|
+
dispatch({
|
|
318
|
+
type: actions_1.BRANCH_ACTION_TYPES.SET_BRANCHES,
|
|
319
|
+
payload: { branches: items },
|
|
320
|
+
});
|
|
321
|
+
dispatch({
|
|
322
|
+
type: actions_1.BRANCH_ACTION_TYPES.SET_COUNT,
|
|
323
|
+
payload: { count: count },
|
|
324
|
+
});
|
|
325
|
+
return [3 /*break*/, 3];
|
|
326
|
+
case 2:
|
|
327
|
+
error_1 = _b.sent();
|
|
328
|
+
return [3 /*break*/, 3];
|
|
329
|
+
case 3: return [2 /*return*/];
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}); })();
|
|
333
|
+
}, [listParams]);
|
|
250
334
|
// ---------------------------------------------------------------------------
|
|
251
335
|
// DRAWER & MODAL HANDLERS
|
|
252
336
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for currencies using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { CurrencyTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedCurrenciesSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: CurrencyTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedCurrencies: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: CurrencyTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedCurrencyById: (currencyId: string) => CurrencyTypeBE | null;
|
|
18
|
+
export declare const invalidateCurrenciesCache: () => void;
|
|
19
|
+
export declare const preloadCurrencies: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: CurrencyTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isCurrenciesCacheStale: () => boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for currencies using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isCurrenciesCacheStale = exports.preloadCurrencies = exports.invalidateCurrenciesCache = exports.getCachedCurrencyById = exports.getCachedCurrencies = exports.getCachedCurrenciesSync = void 0;
|
|
9
|
+
var constants_1 = require("@/constants");
|
|
10
|
+
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
11
|
+
var constants_2 = require("./constants");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// CACHE CONFIGURATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
var CURRENCY_CACHE_CONFIG = {
|
|
16
|
+
apiUrl: constants_2.CURRENCY_API_ROUTES.CURRENCIES,
|
|
17
|
+
cacheKey: constants_1.LS_KEYS.CURRENCIES,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// CURRENCY-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedCurrenciesSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.CURRENCIES);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedCurrenciesSync = getCachedCurrenciesSync;
|
|
26
|
+
var getCachedCurrencies = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: CURRENCY_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedCurrencies = getCachedCurrencies;
|
|
34
|
+
var getCachedCurrencyById = function (currencyId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.CURRENCIES, currencyId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedCurrencyById = getCachedCurrencyById;
|
|
38
|
+
var invalidateCurrenciesCache = function () {
|
|
39
|
+
return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.CURRENCIES);
|
|
40
|
+
};
|
|
41
|
+
exports.invalidateCurrenciesCache = invalidateCurrenciesCache;
|
|
42
|
+
var preloadCurrencies = function () {
|
|
43
|
+
return (0, util_functions_1.preloadCache)(CURRENCY_CACHE_CONFIG);
|
|
44
|
+
};
|
|
45
|
+
exports.preloadCurrencies = preloadCurrencies;
|
|
46
|
+
var isCurrenciesCacheStale = function () { return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.CURRENCIES); };
|
|
47
|
+
exports.isCurrenciesCacheStale = isCurrenciesCacheStale;
|
|
@@ -75,6 +75,42 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
75
75
|
return result;
|
|
76
76
|
};
|
|
77
77
|
})();
|
|
78
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
79
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
80
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
81
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
82
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
83
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
84
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
88
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
89
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
90
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
91
|
+
function step(op) {
|
|
92
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
93
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
94
|
+
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;
|
|
95
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
96
|
+
switch (op[0]) {
|
|
97
|
+
case 0: case 1: t = op; break;
|
|
98
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
99
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
100
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
101
|
+
default:
|
|
102
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
103
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
104
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
105
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
106
|
+
if (t[2]) _.ops.pop();
|
|
107
|
+
_.trys.pop(); continue;
|
|
108
|
+
}
|
|
109
|
+
op = body.call(thisArg, _);
|
|
110
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
111
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
78
114
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
115
|
exports.useCurrencyStateContext = exports.CurrencyStateContextProvider = exports.CurrencyStateContext = void 0;
|
|
80
116
|
var react_1 = __importStar(require("react"));
|
|
@@ -87,6 +123,7 @@ var reducer_1 = require("./reducer");
|
|
|
87
123
|
var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
|
|
88
124
|
var types_1 = require("./types");
|
|
89
125
|
var validate_1 = require("./validate");
|
|
126
|
+
var cache_1 = require("./cache");
|
|
90
127
|
// ============================================================================
|
|
91
128
|
// MAIN HOOK
|
|
92
129
|
// ============================================================================
|
|
@@ -168,6 +205,8 @@ var useCurrencyState = function () {
|
|
|
168
205
|
}
|
|
169
206
|
if (data) {
|
|
170
207
|
showSuccessToast(t("messagesCurrencyUpdated"));
|
|
208
|
+
// Invalidate cache to force fresh data on next fetch
|
|
209
|
+
(0, cache_1.invalidateCurrenciesCache)();
|
|
171
210
|
dispatch({
|
|
172
211
|
type: actions_1.CURRENCY_ACTION_TYPES.RESET_FORM,
|
|
173
212
|
});
|
|
@@ -188,6 +227,8 @@ var useCurrencyState = function () {
|
|
|
188
227
|
}
|
|
189
228
|
if (data) {
|
|
190
229
|
showSuccessToast(t("messagesCurrencyDeleted"));
|
|
230
|
+
// Invalidate cache to force fresh data on next fetch
|
|
231
|
+
(0, cache_1.invalidateCurrenciesCache)();
|
|
191
232
|
dispatch({
|
|
192
233
|
type: actions_1.CURRENCY_ACTION_TYPES.RESET_FORM,
|
|
193
234
|
});
|
|
@@ -223,14 +264,57 @@ var useCurrencyState = function () {
|
|
|
223
264
|
updateCallback: updateCallback,
|
|
224
265
|
updateDeps: [state],
|
|
225
266
|
updateParams: updateParams,
|
|
226
|
-
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
267
|
+
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
|
|
227
268
|
// ---------------------------------------------------------------------------
|
|
228
|
-
// EFFECTS
|
|
269
|
+
// EFFECTS
|
|
229
270
|
// ---------------------------------------------------------------------------
|
|
271
|
+
/**
|
|
272
|
+
* Cache loading effect
|
|
273
|
+
*
|
|
274
|
+
* Loads currencies from cache for instant UI feedback.
|
|
275
|
+
* Falls back to API if cache miss occurs.
|
|
276
|
+
*
|
|
277
|
+
* Triggers on:
|
|
278
|
+
* - debouncedQuery change (search)
|
|
279
|
+
* - currentPage change (pagination)
|
|
280
|
+
* - pageLimit change (items per page)
|
|
281
|
+
*
|
|
282
|
+
* Implementation:
|
|
283
|
+
* - Fetches from cache asynchronously
|
|
284
|
+
* - Applies client-side search filtering
|
|
285
|
+
* - Slices data for client-side pagination
|
|
286
|
+
* - Updates count for pagination controls
|
|
287
|
+
* - Handles errors with toast notifications
|
|
288
|
+
*/
|
|
230
289
|
(0, react_1.useEffect)(function () {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
290
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
291
|
+
var _a, count, items, error_1;
|
|
292
|
+
return __generator(this, function (_b) {
|
|
293
|
+
switch (_b.label) {
|
|
294
|
+
case 0:
|
|
295
|
+
_b.trys.push([0, 2, , 3]);
|
|
296
|
+
return [4 /*yield*/, (0, cache_1.getCachedCurrencies)({
|
|
297
|
+
params: listParams,
|
|
298
|
+
})];
|
|
299
|
+
case 1:
|
|
300
|
+
_a = _b.sent(), count = _a.count, items = _a.items;
|
|
301
|
+
dispatch({
|
|
302
|
+
type: actions_1.CURRENCY_ACTION_TYPES.SET_CURRENCIES,
|
|
303
|
+
payload: { currencies: items },
|
|
304
|
+
});
|
|
305
|
+
dispatch({
|
|
306
|
+
type: actions_1.CURRENCY_ACTION_TYPES.SET_COUNT,
|
|
307
|
+
payload: { count: count },
|
|
308
|
+
});
|
|
309
|
+
return [3 /*break*/, 3];
|
|
310
|
+
case 2:
|
|
311
|
+
error_1 = _b.sent();
|
|
312
|
+
return [3 /*break*/, 3];
|
|
313
|
+
case 3: return [2 /*return*/];
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}); })();
|
|
317
|
+
}, [listParams]);
|
|
234
318
|
// ---------------------------------------------------------------------------
|
|
235
319
|
// DRAWER & MODAL HANDLERS
|
|
236
320
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Mode Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for payment modes using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { PaymentModeTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedPaymentModesSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: PaymentModeTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedPaymentModes: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: PaymentModeTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedPaymentModeById: (paymentModeId: string) => PaymentModeTypeBE | null;
|
|
18
|
+
export declare const invalidatePaymentModesCache: () => void;
|
|
19
|
+
export declare const preloadPaymentModes: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: PaymentModeTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isPaymentModesCacheStale: () => boolean;
|