@appcorp/fusion-storybook 0.1.79 → 0.1.81
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/context.d.ts +1 -1
- package/base-modules/admission/context.js +38 -26
- package/base-modules/attendance/context.d.ts +1 -1
- package/base-modules/attendance/context.js +37 -18
- package/base-modules/campus/context.d.ts +1 -1
- package/base-modules/campus/context.js +40 -21
- package/base-modules/class/context.d.ts +6 -6
- package/base-modules/class/context.js +1 -1
- package/base-modules/course/context.d.ts +1 -1
- package/base-modules/course/context.js +37 -18
- package/base-modules/discount-code/context.d.ts +1 -1
- package/base-modules/discount-code/context.js +29 -20
- package/base-modules/enrollment/context.d.ts +1 -1
- package/base-modules/enrollment/context.js +37 -18
- package/base-modules/expense/context.d.ts +1 -1
- package/base-modules/expense/context.js +31 -20
- package/base-modules/family/context.d.ts +1 -1
- package/base-modules/family/context.js +36 -21
- package/base-modules/family-member/context.d.ts +1 -1
- package/base-modules/family-member/context.js +37 -21
- package/base-modules/fee-structure/context.d.ts +1 -1
- package/base-modules/fee-structure/context.js +29 -20
- package/base-modules/rbac/context.d.ts +1 -1
- package/base-modules/rbac/context.js +26 -22
- package/base-modules/section/context.d.ts +1 -1
- package/base-modules/section/context.js +26 -19
- package/base-modules/student-fee/context.d.ts +1 -1
- package/base-modules/student-fee/context.js +30 -20
- package/base-modules/student-profile/context.d.ts +1 -1
- package/base-modules/student-profile/context.js +34 -22
- package/base-modules/subject/context.d.ts +2 -2
- package/base-modules/subject/context.js +54 -30
- package/base-modules/teacher/context.d.ts +1 -1
- package/base-modules/teacher/context.js +29 -22
- package/base-modules/user/context.d.ts +1 -1
- package/base-modules/user/context.js +27 -20
- package/base-modules/workspace-user/context.d.ts +1 -1
- package/base-modules/workspace-user/context.js +32 -19
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -294,7 +294,7 @@ export declare const useAdmissionModule: () => {
|
|
|
294
294
|
handleDelete: (row?: TableRow) => void;
|
|
295
295
|
handleEdit: (row?: TableRow) => void;
|
|
296
296
|
handleFilters: () => void;
|
|
297
|
-
handlePageChange: (page: number) => void;
|
|
297
|
+
handlePageChange: (page: number | unknown) => void;
|
|
298
298
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
299
299
|
handlePrint: (row?: TableRow) => Promise<void>;
|
|
300
300
|
handleSearch: (query: string) => void;
|
|
@@ -239,6 +239,12 @@ export const useAdmissionModule = () => {
|
|
|
239
239
|
]);
|
|
240
240
|
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
241
241
|
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
242
|
+
const isDefaultListState = state.currentPage === 1 &&
|
|
243
|
+
state.pageLimit === pageLimit &&
|
|
244
|
+
!debouncedQuery &&
|
|
245
|
+
state.filterAdmissionStatus === undefined &&
|
|
246
|
+
state.filterStartDate === undefined &&
|
|
247
|
+
state.filterEndDate === undefined;
|
|
242
248
|
// ============================================================================
|
|
243
249
|
// 1.4.3 UTILITIES
|
|
244
250
|
// ============================================================================
|
|
@@ -459,11 +465,12 @@ export const useAdmissionModule = () => {
|
|
|
459
465
|
});
|
|
460
466
|
}, [dispatch]);
|
|
461
467
|
const handlePageChange = useCallback((page) => {
|
|
468
|
+
const nextPage = typeof page === "number" ? page : state.currentPage + 1;
|
|
462
469
|
dispatch({
|
|
463
470
|
type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
464
|
-
payload: { currentPage:
|
|
471
|
+
payload: { currentPage: nextPage },
|
|
465
472
|
});
|
|
466
|
-
}, [dispatch]);
|
|
473
|
+
}, [dispatch, state.currentPage]);
|
|
467
474
|
const handlePageLimitChange = useCallback((k, value) => {
|
|
468
475
|
const val = Object.assign({}, value);
|
|
469
476
|
dispatch({
|
|
@@ -578,6 +585,7 @@ export const useAdmissionModule = () => {
|
|
|
578
585
|
}
|
|
579
586
|
}, [workspace, t, showToast]);
|
|
580
587
|
const handleAddStudent = useCallback(async (row) => {
|
|
588
|
+
var _a;
|
|
581
589
|
const tableRow = row;
|
|
582
590
|
const { data, error } = await fetchData({
|
|
583
591
|
url: "/api/v1/admit-student",
|
|
@@ -588,7 +596,7 @@ export const useAdmissionModule = () => {
|
|
|
588
596
|
},
|
|
589
597
|
body: JSON.stringify({ admissionId: tableRow === null || tableRow === void 0 ? void 0 : tableRow.id }),
|
|
590
598
|
});
|
|
591
|
-
|
|
599
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
592
600
|
invalidateAdmissionsCache();
|
|
593
601
|
invalidateFamiliesCache();
|
|
594
602
|
invalidateFamilyMembersCache();
|
|
@@ -599,12 +607,12 @@ export const useAdmissionModule = () => {
|
|
|
599
607
|
if (error) {
|
|
600
608
|
showToast(t("messagesAdmitFailed"), TOAST_VARIANT.ERROR);
|
|
601
609
|
}
|
|
602
|
-
}, [t, showToast
|
|
610
|
+
}, [t, showToast]);
|
|
603
611
|
// ============================================================================
|
|
604
612
|
// 1.4.7 NETWORK ACTIONS
|
|
605
613
|
// ============================================================================
|
|
606
614
|
const handleAnalyze = useCallback(async (row) => {
|
|
607
|
-
var _a, _b, _c;
|
|
615
|
+
var _a, _b, _c, _d;
|
|
608
616
|
const tableRow = row;
|
|
609
617
|
if (!(tableRow === null || tableRow === void 0 ? void 0 : tableRow.id))
|
|
610
618
|
return;
|
|
@@ -654,12 +662,12 @@ export const useAdmissionModule = () => {
|
|
|
654
662
|
});
|
|
655
663
|
}
|
|
656
664
|
invalidateAdmissionsCache();
|
|
657
|
-
|
|
665
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
658
666
|
generateThemeToast({
|
|
659
|
-
description: `${t("messagesAnalyzeSuccess")} ${(
|
|
667
|
+
description: `${t("messagesAnalyzeSuccess")} ${(_c = result === null || result === void 0 ? void 0 : result.score) !== null && _c !== void 0 ? _c : "N/A"} — ${(_d = result === null || result === void 0 ? void 0 : result.status) !== null && _d !== void 0 ? _d : ""}`,
|
|
660
668
|
variant: TOAST_VARIANT.SUCCESS,
|
|
661
669
|
});
|
|
662
|
-
}, [(_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id, t, showToast, byIdFetchNow,
|
|
670
|
+
}, [(_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id, t, showToast, byIdFetchNow, dispatch]);
|
|
663
671
|
const handleSubmit = useCallback(() => {
|
|
664
672
|
dispatch({
|
|
665
673
|
type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
@@ -813,35 +821,39 @@ export const useAdmissionModule = () => {
|
|
|
813
821
|
type: ADMISSION_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
814
822
|
payload: { currentPage: 1 },
|
|
815
823
|
});
|
|
816
|
-
listFetchNow();
|
|
817
824
|
handleCloseDrawer();
|
|
818
|
-
}, [dispatch,
|
|
825
|
+
}, [dispatch, handleCloseDrawer]);
|
|
819
826
|
// ============================================================================
|
|
820
827
|
// 1.4.9 EFFECTS
|
|
821
828
|
// ============================================================================
|
|
822
829
|
// Initial load + re-fetch on page/search/filter change via cache
|
|
823
830
|
useEffect(() => {
|
|
831
|
+
var _a;
|
|
824
832
|
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
|
|
825
833
|
return;
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
834
|
+
if (isDefaultListState) {
|
|
835
|
+
(async () => {
|
|
836
|
+
try {
|
|
837
|
+
const { count, items } = await getCachedAdmissions({
|
|
838
|
+
params: listParams,
|
|
839
|
+
});
|
|
840
|
+
dispatch({
|
|
841
|
+
type: ADMISSION_ACTION_TYPES.SET_ITEMS,
|
|
842
|
+
payload: { items: items || [], count: count || 0 },
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
catch (_a) {
|
|
846
|
+
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
847
|
+
}
|
|
848
|
+
})();
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
852
|
+
}, [dispatch, isDefaultListState, listParams, workspace === null || workspace === void 0 ? void 0 : workspace.id, t, showToast]);
|
|
841
853
|
// Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
|
|
842
854
|
useEffect(() => {
|
|
843
855
|
listFetchNowRef.current = listFetchNow;
|
|
844
|
-
});
|
|
856
|
+
}, [listFetchNow]);
|
|
845
857
|
// ============================================================================
|
|
846
858
|
// 1.4.10 RETURN
|
|
847
859
|
// ============================================================================
|
|
@@ -129,7 +129,7 @@ export declare const useAttendanceModule: () => {
|
|
|
129
129
|
handleEdit: (row?: TableRow) => void;
|
|
130
130
|
handleFilters: () => void;
|
|
131
131
|
handleMoreActions: () => void;
|
|
132
|
-
handlePageChange: (
|
|
132
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
133
133
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
134
134
|
handleSearch: (query: string) => void;
|
|
135
135
|
handleSubmit: () => void;
|
|
@@ -234,12 +234,15 @@ export const useAttendanceModule = () => {
|
|
|
234
234
|
payload: { key: field, value },
|
|
235
235
|
});
|
|
236
236
|
}, [dispatch]);
|
|
237
|
-
const handlePageChange = useCallback((
|
|
237
|
+
const handlePageChange = useCallback((pageOrEvent) => {
|
|
238
|
+
const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
|
|
239
|
+
? pageOrEvent
|
|
240
|
+
: state.currentPage + 1;
|
|
238
241
|
dispatch({
|
|
239
242
|
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
240
243
|
payload: { currentPage: page },
|
|
241
244
|
});
|
|
242
|
-
}, [dispatch]);
|
|
245
|
+
}, [dispatch, state.currentPage]);
|
|
243
246
|
const handlePageLimitChange = useCallback((k, value) => {
|
|
244
247
|
const val = Object.assign({}, value);
|
|
245
248
|
dispatch({
|
|
@@ -388,32 +391,48 @@ export const useAttendanceModule = () => {
|
|
|
388
391
|
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
389
392
|
payload: { currentPage: 1 },
|
|
390
393
|
});
|
|
391
|
-
listFetchNow();
|
|
392
394
|
closeDrawer();
|
|
393
|
-
}, [dispatch,
|
|
395
|
+
}, [dispatch, closeDrawer]);
|
|
394
396
|
// ==========================================================================
|
|
395
397
|
// 1.4.9 EFFECTS
|
|
396
398
|
// ==========================================================================
|
|
399
|
+
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
400
|
+
// without depending on listFetchNow's unstable identity.
|
|
397
401
|
useEffect(() => {
|
|
398
402
|
listFetchNowRef.current = listFetchNow;
|
|
399
403
|
});
|
|
404
|
+
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
400
405
|
useEffect(() => {
|
|
406
|
+
var _a;
|
|
401
407
|
if (!schoolId)
|
|
402
408
|
return;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
409
|
+
const currentPage = Number(listParams.currentPage) || 1;
|
|
410
|
+
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
411
|
+
const isDefaultLoad = currentPage === 1 &&
|
|
412
|
+
currentPageLimit === pageLimit &&
|
|
413
|
+
!listParams.searchQuery &&
|
|
414
|
+
listParams.filterEnabled === undefined;
|
|
415
|
+
if (isDefaultLoad) {
|
|
416
|
+
(async () => {
|
|
417
|
+
try {
|
|
418
|
+
const { count, items } = await getCachedAttendances({
|
|
419
|
+
params: listParams,
|
|
420
|
+
});
|
|
421
|
+
dispatch({
|
|
422
|
+
type: ATTENDANCE_ACTION_TYPES.SET_ITEMS,
|
|
423
|
+
payload: { items: items || [], count: count || 0 },
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
catch (_a) {
|
|
427
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
428
|
+
}
|
|
429
|
+
})();
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
433
|
+
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
434
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
435
|
+
}
|
|
417
436
|
}, [listParams, dispatch, showToast, schoolId, t]);
|
|
418
437
|
// ==========================================================================
|
|
419
438
|
// 1.4.10 RETURN
|
|
@@ -134,7 +134,7 @@ export declare const useCampusModule: () => {
|
|
|
134
134
|
handleEdit: (row?: TableRow) => void;
|
|
135
135
|
handleFilters: () => void;
|
|
136
136
|
handleMoreActions: () => void;
|
|
137
|
-
handlePageChange: (
|
|
137
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
138
138
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
139
139
|
handleSearch: (query: string) => void;
|
|
140
140
|
handleSubmit: () => void;
|
|
@@ -279,12 +279,15 @@ export const useCampusModule = () => {
|
|
|
279
279
|
payload: { drawer: CAMPUS_DRAWER.MORE_ACTIONS_DRAWER },
|
|
280
280
|
});
|
|
281
281
|
}, [dispatch]);
|
|
282
|
-
const handlePageChange = useCallback((
|
|
282
|
+
const handlePageChange = useCallback((pageOrEvent) => {
|
|
283
|
+
const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
|
|
284
|
+
? pageOrEvent
|
|
285
|
+
: state.currentPage + 1;
|
|
283
286
|
dispatch({
|
|
284
287
|
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
285
288
|
payload: { currentPage: page },
|
|
286
289
|
});
|
|
287
|
-
}, [dispatch]);
|
|
290
|
+
}, [dispatch, state.currentPage]);
|
|
288
291
|
const handlePageLimitChange = useCallback((k, value) => {
|
|
289
292
|
const val = Object.assign({}, value);
|
|
290
293
|
dispatch({
|
|
@@ -313,9 +316,8 @@ export const useCampusModule = () => {
|
|
|
313
316
|
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
314
317
|
payload: { currentPage: 1 },
|
|
315
318
|
});
|
|
316
|
-
listFetchNow();
|
|
317
319
|
closeDrawer();
|
|
318
|
-
}, [dispatch,
|
|
320
|
+
}, [dispatch, closeDrawer]);
|
|
319
321
|
const clearFilters = useCallback(() => {
|
|
320
322
|
dispatch({
|
|
321
323
|
type: CAMPUS_ACTION_TYPES.SET_FILTERS,
|
|
@@ -413,27 +415,44 @@ export const useCampusModule = () => {
|
|
|
413
415
|
// ============================================================================
|
|
414
416
|
// 1.4.9 EFFECTS
|
|
415
417
|
// ============================================================================
|
|
418
|
+
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
419
|
+
// without depending on listFetchNow's unstable identity.
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
listFetchNowRef.current = listFetchNow;
|
|
422
|
+
});
|
|
423
|
+
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
416
424
|
useEffect(() => {
|
|
425
|
+
var _a;
|
|
417
426
|
if (!schoolId)
|
|
418
427
|
return;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
428
|
+
const currentPage = Number(listParams.currentPage) || 1;
|
|
429
|
+
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
430
|
+
const isDefaultLoad = currentPage === 1 &&
|
|
431
|
+
currentPageLimit === pageLimit &&
|
|
432
|
+
!listParams.searchQuery &&
|
|
433
|
+
listParams.filterEnabled === undefined;
|
|
434
|
+
if (isDefaultLoad) {
|
|
435
|
+
(async () => {
|
|
436
|
+
try {
|
|
437
|
+
const { count, items } = await getCachedCampuses({
|
|
438
|
+
params: listParams,
|
|
439
|
+
});
|
|
440
|
+
dispatch({
|
|
441
|
+
type: CAMPUS_ACTION_TYPES.SET_ITEMS,
|
|
442
|
+
payload: { items: items || [], count: count || 0 },
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
catch (_a) {
|
|
446
|
+
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
447
|
+
}
|
|
448
|
+
})();
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
452
|
+
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
453
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
454
|
+
}
|
|
433
455
|
}, [dispatch, listParams, schoolId, showToast, t]);
|
|
434
|
-
useEffect(() => {
|
|
435
|
-
listFetchNowRef.current = listFetchNow;
|
|
436
|
-
});
|
|
437
456
|
// ============================================================================
|
|
438
457
|
// 1.4.10 RETURN
|
|
439
458
|
// ============================================================================
|
|
@@ -28,7 +28,7 @@ export declare const CLASS_ACTION_TYPES: {
|
|
|
28
28
|
drawer: string | null;
|
|
29
29
|
errors: Record<string, string>;
|
|
30
30
|
code: string;
|
|
31
|
-
description: string
|
|
31
|
+
description: string;
|
|
32
32
|
enabled: boolean;
|
|
33
33
|
id: string;
|
|
34
34
|
name: string;
|
|
@@ -44,7 +44,7 @@ export declare const CLASS_ACTION_TYPES: {
|
|
|
44
44
|
drawer: string | null;
|
|
45
45
|
errors: Record<string, string>;
|
|
46
46
|
code: string;
|
|
47
|
-
description: string
|
|
47
|
+
description: string;
|
|
48
48
|
enabled: boolean;
|
|
49
49
|
id: string;
|
|
50
50
|
name: string;
|
|
@@ -62,7 +62,7 @@ export declare const CLASS_ACTION_TYPES: {
|
|
|
62
62
|
drawer: string | null;
|
|
63
63
|
errors: Record<string, string>;
|
|
64
64
|
code: string;
|
|
65
|
-
description: string
|
|
65
|
+
description: string;
|
|
66
66
|
enabled: boolean;
|
|
67
67
|
id: string;
|
|
68
68
|
name: string;
|
|
@@ -78,7 +78,7 @@ export declare const CLASS_ACTION_TYPES: {
|
|
|
78
78
|
drawer: string | null;
|
|
79
79
|
errors: Record<string, string>;
|
|
80
80
|
code: string;
|
|
81
|
-
description: string
|
|
81
|
+
description: string;
|
|
82
82
|
enabled: boolean;
|
|
83
83
|
id: string;
|
|
84
84
|
name: string;
|
|
@@ -94,7 +94,7 @@ export declare const CLASS_ACTION_TYPES: {
|
|
|
94
94
|
drawer: string | null;
|
|
95
95
|
errors: Record<string, string>;
|
|
96
96
|
code: string;
|
|
97
|
-
description: string
|
|
97
|
+
description: string;
|
|
98
98
|
enabled: boolean;
|
|
99
99
|
id: string;
|
|
100
100
|
name: string;
|
|
@@ -141,7 +141,7 @@ export declare const useClassModule: () => {
|
|
|
141
141
|
drawer: string | null;
|
|
142
142
|
errors: Record<string, string>;
|
|
143
143
|
code: string;
|
|
144
|
-
description: string
|
|
144
|
+
description: string;
|
|
145
145
|
enabled: boolean;
|
|
146
146
|
id: string;
|
|
147
147
|
name: string;
|
|
@@ -119,7 +119,7 @@ export declare const useCourseModule: () => {
|
|
|
119
119
|
handleEdit: (row?: TableRow) => void;
|
|
120
120
|
handleFilters: () => void;
|
|
121
121
|
handleMoreActions: () => void;
|
|
122
|
-
handlePageChange: (
|
|
122
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
123
123
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
124
124
|
handleSearch: (query: string) => void;
|
|
125
125
|
handleSubmit: () => void;
|
|
@@ -269,12 +269,15 @@ export const useCourseModule = () => {
|
|
|
269
269
|
payload: { key: field, value },
|
|
270
270
|
});
|
|
271
271
|
}, [dispatch]);
|
|
272
|
-
const handlePageChange = useCallback((
|
|
272
|
+
const handlePageChange = useCallback((pageOrEvent) => {
|
|
273
|
+
const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
|
|
274
|
+
? pageOrEvent
|
|
275
|
+
: state.currentPage + 1;
|
|
273
276
|
dispatch({
|
|
274
277
|
type: COURSE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
275
278
|
payload: { currentPage: page },
|
|
276
279
|
});
|
|
277
|
-
}, [dispatch]);
|
|
280
|
+
}, [dispatch, state.currentPage]);
|
|
278
281
|
const handlePageLimitChange = useCallback((k, value) => {
|
|
279
282
|
const val = Object.assign({}, value);
|
|
280
283
|
dispatch({
|
|
@@ -419,32 +422,48 @@ export const useCourseModule = () => {
|
|
|
419
422
|
type: COURSE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
420
423
|
payload: { currentPage: 1 },
|
|
421
424
|
});
|
|
422
|
-
listFetchNow();
|
|
423
425
|
closeDrawer();
|
|
424
|
-
}, [dispatch,
|
|
426
|
+
}, [dispatch, closeDrawer]);
|
|
425
427
|
// ==========================================================================
|
|
426
428
|
// 1.4.9 EFFECTS
|
|
427
429
|
// ==========================================================================
|
|
430
|
+
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
431
|
+
// without depending on listFetchNow's unstable identity.
|
|
428
432
|
useEffect(() => {
|
|
429
433
|
listFetchNowRef.current = listFetchNow;
|
|
430
434
|
});
|
|
435
|
+
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
431
436
|
useEffect(() => {
|
|
437
|
+
var _a;
|
|
432
438
|
if (!schoolId)
|
|
433
439
|
return;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
440
|
+
const currentPage = Number(listParams.currentPage) || 1;
|
|
441
|
+
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
442
|
+
const isDefaultLoad = currentPage === 1 &&
|
|
443
|
+
currentPageLimit === pageLimit &&
|
|
444
|
+
!listParams.searchQuery &&
|
|
445
|
+
listParams.filterEnabled === undefined;
|
|
446
|
+
if (isDefaultLoad) {
|
|
447
|
+
(async () => {
|
|
448
|
+
try {
|
|
449
|
+
const { count, items } = await getCachedCourses({
|
|
450
|
+
params: listParams,
|
|
451
|
+
});
|
|
452
|
+
dispatch({
|
|
453
|
+
type: COURSE_ACTION_TYPES.SET_ITEMS,
|
|
454
|
+
payload: { items: items || [], count: count || 0 },
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
catch (_a) {
|
|
458
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
459
|
+
}
|
|
460
|
+
})();
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
464
|
+
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
465
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
466
|
+
}
|
|
448
467
|
}, [listParams, dispatch, showToast, schoolId, t]);
|
|
449
468
|
// ==========================================================================
|
|
450
469
|
// 1.4.10 RETURN
|
|
@@ -120,7 +120,7 @@ export declare const useDiscountCodeModule: () => {
|
|
|
120
120
|
handleFilters: () => void;
|
|
121
121
|
handleMoreActions: () => void;
|
|
122
122
|
handleNextClick: () => void;
|
|
123
|
-
handlePageChange: (page: number) => void;
|
|
123
|
+
handlePageChange: (page: number | unknown) => void;
|
|
124
124
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
125
125
|
handlePreviousClick: () => void;
|
|
126
126
|
handleSearch: (query: string) => void;
|
|
@@ -121,6 +121,10 @@ export const useDiscountCodeModule = () => {
|
|
|
121
121
|
]);
|
|
122
122
|
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
123
123
|
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
124
|
+
const isDefaultListState = state.currentPage === 1 &&
|
|
125
|
+
state.pageLimit === pageLimit &&
|
|
126
|
+
!debouncedQuery &&
|
|
127
|
+
state.filterEnabled === undefined;
|
|
124
128
|
// ============================================================================
|
|
125
129
|
// 1.4.3 UTILITIES
|
|
126
130
|
// ============================================================================
|
|
@@ -251,11 +255,12 @@ export const useDiscountCodeModule = () => {
|
|
|
251
255
|
});
|
|
252
256
|
}, [dispatch, state.currentPage]);
|
|
253
257
|
const handlePageChange = useCallback((page) => {
|
|
258
|
+
const nextPage = typeof page === "number" ? page : state.currentPage + 1;
|
|
254
259
|
dispatch({
|
|
255
260
|
type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
256
|
-
payload: { currentPage:
|
|
261
|
+
payload: { currentPage: nextPage },
|
|
257
262
|
});
|
|
258
|
-
}, [dispatch]);
|
|
263
|
+
}, [dispatch, state.currentPage]);
|
|
259
264
|
const handlePageLimitChange = useCallback((k, value) => {
|
|
260
265
|
const val = Object.assign({}, value);
|
|
261
266
|
dispatch({
|
|
@@ -323,9 +328,8 @@ export const useDiscountCodeModule = () => {
|
|
|
323
328
|
type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
324
329
|
payload: { currentPage: 1 },
|
|
325
330
|
});
|
|
326
|
-
listFetchNow === null || listFetchNow === void 0 ? void 0 : listFetchNow();
|
|
327
331
|
closeDrawer();
|
|
328
|
-
}, [dispatch,
|
|
332
|
+
}, [dispatch, closeDrawer]);
|
|
329
333
|
const clearFilters = useCallback(() => {
|
|
330
334
|
dispatch({
|
|
331
335
|
type: DISCOUNT_CODE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
@@ -413,27 +417,32 @@ export const useDiscountCodeModule = () => {
|
|
|
413
417
|
// ============================================================================
|
|
414
418
|
// Initial load + re-fetch on page/search/filter change via cache
|
|
415
419
|
useEffect(() => {
|
|
420
|
+
var _a;
|
|
416
421
|
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
|
|
417
422
|
return;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
423
|
+
if (isDefaultListState) {
|
|
424
|
+
(async () => {
|
|
425
|
+
try {
|
|
426
|
+
const { count, items } = await getCachedDiscountCodes({
|
|
427
|
+
params: listParams,
|
|
428
|
+
});
|
|
429
|
+
dispatch({
|
|
430
|
+
type: DISCOUNT_CODE_ACTION_TYPES.SET_ITEMS,
|
|
431
|
+
payload: { items: items || [], count: count || 0 },
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
catch (_a) {
|
|
435
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
436
|
+
}
|
|
437
|
+
})();
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
441
|
+
}, [dispatch, isDefaultListState, listParams, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
433
442
|
// Keep ref in sync with latest listFetchNow (avoids stale closure in callbacks)
|
|
434
443
|
useEffect(() => {
|
|
435
444
|
listFetchNowRef.current = listFetchNow;
|
|
436
|
-
});
|
|
445
|
+
}, [listFetchNow]);
|
|
437
446
|
// ============================================================================
|
|
438
447
|
// 1.4.10 RETURN
|
|
439
448
|
// ============================================================================
|
|
@@ -129,7 +129,7 @@ export declare const useEnrollmentModule: () => {
|
|
|
129
129
|
handleEdit: (row?: TableRow) => void;
|
|
130
130
|
handleFilters: () => void;
|
|
131
131
|
handleMoreActions: () => void;
|
|
132
|
-
handlePageChange: (
|
|
132
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
133
133
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
134
134
|
handleSearch: (query: string) => void;
|
|
135
135
|
handleSubmit: () => void;
|