@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
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Payment Mode Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for payment modes using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isPaymentModesCacheStale = exports.preloadPaymentModes = exports.invalidatePaymentModesCache = exports.getCachedPaymentModeById = exports.getCachedPaymentModes = exports.getCachedPaymentModesSync = 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 PAYMENT_MODE_CACHE_CONFIG = {
|
|
16
|
+
apiUrl: constants_2.PAYMENT_MODE_API_ROUTES.PAYMENT_MODES,
|
|
17
|
+
cacheKey: constants_1.LS_KEYS.PAYMENT_MODES,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// PAYMENT MODE-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedPaymentModesSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.PAYMENT_MODES);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedPaymentModesSync = getCachedPaymentModesSync;
|
|
26
|
+
var getCachedPaymentModes = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: PAYMENT_MODE_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedPaymentModes = getCachedPaymentModes;
|
|
34
|
+
var getCachedPaymentModeById = function (paymentModeId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.PAYMENT_MODES, paymentModeId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedPaymentModeById = getCachedPaymentModeById;
|
|
38
|
+
var invalidatePaymentModesCache = function () {
|
|
39
|
+
return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.PAYMENT_MODES);
|
|
40
|
+
};
|
|
41
|
+
exports.invalidatePaymentModesCache = invalidatePaymentModesCache;
|
|
42
|
+
var preloadPaymentModes = function () {
|
|
43
|
+
return (0, util_functions_1.preloadCache)(PAYMENT_MODE_CACHE_CONFIG);
|
|
44
|
+
};
|
|
45
|
+
exports.preloadPaymentModes = preloadPaymentModes;
|
|
46
|
+
var isPaymentModesCacheStale = function () {
|
|
47
|
+
return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.PAYMENT_MODES);
|
|
48
|
+
};
|
|
49
|
+
exports.isPaymentModesCacheStale = isPaymentModesCacheStale;
|
|
@@ -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.usePaymentModeStateContext = exports.PaymentModeStateContextProvider = exports.PaymentModeStateContext = 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
|
// ============================================================================
|
|
@@ -164,6 +201,8 @@ var usePaymentModeState = function () {
|
|
|
164
201
|
}
|
|
165
202
|
if (data) {
|
|
166
203
|
showSuccessToast(t("messagesPaymentModeUpdated"));
|
|
204
|
+
// Invalidate cache to force fresh data on next fetch
|
|
205
|
+
(0, cache_1.invalidatePaymentModesCache)();
|
|
167
206
|
dispatch({
|
|
168
207
|
type: actions_1.PAYMENT_MODE_ACTION_TYPES.RESET_FORM,
|
|
169
208
|
});
|
|
@@ -199,6 +238,8 @@ var usePaymentModeState = function () {
|
|
|
199
238
|
}
|
|
200
239
|
if (data) {
|
|
201
240
|
showSuccessToast(t("messagesPaymentModeDeleted"));
|
|
241
|
+
// Invalidate cache to force fresh data on next fetch
|
|
242
|
+
(0, cache_1.invalidatePaymentModesCache)();
|
|
202
243
|
dispatch({
|
|
203
244
|
type: actions_1.PAYMENT_MODE_ACTION_TYPES.RESET_FORM,
|
|
204
245
|
});
|
|
@@ -221,14 +262,57 @@ var usePaymentModeState = function () {
|
|
|
221
262
|
updateCallback: updateCallback,
|
|
222
263
|
updateDeps: [state],
|
|
223
264
|
updateParams: updateParams,
|
|
224
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
265
|
+
}), 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;
|
|
225
266
|
// ---------------------------------------------------------------------------
|
|
226
|
-
// EFFECTS
|
|
267
|
+
// EFFECTS
|
|
227
268
|
// ---------------------------------------------------------------------------
|
|
269
|
+
/**
|
|
270
|
+
* Cache loading effect
|
|
271
|
+
*
|
|
272
|
+
* Loads payment modes from cache for instant UI feedback.
|
|
273
|
+
* Falls back to API if cache miss occurs.
|
|
274
|
+
*
|
|
275
|
+
* Triggers on:
|
|
276
|
+
* - debouncedQuery change (search)
|
|
277
|
+
* - currentPage change (pagination)
|
|
278
|
+
* - pageLimit change (items per page)
|
|
279
|
+
*
|
|
280
|
+
* Implementation:
|
|
281
|
+
* - Fetches from cache asynchronously
|
|
282
|
+
* - Applies client-side search filtering
|
|
283
|
+
* - Slices data for client-side pagination
|
|
284
|
+
* - Updates count for pagination controls
|
|
285
|
+
* - Handles errors with toast notifications
|
|
286
|
+
*/
|
|
228
287
|
(0, react_1.useEffect)(function () {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
288
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
289
|
+
var _a, count, items, error_1;
|
|
290
|
+
return __generator(this, function (_b) {
|
|
291
|
+
switch (_b.label) {
|
|
292
|
+
case 0:
|
|
293
|
+
_b.trys.push([0, 2, , 3]);
|
|
294
|
+
return [4 /*yield*/, (0, cache_1.getCachedPaymentModes)({
|
|
295
|
+
params: listParams,
|
|
296
|
+
})];
|
|
297
|
+
case 1:
|
|
298
|
+
_a = _b.sent(), count = _a.count, items = _a.items;
|
|
299
|
+
dispatch({
|
|
300
|
+
type: actions_1.PAYMENT_MODE_ACTION_TYPES.SET_PAYMENT_MODES,
|
|
301
|
+
payload: { paymentModes: items },
|
|
302
|
+
});
|
|
303
|
+
dispatch({
|
|
304
|
+
type: actions_1.PAYMENT_MODE_ACTION_TYPES.SET_COUNT,
|
|
305
|
+
payload: { count: count },
|
|
306
|
+
});
|
|
307
|
+
return [3 /*break*/, 3];
|
|
308
|
+
case 2:
|
|
309
|
+
error_1 = _b.sent();
|
|
310
|
+
return [3 /*break*/, 3];
|
|
311
|
+
case 3: return [2 /*return*/];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}); })();
|
|
315
|
+
}, [listParams]);
|
|
232
316
|
// ---------------------------------------------------------------------------
|
|
233
317
|
// DRAWER & MODAL HANDLERS
|
|
234
318
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preferences Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for preferences using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { PreferenceTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedPreferencesSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: PreferenceTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedPreferences: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: PreferenceTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedPreferenceById: (preferenceId: string) => PreferenceTypeBE | null;
|
|
18
|
+
export declare const invalidatePreferencesCache: () => void;
|
|
19
|
+
export declare const preloadPreferences: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: PreferenceTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isPreferencesCacheStale: () => boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Preferences Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for preferences using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isPreferencesCacheStale = exports.preloadPreferences = exports.invalidatePreferencesCache = exports.getCachedPreferenceById = exports.getCachedPreferences = exports.getCachedPreferencesSync = 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 PREFERENCE_CACHE_CONFIG = {
|
|
16
|
+
apiUrl: constants_2.PREFERENCE_API_ROUTES.PREFERENCES,
|
|
17
|
+
cacheKey: constants_1.LS_KEYS.PREFERENCES,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// PREFERENCE-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedPreferencesSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.PREFERENCES);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedPreferencesSync = getCachedPreferencesSync;
|
|
26
|
+
var getCachedPreferences = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: PREFERENCE_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedPreferences = getCachedPreferences;
|
|
34
|
+
var getCachedPreferenceById = function (preferenceId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.PREFERENCES, preferenceId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedPreferenceById = getCachedPreferenceById;
|
|
38
|
+
var invalidatePreferencesCache = function () {
|
|
39
|
+
return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.PREFERENCES);
|
|
40
|
+
};
|
|
41
|
+
exports.invalidatePreferencesCache = invalidatePreferencesCache;
|
|
42
|
+
var preloadPreferences = function () {
|
|
43
|
+
return (0, util_functions_1.preloadCache)(PREFERENCE_CACHE_CONFIG);
|
|
44
|
+
};
|
|
45
|
+
exports.preloadPreferences = preloadPreferences;
|
|
46
|
+
var isPreferencesCacheStale = function () { return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.PREFERENCES); };
|
|
47
|
+
exports.isPreferencesCacheStale = isPreferencesCacheStale;
|
|
@@ -44,10 +44,47 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
44
44
|
return result;
|
|
45
45
|
};
|
|
46
46
|
})();
|
|
47
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
48
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
49
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
50
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
51
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
52
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
53
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
57
|
+
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);
|
|
58
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
59
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
60
|
+
function step(op) {
|
|
61
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
63
|
+
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;
|
|
64
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
65
|
+
switch (op[0]) {
|
|
66
|
+
case 0: case 1: t = op; break;
|
|
67
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
68
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
69
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
70
|
+
default:
|
|
71
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
72
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
73
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
74
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
75
|
+
if (t[2]) _.ops.pop();
|
|
76
|
+
_.trys.pop(); continue;
|
|
77
|
+
}
|
|
78
|
+
op = body.call(thisArg, _);
|
|
79
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
80
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
47
83
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
84
|
exports.usePreferenceStateContext = exports.PreferenceStateContextProvider = exports.PreferenceStateContext = void 0;
|
|
49
85
|
var react_1 = __importStar(require("react"));
|
|
50
86
|
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
87
|
+
var cache_1 = require("./cache");
|
|
51
88
|
var next_intl_1 = require("next-intl");
|
|
52
89
|
var actions_1 = require("./actions");
|
|
53
90
|
var constants_1 = require("./constants");
|
|
@@ -94,23 +131,15 @@ var usePreferenceState = function () {
|
|
|
94
131
|
var updateCallback = function (_a) {
|
|
95
132
|
var data = _a.data, error = _a.error;
|
|
96
133
|
if (error) {
|
|
97
|
-
(0, toast_utils_1.
|
|
98
|
-
description: tCommon("messagesNetworkError"),
|
|
99
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
100
|
-
});
|
|
134
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
101
135
|
}
|
|
102
136
|
if (data) {
|
|
103
|
-
(0, toast_utils_1.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
137
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceUpdated"));
|
|
138
|
+
// Invalidate cache to force fresh data on next fetch
|
|
139
|
+
(0, cache_1.invalidatePreferencesCache)();
|
|
107
140
|
dispatch({
|
|
108
141
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
109
142
|
});
|
|
110
|
-
dispatch({
|
|
111
|
-
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
112
|
-
});
|
|
113
|
-
listFetchNow();
|
|
114
143
|
// dispatch({
|
|
115
144
|
// type: PREFERENCE_ACTION_TYPES.SET_DRAWER,
|
|
116
145
|
// payload: { drawer: null },
|
|
@@ -123,10 +152,7 @@ var usePreferenceState = function () {
|
|
|
123
152
|
var byIdCallback = function (_a) {
|
|
124
153
|
var data = _a.data, error = _a.error;
|
|
125
154
|
if (error) {
|
|
126
|
-
(0, toast_utils_1.
|
|
127
|
-
description: tCommon("messagesNetworkError"),
|
|
128
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
129
|
-
});
|
|
155
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
130
156
|
}
|
|
131
157
|
if (data) {
|
|
132
158
|
// dispatch({
|
|
@@ -145,20 +171,15 @@ var usePreferenceState = function () {
|
|
|
145
171
|
var deleteCallback = function (_a) {
|
|
146
172
|
var data = _a.data, error = _a.error;
|
|
147
173
|
if (error) {
|
|
148
|
-
(0, toast_utils_1.
|
|
149
|
-
description: tCommon("messagesNetworkError"),
|
|
150
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
151
|
-
});
|
|
174
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
152
175
|
}
|
|
153
176
|
if (data) {
|
|
154
|
-
(0, toast_utils_1.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
177
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceDeleted"));
|
|
178
|
+
// Invalidate cache to force fresh data on next fetch
|
|
179
|
+
(0, cache_1.invalidatePreferencesCache)();
|
|
158
180
|
dispatch({
|
|
159
181
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
160
182
|
});
|
|
161
|
-
listFetchNow();
|
|
162
183
|
}
|
|
163
184
|
};
|
|
164
185
|
var _b = (0, util_functions_1.useModuleEntity)({
|
|
@@ -179,7 +200,7 @@ var usePreferenceState = function () {
|
|
|
179
200
|
// byIdFetchNow,
|
|
180
201
|
byIdLoading = _b.byIdLoading, deleteError = _b.deleteError,
|
|
181
202
|
// deleteFetchNow,
|
|
182
|
-
deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
203
|
+
deleteLoading = _b.deleteLoading, listError = _b.listError, listLoading = _b.listLoading, updateError = _b.updateError,
|
|
183
204
|
// updateFetchNow,
|
|
184
205
|
updateLoading = _b.updateLoading;
|
|
185
206
|
var currencyListParams = {};
|
|
@@ -213,16 +234,10 @@ var usePreferenceState = function () {
|
|
|
213
234
|
var currencyUpdateCallback = function (_a) {
|
|
214
235
|
var data = _a.data, error = _a.error;
|
|
215
236
|
if (error) {
|
|
216
|
-
(0, toast_utils_1.
|
|
217
|
-
description: tCommon("messagesNetworkError"),
|
|
218
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
219
|
-
});
|
|
237
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
220
238
|
}
|
|
221
239
|
if (data) {
|
|
222
|
-
(0, toast_utils_1.
|
|
223
|
-
description: t("messagesPreferenceUpdated"),
|
|
224
|
-
variant: toast_utils_1.TOAST_VARIANT.SUCCESS,
|
|
225
|
-
});
|
|
240
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceUpdated"));
|
|
226
241
|
dispatch({
|
|
227
242
|
type: actions_1.PREFERENCE_ACTION_TYPES.SET_CURRENCY_UPDATE_ID,
|
|
228
243
|
payload: { currencyUpdateId: "" },
|
|
@@ -261,20 +276,15 @@ var usePreferenceState = function () {
|
|
|
261
276
|
var currencyDeleteCallback = function (_a) {
|
|
262
277
|
var data = _a.data, error = _a.error;
|
|
263
278
|
if (error) {
|
|
264
|
-
(0, toast_utils_1.
|
|
265
|
-
description: tCommon("messagesNetworkError"),
|
|
266
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
267
|
-
});
|
|
279
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
268
280
|
}
|
|
269
281
|
if (data) {
|
|
270
|
-
(0, toast_utils_1.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
282
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceDeleted"));
|
|
283
|
+
// Invalidate cache to force fresh data on next fetch
|
|
284
|
+
(0, cache_1.invalidatePreferencesCache)();
|
|
274
285
|
dispatch({
|
|
275
286
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
276
287
|
});
|
|
277
|
-
listFetchNow();
|
|
278
288
|
}
|
|
279
289
|
};
|
|
280
290
|
var _c = (0, util_functions_1.useModuleEntity)({
|
|
@@ -296,13 +306,49 @@ var usePreferenceState = function () {
|
|
|
296
306
|
currencyByIdLoading = _c.byIdLoading, currencyDeleteError = _c.deleteError,
|
|
297
307
|
// deleteFetchNow: currencyDeleteFetchNow,
|
|
298
308
|
currencyDeleteLoading = _c.deleteLoading, currencyListError = _c.listError, currencyListFetchNow = _c.listFetchNow, currencyListLoading = _c.listLoading, currencyUpdateError = _c.updateError, currencyUpdateFetchNow = _c.updateFetchNow, currencyUpdateLoading = _c.updateLoading;
|
|
309
|
+
/**
|
|
310
|
+
* Cache loading effect
|
|
311
|
+
*
|
|
312
|
+
* Loads preferences from cache for instant UI feedback.
|
|
313
|
+
* Falls back to API if cache miss occurs.
|
|
314
|
+
*
|
|
315
|
+
* Implementation:
|
|
316
|
+
* - Fetches from cache asynchronously
|
|
317
|
+
* - Updates preferences list
|
|
318
|
+
* - Handles errors with toast notifications
|
|
319
|
+
*/
|
|
299
320
|
(0, react_1.useEffect)(function () {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
321
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
322
|
+
var cachedData, error_1;
|
|
323
|
+
return __generator(this, function (_a) {
|
|
324
|
+
switch (_a.label) {
|
|
325
|
+
case 0:
|
|
326
|
+
_a.trys.push([0, 2, , 3]);
|
|
327
|
+
return [4 /*yield*/, (0, cache_1.getCachedPreferences)()];
|
|
328
|
+
case 1:
|
|
329
|
+
cachedData = _a.sent();
|
|
330
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
331
|
+
dispatch({
|
|
332
|
+
type: actions_1.PREFERENCE_ACTION_TYPES.SET_PREFERENCES,
|
|
333
|
+
payload: { preferences: cachedData.items },
|
|
334
|
+
});
|
|
335
|
+
dispatch({
|
|
336
|
+
type: actions_1.PREFERENCE_ACTION_TYPES.SET_COUNT,
|
|
337
|
+
payload: { count: cachedData.count },
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return [3 /*break*/, 3];
|
|
341
|
+
case 2:
|
|
342
|
+
error_1 = _a.sent();
|
|
343
|
+
console.error("Error loading preferences from cache:", error_1);
|
|
344
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
345
|
+
return [3 /*break*/, 3];
|
|
346
|
+
case 3: return [2 /*return*/];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}); })();
|
|
350
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
351
|
+
}, []);
|
|
306
352
|
var handleCreateCurrency = (0, react_1.useCallback)(function (currency) {
|
|
307
353
|
dispatch({
|
|
308
354
|
type: actions_1.PREFERENCE_ACTION_TYPES.SET_CURRENCY_UPDATE_ID,
|
|
@@ -419,9 +465,9 @@ var usePreferenceState = function () {
|
|
|
419
465
|
type: "",
|
|
420
466
|
},
|
|
421
467
|
]; }, [state.activeTab]);
|
|
422
|
-
return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, currencyByIdError: currencyByIdError, currencyByIdLoading: currencyByIdLoading, currencyDeleteError: currencyDeleteError, currencyDeleteLoading: currencyDeleteLoading, currencyListError: currencyListError, currencyListLoading: currencyListLoading, currencyUpdateError: currencyUpdateError, currencyUpdateLoading: currencyUpdateLoading, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleCreateCurrency: handleCreateCurrency, handleUpdateCurrency: handleUpdateCurrency, headerTabs: headerTabs, listError: listError,
|
|
468
|
+
return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, currencyByIdError: currencyByIdError, currencyByIdLoading: currencyByIdLoading, currencyDeleteError: currencyDeleteError, currencyDeleteLoading: currencyDeleteLoading, currencyListError: currencyListError, currencyListLoading: currencyListLoading, currencyUpdateError: currencyUpdateError, currencyUpdateLoading: currencyUpdateLoading, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleCreateCurrency: handleCreateCurrency, handleUpdateCurrency: handleUpdateCurrency, headerTabs: headerTabs, listError: listError, listLoading: listLoading, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
|
|
423
469
|
};
|
|
424
|
-
exports.PreferenceStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialPreferenceState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, listError: undefined,
|
|
470
|
+
exports.PreferenceStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialPreferenceState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, listError: undefined, listLoading: false, searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false, headerTabs: [], currencyByIdError: undefined, currencyByIdLoading: false, currencyDeleteError: undefined, currencyDeleteLoading: false, currencyListError: undefined, currencyListLoading: false, currencyUpdateError: undefined, currencyUpdateLoading: false, handleUpdateCurrency: function () { return void 0; }, handleCreateCurrency: function () { return void 0; } }));
|
|
425
471
|
var PreferenceStateContextProvider = function (_a) {
|
|
426
472
|
var children = _a.children;
|
|
427
473
|
var state = usePreferenceState();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attendance Module Cache Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides localStorage-based caching for attendances using generic cache system.
|
|
5
|
+
*/
|
|
6
|
+
import { TaxTypeBE } from "./types";
|
|
7
|
+
export declare const getCachedTaxesSync: () => {
|
|
8
|
+
count: number;
|
|
9
|
+
items: TaxTypeBE[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getCachedTaxes: ({ params, }?: {
|
|
12
|
+
params?: Record<string, unknown>;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
count: number;
|
|
15
|
+
items: TaxTypeBE[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare const getCachedTaxById: (taxId: string) => TaxTypeBE | null;
|
|
18
|
+
export declare const invalidateTaxesCache: () => void;
|
|
19
|
+
export declare const preloadTaxes: () => Promise<{
|
|
20
|
+
count: number;
|
|
21
|
+
items: TaxTypeBE[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const isTaxesCacheStale: () => boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Attendance Module Cache Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides localStorage-based caching for attendances using generic cache system.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isTaxesCacheStale = exports.preloadTaxes = exports.invalidateTaxesCache = exports.getCachedTaxById = exports.getCachedTaxes = exports.getCachedTaxesSync = void 0;
|
|
9
|
+
var constants_1 = require("@/constants");
|
|
10
|
+
var constants_2 = require("./constants");
|
|
11
|
+
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// CACHE CONFIGURATION
|
|
14
|
+
// ============================================================================
|
|
15
|
+
var TAX_CACHE_CONFIG = {
|
|
16
|
+
cacheKey: constants_1.LS_KEYS.TAXES,
|
|
17
|
+
apiUrl: constants_2.TAX_API_ROUTES.TAXES,
|
|
18
|
+
};
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// ATTENDANCE-SPECIFIC CACHE FUNCTIONS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
var getCachedTaxesSync = function () {
|
|
23
|
+
return (0, util_functions_1.getCachedDataSync)(constants_1.LS_KEYS.TAXES);
|
|
24
|
+
};
|
|
25
|
+
exports.getCachedTaxesSync = getCachedTaxesSync;
|
|
26
|
+
var getCachedTaxes = function (_a) {
|
|
27
|
+
var _b = _a === void 0 ? {} : _a, params = _b.params;
|
|
28
|
+
return (0, util_functions_1.getCachedData)({
|
|
29
|
+
config: TAX_CACHE_CONFIG,
|
|
30
|
+
params: params,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.getCachedTaxes = getCachedTaxes;
|
|
34
|
+
var getCachedTaxById = function (taxId) {
|
|
35
|
+
return (0, util_functions_1.getCachedItemById)(constants_1.LS_KEYS.TAXES, taxId);
|
|
36
|
+
};
|
|
37
|
+
exports.getCachedTaxById = getCachedTaxById;
|
|
38
|
+
var invalidateTaxesCache = function () { return (0, util_functions_1.invalidateCache)(constants_1.LS_KEYS.TAXES); };
|
|
39
|
+
exports.invalidateTaxesCache = invalidateTaxesCache;
|
|
40
|
+
var preloadTaxes = function () {
|
|
41
|
+
return (0, util_functions_1.preloadCache)(TAX_CACHE_CONFIG);
|
|
42
|
+
};
|
|
43
|
+
exports.preloadTaxes = preloadTaxes;
|
|
44
|
+
var isTaxesCacheStale = function () { return (0, util_functions_1.isCacheStale)(constants_1.LS_KEYS.TAXES); };
|
|
45
|
+
exports.isTaxesCacheStale = isTaxesCacheStale;
|