@appcorp/fusion-storybook 0.2.39 → 0.2.42
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/base-modules/admission/constants.d.ts +5 -17
- package/base-modules/admission/constants.js +12 -7
- package/base-modules/admission/context/use-admission-module.js +11 -48
- package/base-modules/admission/filter.js +23 -3
- package/base-modules/admission/form.js +49 -19
- package/base-modules/attendance/context.js +3 -37
- package/base-modules/attendance/form.js +26 -10
- package/base-modules/attendance/more-actions.js +34 -25
- package/base-modules/campus/context.js +13 -44
- package/base-modules/class/cache.js +0 -1
- package/base-modules/class/context.js +10 -48
- package/base-modules/class/more-actions.js +0 -2
- package/base-modules/course/context.js +3 -37
- package/base-modules/course/form.js +91 -292
- package/base-modules/discount-code/constants.d.ts +5 -0
- package/base-modules/discount-code/constants.js +5 -0
- package/base-modules/discount-code/context.d.ts +1 -0
- package/base-modules/discount-code/context.js +40 -39
- package/base-modules/discount-code/form.js +21 -15
- package/base-modules/discount-code/more-actions.js +1 -1
- package/base-modules/enrollment/context.js +3 -37
- package/base-modules/enrollment/form.js +38 -11
- package/base-modules/enrollment/more-actions.js +0 -2
- package/base-modules/expense/constants.js +1 -1
- package/base-modules/expense/context.js +5 -32
- package/base-modules/expense/filter.js +50 -3
- package/base-modules/expense/form.js +82 -6
- package/base-modules/family/context.js +7 -38
- package/base-modules/family-member/context.js +7 -39
- package/base-modules/fee-structure/context.js +1 -25
- package/base-modules/fee-structure/form.js +77 -89
- package/base-modules/fee-structure/more-actions.js +0 -2
- package/base-modules/rbac/context.d.ts +1 -0
- package/base-modules/rbac/context.js +23 -32
- package/base-modules/school/context.js +1 -1
- package/base-modules/school/form.js +34 -14
- package/base-modules/section/context.d.ts +1 -0
- package/base-modules/section/context.js +40 -47
- package/base-modules/section/form.js +25 -80
- package/base-modules/section/more-actions.js +0 -2
- package/base-modules/section/view.js +9 -7
- package/base-modules/student-fee/context/use-student-fee-module.d.ts +1 -0
- package/base-modules/student-fee/context/use-student-fee-module.js +48 -32
- package/base-modules/student-fee/context.d.ts +1 -1
- package/base-modules/student-fee/context.js +1 -1
- package/base-modules/student-fee/filter.js +23 -3
- package/base-modules/student-fee/form.js +93 -174
- package/base-modules/student-fee/view.d.ts +7 -1
- package/base-modules/student-fee/view.js +17 -20
- package/base-modules/student-profile/constants.d.ts +0 -6
- package/base-modules/student-profile/constants.js +1 -3
- package/base-modules/student-profile/context/use-student-profile-module.d.ts +1 -0
- package/base-modules/student-profile/context/use-student-profile-module.js +62 -55
- package/base-modules/student-profile/context.d.ts +1 -1
- package/base-modules/student-profile/context.js +1 -1
- package/base-modules/student-profile/filter.js +23 -3
- package/base-modules/student-profile/form.js +35 -3
- package/base-modules/subject/context.d.ts +1 -0
- package/base-modules/subject/context.js +38 -47
- package/base-modules/subject/more-actions.js +0 -2
- package/base-modules/teacher/constants.d.ts +0 -6
- package/base-modules/teacher/constants.js +0 -2
- package/base-modules/teacher/context.d.ts +1 -0
- package/base-modules/teacher/context.js +58 -39
- package/base-modules/teacher/form.js +46 -11
- package/base-modules/teacher/more-actions.js +0 -2
- package/base-modules/user/context/use-user-module.d.ts +1 -0
- package/base-modules/user/context/use-user-module.js +36 -32
- package/base-modules/user/context.js +1 -1
- package/base-modules/user/filter.js +6 -4
- package/base-modules/user/form.js +29 -5
- package/base-modules/user/more-actions.js +9 -7
- package/base-modules/user/view.js +3 -1
- package/base-modules/workspace/form.js +18 -8
- package/base-modules/workspace-user/context.d.ts +2 -1
- package/base-modules/workspace-user/context.js +31 -29
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/base-modules/admission/cache.d.ts +0 -14
- package/base-modules/admission/cache.js +0 -31
- package/base-modules/attendance/cache.d.ts +0 -14
- package/base-modules/attendance/cache.js +0 -31
- package/base-modules/campus/cache.d.ts +0 -14
- package/base-modules/campus/cache.js +0 -31
- package/base-modules/course/cache.d.ts +0 -14
- package/base-modules/course/cache.js +0 -31
- package/base-modules/enrollment/cache.d.ts +0 -14
- package/base-modules/enrollment/cache.js +0 -31
- package/base-modules/expense/cache.d.ts +0 -14
- package/base-modules/expense/cache.js +0 -31
- package/base-modules/family/cache.d.ts +0 -14
- package/base-modules/family/cache.js +0 -31
- package/base-modules/family-member/cache.d.ts +0 -14
- package/base-modules/family-member/cache.js +0 -31
- package/base-modules/rbac/cache.d.ts +0 -27
- package/base-modules/rbac/cache.js +0 -46
- package/base-modules/student-fee/cache.d.ts +0 -15
- package/base-modules/student-fee/cache.js +0 -21
- package/base-modules/workspace-user/cache.d.ts +0 -14
- package/base-modules/workspace-user/cache.js +0 -31
|
@@ -85,8 +85,8 @@ export const useCampusModule = () => {
|
|
|
85
85
|
const { theme } = useTheme();
|
|
86
86
|
const workspace = getCachedWorkspaceSync();
|
|
87
87
|
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
88
|
-
const listFetchNowRef = useRef(null);
|
|
89
88
|
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
89
|
+
const listFetchNowRef = useRef(null);
|
|
90
90
|
// ============================================================================
|
|
91
91
|
// 1.4.2 API PARAMETERS
|
|
92
92
|
// ============================================================================
|
|
@@ -191,7 +191,6 @@ export const useCampusModule = () => {
|
|
|
191
191
|
}
|
|
192
192
|
if (data) {
|
|
193
193
|
const isCreated = isCreatedOrUpdated(data);
|
|
194
|
-
// invalidateCampusesCache();
|
|
195
194
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
196
195
|
resetFormAndCloseDrawer();
|
|
197
196
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
@@ -219,7 +218,6 @@ export const useCampusModule = () => {
|
|
|
219
218
|
return;
|
|
220
219
|
}
|
|
221
220
|
if (data) {
|
|
222
|
-
// invalidateCampusesCache();
|
|
223
221
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
224
222
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
225
223
|
}
|
|
@@ -399,19 +397,19 @@ export const useCampusModule = () => {
|
|
|
399
397
|
{
|
|
400
398
|
enabled: false,
|
|
401
399
|
handleOnClick: handleMoreActions,
|
|
402
|
-
label: t("
|
|
400
|
+
label: t("actionsButtonMoreActions"),
|
|
403
401
|
order: 0,
|
|
404
402
|
},
|
|
405
403
|
{
|
|
406
404
|
enabled: true,
|
|
407
405
|
handleOnClick: handleFilters,
|
|
408
|
-
label: t("
|
|
406
|
+
label: t("actionsButtonFilters"),
|
|
409
407
|
order: 1,
|
|
410
408
|
},
|
|
411
409
|
{
|
|
412
410
|
enabled: true,
|
|
413
411
|
handleOnClick: handleCreate,
|
|
414
|
-
label: t("
|
|
412
|
+
label: t("actionsButtonAdd"),
|
|
415
413
|
order: 2,
|
|
416
414
|
},
|
|
417
415
|
], [handleCreate, handleFilters, handleMoreActions, t]);
|
|
@@ -419,68 +417,39 @@ export const useCampusModule = () => {
|
|
|
419
417
|
{
|
|
420
418
|
enabled: true,
|
|
421
419
|
handleOnClick: handleView,
|
|
422
|
-
label: t("
|
|
420
|
+
label: t("actionsButtonView"),
|
|
423
421
|
order: 1,
|
|
424
422
|
},
|
|
425
423
|
{
|
|
426
424
|
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
|
|
427
425
|
handleOnClick: handleEdit,
|
|
428
|
-
label: t("
|
|
426
|
+
label: t("actionsButtonEdit"),
|
|
429
427
|
order: 2,
|
|
430
428
|
},
|
|
431
429
|
{
|
|
432
430
|
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === false,
|
|
433
431
|
handleOnClick: handleDelete,
|
|
434
|
-
label: t("
|
|
432
|
+
label: t("actionsButtonDelete"),
|
|
435
433
|
order: 3,
|
|
436
434
|
variant: "destructive",
|
|
437
435
|
},
|
|
438
436
|
{
|
|
439
437
|
enabled: false,
|
|
440
438
|
handleOnClick: toggleStatus,
|
|
441
|
-
label: t("
|
|
439
|
+
label: t("actionsButtonToggleStatus"),
|
|
442
440
|
order: 4,
|
|
443
441
|
},
|
|
444
442
|
], [handleDelete, handleEdit, handleView, t, toggleStatus]);
|
|
445
443
|
// ============================================================================
|
|
446
444
|
// 1.4.9 EFFECTS
|
|
447
445
|
// ============================================================================
|
|
448
|
-
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
449
|
-
// without depending on listFetchNow's unstable identity.
|
|
450
446
|
useEffect(() => {
|
|
451
|
-
listFetchNow
|
|
452
|
-
|
|
447
|
+
listFetchNowRef.current = listFetchNow;
|
|
448
|
+
}, [listFetchNow]);
|
|
449
|
+
useEffect(() => {
|
|
450
|
+
var _a;
|
|
451
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
453
452
|
}, [listParams]);
|
|
454
|
-
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
455
|
-
// useEffect(() => {
|
|
456
|
-
// if (!schoolId) return;
|
|
457
|
-
// const currentPage = Number(listParams.currentPage) || 1;
|
|
458
|
-
// const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
459
|
-
// const isDefaultLoad =
|
|
460
|
-
// currentPage === 1 &&
|
|
461
|
-
// currentPageLimit === pageLimit &&
|
|
462
|
-
// !listParams.searchQuery &&
|
|
463
|
-
// listParams.filterEnabled === undefined;
|
|
464
|
-
// if (isDefaultLoad) {
|
|
465
|
-
// (async () => {
|
|
466
|
-
// try {
|
|
467
|
-
// const { count, items } = await getCachedCampuses({
|
|
468
|
-
// params: listParams,
|
|
469
|
-
// });
|
|
470
|
-
// dispatch({
|
|
471
|
-
// type: CAMPUS_ACTION_TYPES.SET_ITEMS,
|
|
472
|
-
// payload: { items: items || [], count: count || 0 },
|
|
473
|
-
// });
|
|
474
|
-
// } catch {
|
|
475
|
-
// showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
476
|
-
// }
|
|
477
|
-
// })();
|
|
478
|
-
// } else {
|
|
479
|
-
// // Bypass cache for pagination, pageLimit, filter and search changes.
|
|
480
|
-
// // Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
481
|
-
// listFetchNowRef.current?.();
|
|
482
|
-
// }
|
|
483
|
-
// }, [dispatch, listParams, schoolId, showToast, t]);
|
|
484
453
|
// ============================================================================
|
|
485
454
|
// 1.4.10 RETURN
|
|
486
455
|
// ============================================================================
|
|
@@ -22,7 +22,6 @@ export const getCachedClasses = ({ params, }) => getCachedData({
|
|
|
22
22
|
params,
|
|
23
23
|
headers: {
|
|
24
24
|
"Content-Type": "application/json",
|
|
25
|
-
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
26
25
|
},
|
|
27
26
|
});
|
|
28
27
|
export const getCachedClassById = (classId) => getCachedItemById(LS_KEYS.CLASSES, classId);
|
|
@@ -28,7 +28,6 @@ import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-com
|
|
|
28
28
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
29
29
|
import { CLASS_API_ROUTES, pageLimit } from "./constants";
|
|
30
30
|
import { classFormValidation } from "./validate";
|
|
31
|
-
import { getCachedClasses, invalidateClassesCache } from "./cache";
|
|
32
31
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
33
32
|
// ============================================================================
|
|
34
33
|
// 1.1 DRAWER TYPES
|
|
@@ -159,7 +158,6 @@ export const useClassModule = () => {
|
|
|
159
158
|
}
|
|
160
159
|
if (data) {
|
|
161
160
|
const isCreated = isCreatedOrUpdated(data);
|
|
162
|
-
invalidateClassesCache();
|
|
163
161
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
164
162
|
resetFormAndCloseDrawer();
|
|
165
163
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
@@ -184,7 +182,6 @@ export const useClassModule = () => {
|
|
|
184
182
|
return;
|
|
185
183
|
}
|
|
186
184
|
if (data) {
|
|
187
|
-
invalidateClassesCache();
|
|
188
185
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
189
186
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
190
187
|
}
|
|
@@ -378,19 +375,19 @@ export const useClassModule = () => {
|
|
|
378
375
|
{
|
|
379
376
|
enabled: true,
|
|
380
377
|
handleOnClick: handleMoreActions,
|
|
381
|
-
label: t("
|
|
378
|
+
label: t("actionsButtonMoreActions"),
|
|
382
379
|
order: 0,
|
|
383
380
|
},
|
|
384
381
|
{
|
|
385
382
|
enabled: true,
|
|
386
383
|
handleOnClick: handleFilters,
|
|
387
|
-
label: t("
|
|
384
|
+
label: t("actionsButtonFilters"),
|
|
388
385
|
order: 1,
|
|
389
386
|
},
|
|
390
387
|
{
|
|
391
388
|
enabled: true,
|
|
392
389
|
handleOnClick: handleCreate,
|
|
393
|
-
label: t("
|
|
390
|
+
label: t("actionsButtonAdd"),
|
|
394
391
|
order: 2,
|
|
395
392
|
},
|
|
396
393
|
], [handleCreate, handleFilters, handleMoreActions, t]);
|
|
@@ -398,74 +395,39 @@ export const useClassModule = () => {
|
|
|
398
395
|
{
|
|
399
396
|
enabled: true,
|
|
400
397
|
handleOnClick: handleView,
|
|
401
|
-
label: t("
|
|
398
|
+
label: t("actionsButtonView"),
|
|
402
399
|
order: 1,
|
|
403
400
|
},
|
|
404
401
|
{
|
|
405
402
|
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
|
|
406
403
|
handleOnClick: handleEdit,
|
|
407
|
-
label: t("
|
|
404
|
+
label: t("actionsButtonEdit"),
|
|
408
405
|
order: 2,
|
|
409
406
|
},
|
|
410
407
|
{
|
|
411
408
|
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === false,
|
|
412
409
|
handleOnClick: handleDelete,
|
|
413
|
-
label: t("
|
|
410
|
+
label: t("actionsButtonDelete"),
|
|
414
411
|
order: 3,
|
|
415
412
|
variant: "destructive",
|
|
416
413
|
},
|
|
417
414
|
{
|
|
418
415
|
enabled: false,
|
|
419
416
|
handleOnClick: toggleStatus,
|
|
420
|
-
label: t("
|
|
417
|
+
label: t("actionsButtonToggleStatus"),
|
|
421
418
|
order: 4,
|
|
422
419
|
},
|
|
423
420
|
], [handleDelete, handleEdit, handleView, t, toggleStatus]);
|
|
424
421
|
// ============================================================================
|
|
425
422
|
// 1.4.9 EFFECTS
|
|
426
423
|
// ============================================================================
|
|
427
|
-
// Always keep the ref current so the main effect can call the latest listFetchNow
|
|
428
|
-
// without including it in the dependency array (listFetchNow changes identity every
|
|
429
|
-
// render because useModuleEntityV2 passes an inline headers object to useFetch).
|
|
430
|
-
// Declared first so the ref is populated before the fetch effect runs.
|
|
431
424
|
useEffect(() => {
|
|
432
425
|
listFetchNowRef.current = listFetchNow;
|
|
433
|
-
});
|
|
434
|
-
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
435
|
-
// listFetchNow is intentionally excluded from deps — it changes every render due to the
|
|
436
|
-
// inline headers object in useModuleEntityV2. We call it via the stable ref instead.
|
|
426
|
+
}, [listFetchNow]);
|
|
437
427
|
useEffect(() => {
|
|
438
428
|
var _a;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const currentPage = Number(listParams.currentPage) || 1;
|
|
442
|
-
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
443
|
-
const isDefaultLoad = currentPage === 1 &&
|
|
444
|
-
currentPageLimit === pageLimit &&
|
|
445
|
-
!listParams.searchQuery &&
|
|
446
|
-
listParams.filterEnabled === undefined;
|
|
447
|
-
if (isDefaultLoad) {
|
|
448
|
-
(async () => {
|
|
449
|
-
try {
|
|
450
|
-
const { count, items } = await getCachedClasses({
|
|
451
|
-
params: listParams,
|
|
452
|
-
});
|
|
453
|
-
dispatch({
|
|
454
|
-
type: CLASS_ACTION_TYPES.SET_ITEMS,
|
|
455
|
-
payload: { items: items || [], count: count || 0 },
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
catch (_a) {
|
|
459
|
-
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
460
|
-
}
|
|
461
|
-
})();
|
|
462
|
-
}
|
|
463
|
-
else {
|
|
464
|
-
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
465
|
-
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
466
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
467
|
-
}
|
|
468
|
-
}, [dispatch, listParams, schoolId, showToast, t]);
|
|
429
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
430
|
+
}, [listParams]);
|
|
469
431
|
// ============================================================================
|
|
470
432
|
// 1.4.10 RETURN
|
|
471
433
|
// ============================================================================
|
|
@@ -7,7 +7,6 @@ import converter from "json-2-csv";
|
|
|
7
7
|
import { Timeline } from "../../components/timeline";
|
|
8
8
|
import { useTranslations } from "next-intl";
|
|
9
9
|
import { CLASS_API_ROUTES, pageLimit } from "./constants";
|
|
10
|
-
import { invalidateClassesCache } from "./cache";
|
|
11
10
|
import { CLASS_ACTION_TYPES, useClassContext } from "./context";
|
|
12
11
|
import { useRef, useEffect, useCallback } from "react";
|
|
13
12
|
const workspace = getCachedWorkspaceSync();
|
|
@@ -165,7 +164,6 @@ export const ClassMoreActions = () => {
|
|
|
165
164
|
else {
|
|
166
165
|
showSuccessToast("Bulk operation completed successfully");
|
|
167
166
|
}
|
|
168
|
-
invalidateClassesCache();
|
|
169
167
|
const schoolId = ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id) || "";
|
|
170
168
|
fetch(`${CLASS_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
|
|
171
169
|
headers: {
|
|
@@ -25,7 +25,6 @@ import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
|
25
25
|
import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
|
|
26
26
|
import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
27
27
|
import { COURSE_API_ROUTES, pageLimit } from "./constants";
|
|
28
|
-
import { getCachedCourses, invalidateCoursesCache } from "./cache";
|
|
29
28
|
import { courseFormValidation } from "./validate";
|
|
30
29
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
31
30
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
@@ -167,7 +166,6 @@ export const useCourseModule = () => {
|
|
|
167
166
|
showToast(isCreatedOrUpdated(data)
|
|
168
167
|
? t("messagesCourseCreated")
|
|
169
168
|
: t("messagesCourseUpdated"), TOAST_VARIANT.SUCCESS);
|
|
170
|
-
invalidateCoursesCache();
|
|
171
169
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
172
170
|
resetFormAndCloseDrawer();
|
|
173
171
|
}
|
|
@@ -247,7 +245,6 @@ export const useCourseModule = () => {
|
|
|
247
245
|
}
|
|
248
246
|
if (data) {
|
|
249
247
|
showToast(t("messagesCourseDeleted"), TOAST_VARIANT.SUCCESS);
|
|
250
|
-
invalidateCoursesCache();
|
|
251
248
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
252
249
|
}
|
|
253
250
|
}, [showToast, t]);
|
|
@@ -456,44 +453,13 @@ export const useCourseModule = () => {
|
|
|
456
453
|
// ==========================================================================
|
|
457
454
|
// 1.4.9 EFFECTS
|
|
458
455
|
// ==========================================================================
|
|
459
|
-
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
460
|
-
// without depending on listFetchNow's unstable identity.
|
|
461
456
|
useEffect(() => {
|
|
462
457
|
listFetchNowRef.current = listFetchNow;
|
|
463
|
-
});
|
|
464
|
-
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
458
|
+
}, [listFetchNow]);
|
|
465
459
|
useEffect(() => {
|
|
466
460
|
var _a;
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const currentPage = Number(listParams.currentPage) || 1;
|
|
470
|
-
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
471
|
-
const isDefaultLoad = currentPage === 1 &&
|
|
472
|
-
currentPageLimit === pageLimit &&
|
|
473
|
-
!listParams.searchQuery &&
|
|
474
|
-
listParams.filterEnabled === undefined;
|
|
475
|
-
if (isDefaultLoad) {
|
|
476
|
-
(async () => {
|
|
477
|
-
try {
|
|
478
|
-
const { count, items } = await getCachedCourses({
|
|
479
|
-
params: listParams,
|
|
480
|
-
});
|
|
481
|
-
dispatch({
|
|
482
|
-
type: COURSE_ACTION_TYPES.SET_ITEMS,
|
|
483
|
-
payload: { items: items || [], count: count || 0 },
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
catch (_a) {
|
|
487
|
-
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
488
|
-
}
|
|
489
|
-
})();
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
493
|
-
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
494
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
495
|
-
}
|
|
496
|
-
}, [listParams, dispatch, showToast, schoolId, t]);
|
|
461
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
462
|
+
}, [listParams]);
|
|
497
463
|
// ==========================================================================
|
|
498
464
|
// 1.4.10 RETURN
|
|
499
465
|
// ==========================================================================
|