@appcorp/stellar-solutions-modules 0.1.68 → 0.1.69
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/global-modules/bank/context.js +103 -4
- package/global-modules/branch/context.js +104 -3
- package/global-modules/currency/context.js +101 -3
- package/global-modules/payment-mode/context.js +98 -4
- package/global-modules/preferences/context.js +96 -51
- package/global-modules/preferences/types.d.ts +0 -1
- package/global-modules/tax/context.js +102 -3
- package/package.json +4 -4
|
@@ -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"));
|
|
@@ -179,6 +215,8 @@ var useBankState = function () {
|
|
|
179
215
|
}
|
|
180
216
|
if (data) {
|
|
181
217
|
showSuccessToast(t("messagesBankUpdated"));
|
|
218
|
+
// Invalidate cache to force fresh data on next fetch
|
|
219
|
+
(0, util_functions_1.invalidateBanksCache)();
|
|
182
220
|
dispatch({
|
|
183
221
|
type: actions_1.BANK_ACTION_TYPES.RESET_FORM,
|
|
184
222
|
});
|
|
@@ -194,11 +232,13 @@ var useBankState = function () {
|
|
|
194
232
|
var deleteCallback = (0, react_1.useCallback)(function (_a) {
|
|
195
233
|
var data = _a.data, error = _a.error;
|
|
196
234
|
if (error) {
|
|
197
|
-
showErrorToast(
|
|
235
|
+
showErrorToast(t("messagesNetworkError"));
|
|
198
236
|
return;
|
|
199
237
|
}
|
|
200
238
|
if (data) {
|
|
201
239
|
showSuccessToast(t("messagesBankDeleted"));
|
|
240
|
+
// Invalidate cache to force fresh data on next fetch
|
|
241
|
+
(0, util_functions_1.invalidateBanksCache)();
|
|
202
242
|
dispatch({
|
|
203
243
|
type: actions_1.BANK_ACTION_TYPES.RESET_FORM,
|
|
204
244
|
});
|
|
@@ -234,12 +274,71 @@ var useBankState = function () {
|
|
|
234
274
|
updateCallback: updateCallback,
|
|
235
275
|
updateDeps: [state],
|
|
236
276
|
updateParams: updateParams,
|
|
237
|
-
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
277
|
+
}), 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
278
|
// ---------------------------------------------------------------------------
|
|
239
|
-
// EFFECTS
|
|
279
|
+
// EFFECTS
|
|
240
280
|
// ---------------------------------------------------------------------------
|
|
281
|
+
/**
|
|
282
|
+
* Cache loading effect
|
|
283
|
+
*
|
|
284
|
+
* Loads banks from cache for instant UI feedback.
|
|
285
|
+
* Falls back to API if cache miss occurs.
|
|
286
|
+
*
|
|
287
|
+
* Triggers on:
|
|
288
|
+
* - debouncedQuery change (search)
|
|
289
|
+
* - currentPage change (pagination)
|
|
290
|
+
* - pageLimit change (items per page)
|
|
291
|
+
*
|
|
292
|
+
* Implementation:
|
|
293
|
+
* - Fetches from cache asynchronously
|
|
294
|
+
* - Slices data for client-side pagination
|
|
295
|
+
* - Updates count for pagination controls
|
|
296
|
+
* - Handles errors with toast notifications
|
|
297
|
+
*/
|
|
241
298
|
(0, react_1.useEffect)(function () {
|
|
242
|
-
|
|
299
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
300
|
+
var cachedData, filteredItems, query_1, startIndex, endIndex, paginatedItems, error_1;
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0:
|
|
304
|
+
_a.trys.push([0, 2, , 3]);
|
|
305
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedBanks)()];
|
|
306
|
+
case 1:
|
|
307
|
+
cachedData = _a.sent();
|
|
308
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
309
|
+
filteredItems = cachedData.items;
|
|
310
|
+
if (debouncedQuery) {
|
|
311
|
+
query_1 = debouncedQuery.toLowerCase();
|
|
312
|
+
filteredItems = cachedData.items.filter(function (bank) {
|
|
313
|
+
var _a, _b, _c, _d;
|
|
314
|
+
return ((_a = bank.bankName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query_1)) ||
|
|
315
|
+
((_b = bank.accountTitle) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query_1)) ||
|
|
316
|
+
((_c = bank.accountNumber) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes(query_1)) ||
|
|
317
|
+
((_d = bank.iban) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(query_1));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
startIndex = (state.currentPage - 1) * state.pageLimit;
|
|
321
|
+
endIndex = startIndex + state.pageLimit;
|
|
322
|
+
paginatedItems = filteredItems.slice(startIndex, endIndex);
|
|
323
|
+
dispatch({
|
|
324
|
+
type: actions_1.BANK_ACTION_TYPES.SET_BANKS,
|
|
325
|
+
payload: { banks: paginatedItems },
|
|
326
|
+
});
|
|
327
|
+
dispatch({
|
|
328
|
+
type: actions_1.BANK_ACTION_TYPES.SET_COUNT,
|
|
329
|
+
payload: { count: filteredItems.length },
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return [3 /*break*/, 3];
|
|
333
|
+
case 2:
|
|
334
|
+
error_1 = _a.sent();
|
|
335
|
+
console.error("Error loading banks from cache:", error_1);
|
|
336
|
+
showErrorToast(t("messagesNetworkError"));
|
|
337
|
+
return [3 /*break*/, 3];
|
|
338
|
+
case 3: return [2 /*return*/];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); })();
|
|
243
342
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
244
343
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
245
344
|
// ---------------------------------------------------------------------------
|
|
@@ -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"));
|
|
@@ -182,6 +218,8 @@ var useBranchState = function () {
|
|
|
182
218
|
}
|
|
183
219
|
if (data) {
|
|
184
220
|
showSuccessToast(t("messagesBranchUpdated"));
|
|
221
|
+
// Invalidate cache to force fresh data on next fetch
|
|
222
|
+
(0, util_functions_1.invalidateBranchesCache)();
|
|
185
223
|
dispatch({
|
|
186
224
|
type: actions_1.BRANCH_ACTION_TYPES.RESET_FORM,
|
|
187
225
|
});
|
|
@@ -217,6 +255,8 @@ var useBranchState = function () {
|
|
|
217
255
|
}
|
|
218
256
|
if (data) {
|
|
219
257
|
showSuccessToast(t("messagesBranchDeleted"));
|
|
258
|
+
// Invalidate cache to force fresh data on next fetch
|
|
259
|
+
(0, util_functions_1.invalidateBranchesCache)();
|
|
220
260
|
dispatch({
|
|
221
261
|
type: actions_1.BRANCH_ACTION_TYPES.RESET_FORM,
|
|
222
262
|
});
|
|
@@ -239,12 +279,73 @@ var useBranchState = function () {
|
|
|
239
279
|
updateCallback: updateCallback,
|
|
240
280
|
updateDeps: [state],
|
|
241
281
|
updateParams: updateParams,
|
|
242
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
282
|
+
}), 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
283
|
// ---------------------------------------------------------------------------
|
|
244
|
-
// EFFECTS
|
|
284
|
+
// EFFECTS
|
|
245
285
|
// ---------------------------------------------------------------------------
|
|
286
|
+
/**
|
|
287
|
+
* Cache loading effect
|
|
288
|
+
*
|
|
289
|
+
* Loads branches from cache for instant UI feedback.
|
|
290
|
+
* Falls back to API if cache miss occurs.
|
|
291
|
+
*
|
|
292
|
+
* Triggers on:
|
|
293
|
+
* - debouncedQuery change (search)
|
|
294
|
+
* - currentPage change (pagination)
|
|
295
|
+
* - pageLimit change (items per page)
|
|
296
|
+
*
|
|
297
|
+
* Implementation:
|
|
298
|
+
* - Fetches from cache asynchronously
|
|
299
|
+
* - Applies client-side search filtering
|
|
300
|
+
* - Slices data for client-side pagination
|
|
301
|
+
* - Updates count for pagination controls
|
|
302
|
+
* - Handles errors with toast notifications
|
|
303
|
+
*/
|
|
246
304
|
(0, react_1.useEffect)(function () {
|
|
247
|
-
|
|
305
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
306
|
+
var cachedData, filteredItems, query_1, startIndex, endIndex, paginatedItems, error_1;
|
|
307
|
+
return __generator(this, function (_a) {
|
|
308
|
+
switch (_a.label) {
|
|
309
|
+
case 0:
|
|
310
|
+
_a.trys.push([0, 2, , 3]);
|
|
311
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedBranches)()];
|
|
312
|
+
case 1:
|
|
313
|
+
cachedData = _a.sent();
|
|
314
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
315
|
+
filteredItems = cachedData.items;
|
|
316
|
+
if (debouncedQuery) {
|
|
317
|
+
query_1 = debouncedQuery.toLowerCase();
|
|
318
|
+
filteredItems = cachedData.items.filter(function (branch) {
|
|
319
|
+
var _a, _b, _c, _d, _e;
|
|
320
|
+
return ((_a = branch.branchName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query_1)) ||
|
|
321
|
+
((_b = branch.branchAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query_1)) ||
|
|
322
|
+
((_c = branch.personName) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes(query_1)) ||
|
|
323
|
+
((_d = branch.personEmail) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes(query_1)) ||
|
|
324
|
+
((_e = branch.personPhone) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes(query_1));
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
startIndex = (state.currentPage - 1) * state.pageLimit;
|
|
328
|
+
endIndex = startIndex + state.pageLimit;
|
|
329
|
+
paginatedItems = filteredItems.slice(startIndex, endIndex);
|
|
330
|
+
dispatch({
|
|
331
|
+
type: actions_1.BRANCH_ACTION_TYPES.SET_BRANCHES,
|
|
332
|
+
payload: { branches: paginatedItems },
|
|
333
|
+
});
|
|
334
|
+
dispatch({
|
|
335
|
+
type: actions_1.BRANCH_ACTION_TYPES.SET_COUNT,
|
|
336
|
+
payload: { count: filteredItems.length },
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return [3 /*break*/, 3];
|
|
340
|
+
case 2:
|
|
341
|
+
error_1 = _a.sent();
|
|
342
|
+
console.error("Error loading branches from cache:", error_1);
|
|
343
|
+
showErrorToast(tCommon("messagesNetworkError"));
|
|
344
|
+
return [3 /*break*/, 3];
|
|
345
|
+
case 3: return [2 /*return*/];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}); })();
|
|
248
349
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
249
350
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
250
351
|
// ---------------------------------------------------------------------------
|
|
@@ -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"));
|
|
@@ -168,6 +204,8 @@ var useCurrencyState = function () {
|
|
|
168
204
|
}
|
|
169
205
|
if (data) {
|
|
170
206
|
showSuccessToast(t("messagesCurrencyUpdated"));
|
|
207
|
+
// Invalidate cache to force fresh data on next fetch
|
|
208
|
+
(0, util_functions_1.invalidateCurrenciesCache)();
|
|
171
209
|
dispatch({
|
|
172
210
|
type: actions_1.CURRENCY_ACTION_TYPES.RESET_FORM,
|
|
173
211
|
});
|
|
@@ -188,6 +226,8 @@ var useCurrencyState = function () {
|
|
|
188
226
|
}
|
|
189
227
|
if (data) {
|
|
190
228
|
showSuccessToast(t("messagesCurrencyDeleted"));
|
|
229
|
+
// Invalidate cache to force fresh data on next fetch
|
|
230
|
+
(0, util_functions_1.invalidateCurrenciesCache)();
|
|
191
231
|
dispatch({
|
|
192
232
|
type: actions_1.CURRENCY_ACTION_TYPES.RESET_FORM,
|
|
193
233
|
});
|
|
@@ -223,12 +263,70 @@ var useCurrencyState = function () {
|
|
|
223
263
|
updateCallback: updateCallback,
|
|
224
264
|
updateDeps: [state],
|
|
225
265
|
updateParams: updateParams,
|
|
226
|
-
}), deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
266
|
+
}), 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
267
|
// ---------------------------------------------------------------------------
|
|
228
|
-
// EFFECTS
|
|
268
|
+
// EFFECTS
|
|
229
269
|
// ---------------------------------------------------------------------------
|
|
270
|
+
/**
|
|
271
|
+
* Cache loading effect
|
|
272
|
+
*
|
|
273
|
+
* Loads currencies from cache for instant UI feedback.
|
|
274
|
+
* Falls back to API if cache miss occurs.
|
|
275
|
+
*
|
|
276
|
+
* Triggers on:
|
|
277
|
+
* - debouncedQuery change (search)
|
|
278
|
+
* - currentPage change (pagination)
|
|
279
|
+
* - pageLimit change (items per page)
|
|
280
|
+
*
|
|
281
|
+
* Implementation:
|
|
282
|
+
* - Fetches from cache asynchronously
|
|
283
|
+
* - Applies client-side search filtering
|
|
284
|
+
* - Slices data for client-side pagination
|
|
285
|
+
* - Updates count for pagination controls
|
|
286
|
+
* - Handles errors with toast notifications
|
|
287
|
+
*/
|
|
230
288
|
(0, react_1.useEffect)(function () {
|
|
231
|
-
|
|
289
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
290
|
+
var cachedData, filteredItems, query_1, startIndex, endIndex, paginatedItems, error_1;
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
switch (_a.label) {
|
|
293
|
+
case 0:
|
|
294
|
+
_a.trys.push([0, 2, , 3]);
|
|
295
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedCurrencies)()];
|
|
296
|
+
case 1:
|
|
297
|
+
cachedData = _a.sent();
|
|
298
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
299
|
+
filteredItems = cachedData.items;
|
|
300
|
+
if (debouncedQuery) {
|
|
301
|
+
query_1 = debouncedQuery.toLowerCase();
|
|
302
|
+
filteredItems = cachedData.items.filter(function (currency) {
|
|
303
|
+
var _a, _b;
|
|
304
|
+
return ((_a = currency.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query_1)) ||
|
|
305
|
+
((_b = currency.code) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query_1));
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
startIndex = (state.currentPage - 1) * state.pageLimit;
|
|
309
|
+
endIndex = startIndex + state.pageLimit;
|
|
310
|
+
paginatedItems = filteredItems.slice(startIndex, endIndex);
|
|
311
|
+
dispatch({
|
|
312
|
+
type: actions_1.CURRENCY_ACTION_TYPES.SET_CURRENCIES,
|
|
313
|
+
payload: { currencies: paginatedItems },
|
|
314
|
+
});
|
|
315
|
+
dispatch({
|
|
316
|
+
type: actions_1.CURRENCY_ACTION_TYPES.SET_COUNT,
|
|
317
|
+
payload: { count: filteredItems.length },
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return [3 /*break*/, 3];
|
|
321
|
+
case 2:
|
|
322
|
+
error_1 = _a.sent();
|
|
323
|
+
console.error("Error loading currencies from cache:", error_1);
|
|
324
|
+
showErrorToast(tCommon("messagesNetworkError"));
|
|
325
|
+
return [3 /*break*/, 3];
|
|
326
|
+
case 3: return [2 /*return*/];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}); })();
|
|
232
330
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
233
331
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
234
332
|
// ---------------------------------------------------------------------------
|
|
@@ -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"));
|
|
@@ -164,6 +200,8 @@ var usePaymentModeState = function () {
|
|
|
164
200
|
}
|
|
165
201
|
if (data) {
|
|
166
202
|
showSuccessToast(t("messagesPaymentModeUpdated"));
|
|
203
|
+
// Invalidate cache to force fresh data on next fetch
|
|
204
|
+
(0, util_functions_1.invalidatePaymentModesCache)();
|
|
167
205
|
dispatch({
|
|
168
206
|
type: actions_1.PAYMENT_MODE_ACTION_TYPES.RESET_FORM,
|
|
169
207
|
});
|
|
@@ -199,6 +237,8 @@ var usePaymentModeState = function () {
|
|
|
199
237
|
}
|
|
200
238
|
if (data) {
|
|
201
239
|
showSuccessToast(t("messagesPaymentModeDeleted"));
|
|
240
|
+
// Invalidate cache to force fresh data on next fetch
|
|
241
|
+
(0, util_functions_1.invalidatePaymentModesCache)();
|
|
202
242
|
dispatch({
|
|
203
243
|
type: actions_1.PAYMENT_MODE_ACTION_TYPES.RESET_FORM,
|
|
204
244
|
});
|
|
@@ -221,13 +261,67 @@ var usePaymentModeState = function () {
|
|
|
221
261
|
updateCallback: updateCallback,
|
|
222
262
|
updateDeps: [state],
|
|
223
263
|
updateParams: updateParams,
|
|
224
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
264
|
+
}), 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
265
|
// ---------------------------------------------------------------------------
|
|
226
|
-
// EFFECTS
|
|
266
|
+
// EFFECTS
|
|
227
267
|
// ---------------------------------------------------------------------------
|
|
268
|
+
/**
|
|
269
|
+
* Cache loading effect
|
|
270
|
+
*
|
|
271
|
+
* Loads payment modes from cache for instant UI feedback.
|
|
272
|
+
* Falls back to API if cache miss occurs.
|
|
273
|
+
*
|
|
274
|
+
* Triggers on:
|
|
275
|
+
* - debouncedQuery change (search)
|
|
276
|
+
* - currentPage change (pagination)
|
|
277
|
+
* - pageLimit change (items per page)
|
|
278
|
+
*
|
|
279
|
+
* Implementation:
|
|
280
|
+
* - Fetches from cache asynchronously
|
|
281
|
+
* - Applies client-side search filtering
|
|
282
|
+
* - Slices data for client-side pagination
|
|
283
|
+
* - Updates count for pagination controls
|
|
284
|
+
* - Handles errors with toast notifications
|
|
285
|
+
*/
|
|
228
286
|
(0, react_1.useEffect)(function () {
|
|
229
|
-
|
|
230
|
-
|
|
287
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
288
|
+
var cachedData, filteredItems, query_1, startIndex, endIndex, paginatedItems, error_1;
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
switch (_a.label) {
|
|
291
|
+
case 0:
|
|
292
|
+
_a.trys.push([0, 2, , 3]);
|
|
293
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedPaymentModes)()];
|
|
294
|
+
case 1:
|
|
295
|
+
cachedData = _a.sent();
|
|
296
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
297
|
+
filteredItems = cachedData.items;
|
|
298
|
+
if (debouncedQuery) {
|
|
299
|
+
query_1 = debouncedQuery.toLowerCase();
|
|
300
|
+
filteredItems = cachedData.items.filter(function (paymentMode) { var _a; return (_a = paymentMode.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query_1); });
|
|
301
|
+
}
|
|
302
|
+
startIndex = (state.currentPage - 1) * state.pageLimit;
|
|
303
|
+
endIndex = startIndex + state.pageLimit;
|
|
304
|
+
paginatedItems = filteredItems.slice(startIndex, endIndex);
|
|
305
|
+
dispatch({
|
|
306
|
+
type: actions_1.PAYMENT_MODE_ACTION_TYPES.SET_PAYMENT_MODES,
|
|
307
|
+
payload: { paymentModes: paginatedItems },
|
|
308
|
+
});
|
|
309
|
+
dispatch({
|
|
310
|
+
type: actions_1.PAYMENT_MODE_ACTION_TYPES.SET_COUNT,
|
|
311
|
+
payload: { count: filteredItems.length },
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return [3 /*break*/, 3];
|
|
315
|
+
case 2:
|
|
316
|
+
error_1 = _a.sent();
|
|
317
|
+
console.error("Error loading payment modes from cache:", error_1);
|
|
318
|
+
showErrorToast(tCommon("messagesNetworkError"));
|
|
319
|
+
return [3 /*break*/, 3];
|
|
320
|
+
case 3: return [2 /*return*/];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}); })();
|
|
324
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
231
325
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
232
326
|
// ---------------------------------------------------------------------------
|
|
233
327
|
// DRAWER & MODAL HANDLERS
|
|
@@ -44,6 +44,42 @@ 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"));
|
|
@@ -94,23 +130,15 @@ var usePreferenceState = function () {
|
|
|
94
130
|
var updateCallback = function (_a) {
|
|
95
131
|
var data = _a.data, error = _a.error;
|
|
96
132
|
if (error) {
|
|
97
|
-
(0, toast_utils_1.
|
|
98
|
-
description: tCommon("messagesNetworkError"),
|
|
99
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
100
|
-
});
|
|
133
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
101
134
|
}
|
|
102
135
|
if (data) {
|
|
103
|
-
(0, toast_utils_1.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
136
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceUpdated"));
|
|
137
|
+
// Invalidate cache to force fresh data on next fetch
|
|
138
|
+
(0, util_functions_1.invalidatePreferencesCache)();
|
|
107
139
|
dispatch({
|
|
108
140
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
109
141
|
});
|
|
110
|
-
dispatch({
|
|
111
|
-
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
112
|
-
});
|
|
113
|
-
listFetchNow();
|
|
114
142
|
// dispatch({
|
|
115
143
|
// type: PREFERENCE_ACTION_TYPES.SET_DRAWER,
|
|
116
144
|
// payload: { drawer: null },
|
|
@@ -123,10 +151,7 @@ var usePreferenceState = function () {
|
|
|
123
151
|
var byIdCallback = function (_a) {
|
|
124
152
|
var data = _a.data, error = _a.error;
|
|
125
153
|
if (error) {
|
|
126
|
-
(0, toast_utils_1.
|
|
127
|
-
description: tCommon("messagesNetworkError"),
|
|
128
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
129
|
-
});
|
|
154
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
130
155
|
}
|
|
131
156
|
if (data) {
|
|
132
157
|
// dispatch({
|
|
@@ -145,20 +170,15 @@ var usePreferenceState = function () {
|
|
|
145
170
|
var deleteCallback = function (_a) {
|
|
146
171
|
var data = _a.data, error = _a.error;
|
|
147
172
|
if (error) {
|
|
148
|
-
(0, toast_utils_1.
|
|
149
|
-
description: tCommon("messagesNetworkError"),
|
|
150
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
151
|
-
});
|
|
173
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
152
174
|
}
|
|
153
175
|
if (data) {
|
|
154
|
-
(0, toast_utils_1.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
176
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceDeleted"));
|
|
177
|
+
// Invalidate cache to force fresh data on next fetch
|
|
178
|
+
(0, util_functions_1.invalidatePreferencesCache)();
|
|
158
179
|
dispatch({
|
|
159
180
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
160
181
|
});
|
|
161
|
-
listFetchNow();
|
|
162
182
|
}
|
|
163
183
|
};
|
|
164
184
|
var _b = (0, util_functions_1.useModuleEntity)({
|
|
@@ -179,7 +199,7 @@ var usePreferenceState = function () {
|
|
|
179
199
|
// byIdFetchNow,
|
|
180
200
|
byIdLoading = _b.byIdLoading, deleteError = _b.deleteError,
|
|
181
201
|
// deleteFetchNow,
|
|
182
|
-
deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
202
|
+
deleteLoading = _b.deleteLoading, listError = _b.listError, listLoading = _b.listLoading, updateError = _b.updateError,
|
|
183
203
|
// updateFetchNow,
|
|
184
204
|
updateLoading = _b.updateLoading;
|
|
185
205
|
var currencyListParams = {};
|
|
@@ -213,16 +233,10 @@ var usePreferenceState = function () {
|
|
|
213
233
|
var currencyUpdateCallback = function (_a) {
|
|
214
234
|
var data = _a.data, error = _a.error;
|
|
215
235
|
if (error) {
|
|
216
|
-
(0, toast_utils_1.
|
|
217
|
-
description: tCommon("messagesNetworkError"),
|
|
218
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
219
|
-
});
|
|
236
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
220
237
|
}
|
|
221
238
|
if (data) {
|
|
222
|
-
(0, toast_utils_1.
|
|
223
|
-
description: t("messagesPreferenceUpdated"),
|
|
224
|
-
variant: toast_utils_1.TOAST_VARIANT.SUCCESS,
|
|
225
|
-
});
|
|
239
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceUpdated"));
|
|
226
240
|
dispatch({
|
|
227
241
|
type: actions_1.PREFERENCE_ACTION_TYPES.SET_CURRENCY_UPDATE_ID,
|
|
228
242
|
payload: { currencyUpdateId: "" },
|
|
@@ -261,20 +275,15 @@ var usePreferenceState = function () {
|
|
|
261
275
|
var currencyDeleteCallback = function (_a) {
|
|
262
276
|
var data = _a.data, error = _a.error;
|
|
263
277
|
if (error) {
|
|
264
|
-
(0, toast_utils_1.
|
|
265
|
-
description: tCommon("messagesNetworkError"),
|
|
266
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
267
|
-
});
|
|
278
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
268
279
|
}
|
|
269
280
|
if (data) {
|
|
270
|
-
(0, toast_utils_1.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
281
|
+
(0, toast_utils_1.showSuccessToast)(t("messagesPreferenceDeleted"));
|
|
282
|
+
// Invalidate cache to force fresh data on next fetch
|
|
283
|
+
(0, util_functions_1.invalidatePreferencesCache)();
|
|
274
284
|
dispatch({
|
|
275
285
|
type: actions_1.PREFERENCE_ACTION_TYPES.RESET_FORM,
|
|
276
286
|
});
|
|
277
|
-
listFetchNow();
|
|
278
287
|
}
|
|
279
288
|
};
|
|
280
289
|
var _c = (0, util_functions_1.useModuleEntity)({
|
|
@@ -296,13 +305,49 @@ var usePreferenceState = function () {
|
|
|
296
305
|
currencyByIdLoading = _c.byIdLoading, currencyDeleteError = _c.deleteError,
|
|
297
306
|
// deleteFetchNow: currencyDeleteFetchNow,
|
|
298
307
|
currencyDeleteLoading = _c.deleteLoading, currencyListError = _c.listError, currencyListFetchNow = _c.listFetchNow, currencyListLoading = _c.listLoading, currencyUpdateError = _c.updateError, currencyUpdateFetchNow = _c.updateFetchNow, currencyUpdateLoading = _c.updateLoading;
|
|
308
|
+
/**
|
|
309
|
+
* Cache loading effect
|
|
310
|
+
*
|
|
311
|
+
* Loads preferences from cache for instant UI feedback.
|
|
312
|
+
* Falls back to API if cache miss occurs.
|
|
313
|
+
*
|
|
314
|
+
* Implementation:
|
|
315
|
+
* - Fetches from cache asynchronously
|
|
316
|
+
* - Updates preferences list
|
|
317
|
+
* - Handles errors with toast notifications
|
|
318
|
+
*/
|
|
299
319
|
(0, react_1.useEffect)(function () {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
320
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
321
|
+
var cachedData, error_1;
|
|
322
|
+
return __generator(this, function (_a) {
|
|
323
|
+
switch (_a.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
_a.trys.push([0, 2, , 3]);
|
|
326
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedPreferences)()];
|
|
327
|
+
case 1:
|
|
328
|
+
cachedData = _a.sent();
|
|
329
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
330
|
+
dispatch({
|
|
331
|
+
type: actions_1.PREFERENCE_ACTION_TYPES.SET_PREFERENCES,
|
|
332
|
+
payload: { preferences: cachedData.items },
|
|
333
|
+
});
|
|
334
|
+
dispatch({
|
|
335
|
+
type: actions_1.PREFERENCE_ACTION_TYPES.SET_COUNT,
|
|
336
|
+
payload: { count: cachedData.count },
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return [3 /*break*/, 3];
|
|
340
|
+
case 2:
|
|
341
|
+
error_1 = _a.sent();
|
|
342
|
+
console.error("Error loading preferences from cache:", error_1);
|
|
343
|
+
(0, toast_utils_1.showErrorToast)(tCommon("messagesNetworkError"));
|
|
344
|
+
return [3 /*break*/, 3];
|
|
345
|
+
case 3: return [2 /*return*/];
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}); })();
|
|
349
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
350
|
+
}, []);
|
|
306
351
|
var handleCreateCurrency = (0, react_1.useCallback)(function (currency) {
|
|
307
352
|
dispatch({
|
|
308
353
|
type: actions_1.PREFERENCE_ACTION_TYPES.SET_CURRENCY_UPDATE_ID,
|
|
@@ -419,9 +464,9 @@ var usePreferenceState = function () {
|
|
|
419
464
|
type: "",
|
|
420
465
|
},
|
|
421
466
|
]; }, [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,
|
|
467
|
+
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
468
|
};
|
|
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,
|
|
469
|
+
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
470
|
var PreferenceStateContextProvider = function (_a) {
|
|
426
471
|
var children = _a.children;
|
|
427
472
|
var state = usePreferenceState();
|
|
@@ -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.useTaxStateContext = exports.TaxStateContextProvider = exports.TaxStateContext = void 0;
|
|
80
116
|
var react_1 = __importStar(require("react"));
|
|
@@ -170,6 +206,8 @@ var useTaxState = function () {
|
|
|
170
206
|
}
|
|
171
207
|
if (data) {
|
|
172
208
|
showSuccessToast(t("messagesTaxUpdated"));
|
|
209
|
+
// Invalidate cache to force fresh data on next fetch
|
|
210
|
+
(0, util_functions_1.invalidateTaxesCache)();
|
|
173
211
|
dispatch({
|
|
174
212
|
type: actions_1.TAX_ACTION_TYPES.RESET_FORM,
|
|
175
213
|
});
|
|
@@ -207,6 +245,8 @@ var useTaxState = function () {
|
|
|
207
245
|
}
|
|
208
246
|
if (data) {
|
|
209
247
|
showSuccessToast(t("messagesTaxDeleted"));
|
|
248
|
+
// Invalidate cache to force fresh data on next fetch
|
|
249
|
+
(0, util_functions_1.invalidateTaxesCache)();
|
|
210
250
|
dispatch({
|
|
211
251
|
type: actions_1.TAX_ACTION_TYPES.RESET_FORM,
|
|
212
252
|
});
|
|
@@ -229,12 +269,71 @@ var useTaxState = function () {
|
|
|
229
269
|
updateCallback: updateCallback,
|
|
230
270
|
updateDeps: [state],
|
|
231
271
|
updateParams: updateParams,
|
|
232
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError,
|
|
272
|
+
}), 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;
|
|
233
273
|
// ---------------------------------------------------------------------------
|
|
234
|
-
// EFFECTS
|
|
274
|
+
// EFFECTS
|
|
235
275
|
// ---------------------------------------------------------------------------
|
|
276
|
+
/**
|
|
277
|
+
* Cache loading effect
|
|
278
|
+
*
|
|
279
|
+
* Loads taxes from cache for instant UI feedback.
|
|
280
|
+
* Falls back to API if cache miss occurs.
|
|
281
|
+
*
|
|
282
|
+
* Triggers on:
|
|
283
|
+
* - debouncedQuery change (search)
|
|
284
|
+
* - currentPage change (pagination)
|
|
285
|
+
* - pageLimit change (items per page)
|
|
286
|
+
*
|
|
287
|
+
* Implementation:
|
|
288
|
+
* - Fetches from cache asynchronously
|
|
289
|
+
* - Applies client-side search filtering
|
|
290
|
+
* - Slices data for client-side pagination
|
|
291
|
+
* - Updates count for pagination controls
|
|
292
|
+
* - Handles errors with toast notifications
|
|
293
|
+
*/
|
|
236
294
|
(0, react_1.useEffect)(function () {
|
|
237
|
-
|
|
295
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
296
|
+
var cachedData, filteredItems, query_1, startIndex, endIndex, paginatedItems, error_1;
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
switch (_a.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
_a.trys.push([0, 2, , 3]);
|
|
301
|
+
return [4 /*yield*/, (0, util_functions_1.getCachedTaxes)()];
|
|
302
|
+
case 1:
|
|
303
|
+
cachedData = _a.sent();
|
|
304
|
+
if (cachedData === null || cachedData === void 0 ? void 0 : cachedData.items) {
|
|
305
|
+
filteredItems = cachedData.items;
|
|
306
|
+
if (debouncedQuery) {
|
|
307
|
+
query_1 = debouncedQuery.toLowerCase();
|
|
308
|
+
filteredItems = cachedData.items.filter(function (tax) {
|
|
309
|
+
var _a, _b, _c;
|
|
310
|
+
return ((_a = tax.taxName) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(query_1)) ||
|
|
311
|
+
((_b = tax.taxRate) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(query_1)) ||
|
|
312
|
+
((_c = tax.description) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes(query_1));
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
startIndex = (state.currentPage - 1) * state.pageLimit;
|
|
316
|
+
endIndex = startIndex + state.pageLimit;
|
|
317
|
+
paginatedItems = filteredItems.slice(startIndex, endIndex);
|
|
318
|
+
dispatch({
|
|
319
|
+
type: actions_1.TAX_ACTION_TYPES.SET_TAXES,
|
|
320
|
+
payload: { taxes: paginatedItems },
|
|
321
|
+
});
|
|
322
|
+
dispatch({
|
|
323
|
+
type: actions_1.TAX_ACTION_TYPES.SET_COUNT,
|
|
324
|
+
payload: { count: filteredItems.length },
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return [3 /*break*/, 3];
|
|
328
|
+
case 2:
|
|
329
|
+
error_1 = _a.sent();
|
|
330
|
+
console.error("Error loading taxes from cache:", error_1);
|
|
331
|
+
showErrorToast(tCommon("messagesNetworkError"));
|
|
332
|
+
return [3 /*break*/, 3];
|
|
333
|
+
case 3: return [2 /*return*/];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}); })();
|
|
238
337
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
239
338
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
240
339
|
// ---------------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appcorp/stellar-solutions-modules",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"automate": "./automate.sh",
|
|
6
6
|
"build": "yarn clean && yarn build:ts && cp package.json lib && cp README.md lib && cp yarn.lock lib",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"upgrade:own": "ncu -f '@appcorp/app-corp-vista, @appcorp/shadcn, @react-pakistan/util-functions' -u"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@appcorp/app-corp-vista": "^0.3.
|
|
23
|
-
"@appcorp/shadcn": "^1.1.
|
|
22
|
+
"@appcorp/app-corp-vista": "^0.3.85",
|
|
23
|
+
"@appcorp/shadcn": "^1.1.20",
|
|
24
24
|
"@dnd-kit/core": "^6.3.1",
|
|
25
25
|
"@dnd-kit/modifiers": "^9.0.0",
|
|
26
26
|
"@eslint/eslintrc": "^3",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@radix-ui/react-separator": "^1.1.7",
|
|
36
36
|
"@radix-ui/react-slot": "^1.2.3",
|
|
37
37
|
"@radix-ui/react-switch": "^1.2.6",
|
|
38
|
-
"@react-pakistan/util-functions": "^1.
|
|
38
|
+
"@react-pakistan/util-functions": "^1.25.3",
|
|
39
39
|
"@supabase/supabase-js": "^2",
|
|
40
40
|
"@tailwindcss/forms": "^0",
|
|
41
41
|
"@tailwindcss/postcss": "^4",
|