@appcorp/fusion-storybook 0.1.78 → 0.1.80

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.
Files changed (39) hide show
  1. package/base-modules/admission/context.d.ts +1 -1
  2. package/base-modules/admission/context.js +38 -26
  3. package/base-modules/attendance/context.d.ts +1 -1
  4. package/base-modules/attendance/context.js +37 -18
  5. package/base-modules/campus/context.d.ts +1 -1
  6. package/base-modules/campus/context.js +40 -21
  7. package/base-modules/class/context.js +15 -8
  8. package/base-modules/course/context.d.ts +1 -1
  9. package/base-modules/course/context.js +37 -18
  10. package/base-modules/discount-code/context.d.ts +1 -1
  11. package/base-modules/discount-code/context.js +29 -20
  12. package/base-modules/enrollment/context.d.ts +1 -1
  13. package/base-modules/enrollment/context.js +37 -18
  14. package/base-modules/expense/context.d.ts +1 -1
  15. package/base-modules/expense/context.js +31 -20
  16. package/base-modules/family/context.d.ts +1 -1
  17. package/base-modules/family/context.js +36 -21
  18. package/base-modules/family-member/context.d.ts +1 -1
  19. package/base-modules/family-member/context.js +37 -21
  20. package/base-modules/fee-structure/context.d.ts +1 -1
  21. package/base-modules/fee-structure/context.js +29 -20
  22. package/base-modules/rbac/context.d.ts +1 -1
  23. package/base-modules/rbac/context.js +26 -22
  24. package/base-modules/section/context.d.ts +1 -1
  25. package/base-modules/section/context.js +26 -19
  26. package/base-modules/student-fee/context.d.ts +1 -1
  27. package/base-modules/student-fee/context.js +30 -20
  28. package/base-modules/student-profile/context.d.ts +1 -1
  29. package/base-modules/student-profile/context.js +34 -22
  30. package/base-modules/subject/context.d.ts +2 -2
  31. package/base-modules/subject/context.js +54 -30
  32. package/base-modules/teacher/context.d.ts +1 -1
  33. package/base-modules/teacher/context.js +29 -22
  34. package/base-modules/user/context.d.ts +1 -1
  35. package/base-modules/user/context.js +27 -20
  36. package/base-modules/workspace-user/context.d.ts +1 -1
  37. package/base-modules/workspace-user/context.js +32 -19
  38. package/package.json +1 -1
  39. package/tsconfig.build.tsbuildinfo +1 -1
@@ -28,7 +28,7 @@ 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 { SECTION_API_ROUTES, pageLimit } from "./constants";
30
30
  import { sectionFormValidation } from "./validate";
31
- import { getCachedSections, getCachedSectionsSync, invalidateSectionsCache, isSectionsCacheStale, } from "./cache";
31
+ import { getCachedSections, invalidateSectionsCache } from "./cache";
32
32
  import { getCachedWorkspaceSync } from "../workspace/cache";
33
33
  // ============================================================================
34
34
  // 1.1 DRAWER TYPES
@@ -268,12 +268,15 @@ export const useSectionModule = () => {
268
268
  payload: { drawer: SECTION_DRAWER.MORE_ACTIONS_DRAWER },
269
269
  });
270
270
  }, [dispatch]);
271
- const handlePageChange = useCallback((page) => {
271
+ const handlePageChange = useCallback((pageOrEvent) => {
272
+ const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
273
+ ? pageOrEvent
274
+ : state.currentPage + 1;
272
275
  dispatch({
273
276
  type: SECTION_ACTION_TYPES.SET_CURRENT_PAGE,
274
277
  payload: { currentPage: page },
275
278
  });
276
- }, [dispatch]);
279
+ }, [dispatch, state.currentPage]);
277
280
  const handlePageLimitChange = useCallback((k, value) => {
278
281
  const val = Object.assign({}, value);
279
282
  dispatch({
@@ -313,9 +316,8 @@ export const useSectionModule = () => {
313
316
  type: SECTION_ACTION_TYPES.SET_CURRENT_PAGE,
314
317
  payload: { currentPage: 1 },
315
318
  });
316
- listFetchNow();
317
319
  closeDrawer();
318
- }, [dispatch, listFetchNow, closeDrawer]);
320
+ }, [dispatch, closeDrawer]);
319
321
  const clearFilters = useCallback(() => {
320
322
  dispatch({
321
323
  type: SECTION_ACTION_TYPES.SET_FILTERS,
@@ -413,19 +415,23 @@ export const useSectionModule = () => {
413
415
  // ============================================================================
414
416
  // 1.4.9 EFFECTS
415
417
  // ============================================================================
416
- // Initial load + re-fetch on page/search/filter change via cache
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.
417
424
  useEffect(() => {
425
+ var _a;
418
426
  if (!schoolId)
419
427
  return;
420
- const cachedData = getCachedSectionsSync();
421
- if (cachedData && !isSectionsCacheStale()) {
422
- const { count, items } = cachedData;
423
- dispatch({
424
- type: SECTION_ACTION_TYPES.SET_ITEMS,
425
- payload: { items: items || [], count: count || 0 },
426
- });
427
- }
428
- else {
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) {
429
435
  (async () => {
430
436
  try {
431
437
  const { count, items } = await getCachedSections({
@@ -441,11 +447,12 @@ export const useSectionModule = () => {
441
447
  }
442
448
  })();
443
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
+ }
444
455
  }, [dispatch, listParams, schoolId, showToast, t]);
445
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
446
- useEffect(() => {
447
- listFetchNowRef.current = listFetchNow;
448
- });
449
456
  // ============================================================================
450
457
  // 1.4.10 RETURN
451
458
  // ============================================================================
@@ -184,7 +184,7 @@ export declare const useStudentFeeModule: () => {
184
184
  handleEdit: (row?: TableRow) => void;
185
185
  handleFilters: () => void;
186
186
  handleMoreActions: () => void;
187
- handlePageChange: (page: number) => void;
187
+ handlePageChange: (page: number | unknown) => void;
188
188
  handlePageLimitChange: (k: string, value: object) => void;
189
189
  handleSearch: (query: string) => void;
190
190
  handleSubmit: () => void;
@@ -145,6 +145,11 @@ export const useStudentFeeModule = () => {
145
145
  }), [state, schoolId]);
146
146
  const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
147
147
  const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
148
+ const isDefaultListState = state.currentPage === 1 &&
149
+ state.pageLimit === pageLimit &&
150
+ !debouncedQuery &&
151
+ state.filterEnabled === undefined &&
152
+ !state.filterStatus;
148
153
  // ============================================================================
149
154
  // 1.4.3 UTILITIES
150
155
  // ============================================================================
@@ -462,11 +467,12 @@ export const useStudentFeeModule = () => {
462
467
  }
463
468
  }, [dispatch, state]);
464
469
  const handlePageChange = useCallback((page) => {
470
+ const nextPage = typeof page === "number" ? page : state.currentPage + 1;
465
471
  dispatch({
466
472
  type: STUDENT_FEE_ACTION_TYPES.SET_CURRENT_PAGE,
467
- payload: { currentPage: page },
473
+ payload: { currentPage: nextPage },
468
474
  });
469
- }, [dispatch]);
475
+ }, [dispatch, state.currentPage]);
470
476
  const handlePageLimitChange = useCallback((k, value) => {
471
477
  const { option } = Object.assign({}, value);
472
478
  dispatch({
@@ -536,9 +542,8 @@ export const useStudentFeeModule = () => {
536
542
  type: STUDENT_FEE_ACTION_TYPES.SET_CURRENT_PAGE,
537
543
  payload: { currentPage: 1 },
538
544
  });
539
- listFetchNow();
540
545
  closeDrawer();
541
- }, [dispatch, closeDrawer, listFetchNow]);
546
+ }, [dispatch, closeDrawer]);
542
547
  const clearFilters = useCallback(() => {
543
548
  dispatch({
544
549
  type: STUDENT_FEE_ACTION_TYPES.SET_CURRENT_PAGE,
@@ -632,27 +637,32 @@ export const useStudentFeeModule = () => {
632
637
  // 1.4.9 EFFECTS
633
638
  // ============================================================================
634
639
  useEffect(() => {
640
+ var _a;
635
641
  if (!schoolId)
636
642
  return;
637
- (async () => {
638
- try {
639
- const { count, items } = await getCachedStudentFees({
640
- params: listParams,
641
- });
642
- dispatch({
643
- type: STUDENT_FEE_ACTION_TYPES.SET_ITEMS,
644
- payload: { items: items || [], count: count || 0 },
645
- });
646
- }
647
- catch (_a) {
648
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
649
- }
650
- })();
651
- }, [listParams, dispatch, showToast, t]);
643
+ if (isDefaultListState) {
644
+ (async () => {
645
+ try {
646
+ const { count, items } = await getCachedStudentFees({
647
+ params: listParams,
648
+ });
649
+ dispatch({
650
+ type: STUDENT_FEE_ACTION_TYPES.SET_ITEMS,
651
+ payload: { items: items || [], count: count || 0 },
652
+ });
653
+ }
654
+ catch (_a) {
655
+ showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
656
+ }
657
+ })();
658
+ return;
659
+ }
660
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
661
+ }, [dispatch, isDefaultListState, listParams, schoolId, showToast, t]);
652
662
  // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
653
663
  useEffect(() => {
654
664
  listFetchNowRef.current = listFetchNow;
655
- });
665
+ }, [listFetchNow]);
656
666
  // ============================================================================
657
667
  // 1.4.10 RETURN
658
668
  // ============================================================================
@@ -200,7 +200,7 @@ export declare const useStudentProfileModule: () => {
200
200
  handleEdit: (row?: TableRow) => void;
201
201
  handleFilters: () => void;
202
202
  handleMoreActions: () => void;
203
- handlePageChange: (page: number) => void;
203
+ handlePageChange: (page: number | unknown) => void;
204
204
  handlePageLimitChange: (k: string, value: object) => void;
205
205
  handleReAdmitStudent: (row?: TableRow) => Promise<void>;
206
206
  handleSearch: (query: string) => void;
@@ -158,6 +158,12 @@ export const useStudentProfileModule = () => {
158
158
  ]);
159
159
  const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
160
160
  const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
161
+ const isDefaultListState = state.currentPage === 1 &&
162
+ state.pageLimit === pageLimit &&
163
+ !debouncedQuery &&
164
+ state.filterEnabled === undefined &&
165
+ !state.filterGender &&
166
+ !state.filterStatus;
161
167
  // ============================================================================
162
168
  // 1.4.3 UTILITIES
163
169
  // ============================================================================
@@ -348,11 +354,12 @@ export const useStudentProfileModule = () => {
348
354
  });
349
355
  }, [dispatch]);
350
356
  const handlePageChange = useCallback((page) => {
357
+ const nextPage = typeof page === "number" ? page : state.currentPage + 1;
351
358
  dispatch({
352
359
  type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
353
- payload: { currentPage: page },
360
+ payload: { currentPage: nextPage },
354
361
  });
355
- }, [dispatch]);
362
+ }, [dispatch, state.currentPage]);
356
363
  const handlePageLimitChange = useCallback((k, value) => {
357
364
  const val = Object.assign({}, value);
358
365
  dispatch({
@@ -392,9 +399,8 @@ export const useStudentProfileModule = () => {
392
399
  type: STUDENT_PROFILE_ACTION_TYPES.SET_CURRENT_PAGE,
393
400
  payload: { currentPage: 1 },
394
401
  });
395
- listFetchNow();
396
402
  closeDrawer();
397
- }, [dispatch, listFetchNow, closeDrawer]);
403
+ }, [dispatch, closeDrawer]);
398
404
  const clearFilters = useCallback(() => {
399
405
  dispatch({
400
406
  type: STUDENT_PROFILE_ACTION_TYPES.SET_FILTERS,
@@ -433,6 +439,7 @@ export const useStudentProfileModule = () => {
433
439
  invalidateAdmissionsCache();
434
440
  }, [dispatch, t]);
435
441
  const handleReAdmitStudent = useCallback(async (row) => {
442
+ var _a;
436
443
  if (!confirm(t("areYouSureYouWantToReAdmitThisStudent")))
437
444
  return;
438
445
  const { data, error } = await fetchData({
@@ -444,7 +451,7 @@ export const useStudentProfileModule = () => {
444
451
  },
445
452
  body: JSON.stringify({ studentProfileId: row === null || row === void 0 ? void 0 : row.id }),
446
453
  });
447
- listFetchNow();
454
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
448
455
  invalidateStudentProfilesCache();
449
456
  invalidateFamiliesCache();
450
457
  invalidateFamilyMembersCache();
@@ -455,7 +462,7 @@ export const useStudentProfileModule = () => {
455
462
  if (error) {
456
463
  showToast(t("messagesReAdmitFailed"), TOAST_VARIANT.ERROR);
457
464
  }
458
- }, [showToast, t, listFetchNow]);
465
+ }, [showToast, t]);
459
466
  // ============================================================================
460
467
  // 1.4.7 SUBMIT
461
468
  // ============================================================================
@@ -553,27 +560,32 @@ export const useStudentProfileModule = () => {
553
560
  // ============================================================================
554
561
  // Initial load + re-fetch on page/search/filter change via cache
555
562
  useEffect(() => {
563
+ var _a;
556
564
  if (!schoolId)
557
565
  return;
558
- (async () => {
559
- try {
560
- const { count, items } = await getCachedStudentProfiles({
561
- params: listParams,
562
- });
563
- dispatch({
564
- type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
565
- payload: { items: items || [], count: count || 0 },
566
- });
567
- }
568
- catch (_a) {
569
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
570
- }
571
- })();
572
- }, [dispatch, listParams, schoolId, showToast, t]);
566
+ if (isDefaultListState) {
567
+ (async () => {
568
+ try {
569
+ const { count, items } = await getCachedStudentProfiles({
570
+ params: listParams,
571
+ });
572
+ dispatch({
573
+ type: STUDENT_PROFILE_ACTION_TYPES.SET_ITEMS,
574
+ payload: { items: items || [], count: count || 0 },
575
+ });
576
+ }
577
+ catch (_a) {
578
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
579
+ }
580
+ })();
581
+ return;
582
+ }
583
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
584
+ }, [dispatch, isDefaultListState, listParams, schoolId, showToast, t]);
573
585
  // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
574
586
  useEffect(() => {
575
587
  listFetchNowRef.current = listFetchNow;
576
- });
588
+ }, [listFetchNow]);
577
589
  // ============================================================================
578
590
  // 1.4.10 RETURN
579
591
  // ============================================================================
@@ -114,8 +114,8 @@ export declare const useSubjectModule: () => {
114
114
  handleEdit: (row?: TableRow) => void;
115
115
  handleFilters: () => void;
116
116
  handleMoreActions: () => void;
117
- handlePageChange: (page: number) => void;
118
- handlePageLimitChange: (limit: number) => void;
117
+ handlePageChange: (pageOrEvent?: unknown) => void;
118
+ handlePageLimitChange: (k: string, value: object) => void;
119
119
  handleSearch: (query: string) => void;
120
120
  handleSubmit: () => void;
121
121
  handleView: (row?: TableRow) => void;
@@ -194,27 +194,6 @@ export const useSubjectModule = () => {
194
194
  }
195
195
  }, [showToast, t]);
196
196
  // ============================================================================
197
- // INITIAL DATA LOADING (sync cache to prevent UI hanging)
198
- // ============================================================================
199
- useEffect(() => {
200
- if (!schoolId)
201
- return;
202
- (async () => {
203
- try {
204
- const { count, items } = await getCachedSubjects({
205
- params: listParams,
206
- });
207
- dispatch({
208
- type: SUBJECT_ACTION_TYPES.SET_ITEMS,
209
- payload: { items: items || [], count: count || 0 },
210
- });
211
- }
212
- catch (_a) {
213
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
214
- }
215
- })();
216
- }, [dispatch, listParams, schoolId, showToast, t]);
217
- // ============================================================================
218
197
  // API HOOKS
219
198
  // ============================================================================
220
199
  const { listFetchNow, listLoading, updateFetchNow, updateLoading, byIdFetchNow, deleteFetchNow, deleteLoading, byIdLoading, } = useModuleEntityV2({
@@ -235,9 +214,6 @@ export const useSubjectModule = () => {
235
214
  "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
236
215
  },
237
216
  });
238
- useEffect(() => {
239
- listFetchNowRef.current = listFetchNow;
240
- });
241
217
  // ============================================================================
242
218
  // HANDLERS
243
219
  // ============================================================================
@@ -264,16 +240,24 @@ export const useSubjectModule = () => {
264
240
  payload: { key: field, value },
265
241
  });
266
242
  }, [dispatch]);
267
- const handlePageChange = useCallback((page) => {
243
+ const handlePageChange = useCallback((pageOrEvent) => {
244
+ const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
245
+ ? pageOrEvent
246
+ : state.currentPage + 1;
268
247
  dispatch({
269
248
  type: SUBJECT_ACTION_TYPES.SET_CURRENT_PAGE,
270
249
  payload: { currentPage: page },
271
250
  });
272
- }, [dispatch]);
273
- const handlePageLimitChange = useCallback((limit) => {
251
+ }, [dispatch, state.currentPage]);
252
+ const handlePageLimitChange = useCallback((k, value) => {
253
+ const val = Object.assign({}, value);
274
254
  dispatch({
275
255
  type: SUBJECT_ACTION_TYPES.SET_PAGE_LIMIT,
276
- payload: { pageLimit: limit },
256
+ payload: { pageLimit: Number(val.option) },
257
+ });
258
+ dispatch({
259
+ type: SUBJECT_ACTION_TYPES.SET_CURRENT_PAGE,
260
+ payload: { currentPage: 1 },
277
261
  });
278
262
  }, [dispatch]);
279
263
  const handleCreate = useCallback(() => {
@@ -415,9 +399,49 @@ export const useSubjectModule = () => {
415
399
  type: SUBJECT_ACTION_TYPES.SET_CURRENT_PAGE,
416
400
  payload: { currentPage: 1 },
417
401
  });
418
- listFetchNow();
419
402
  closeDrawer();
420
- }, [dispatch, listFetchNow, closeDrawer]);
403
+ }, [dispatch, closeDrawer]);
404
+ // ============================================================================
405
+ // EFFECTS
406
+ // ============================================================================
407
+ // Keep the latest fetch function in a ref so the fetch effect can call it
408
+ // without depending on listFetchNow's unstable identity.
409
+ useEffect(() => {
410
+ listFetchNowRef.current = listFetchNow;
411
+ });
412
+ // Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
413
+ useEffect(() => {
414
+ var _a;
415
+ if (!schoolId)
416
+ return;
417
+ const currentPage = Number(listParams.currentPage) || 1;
418
+ const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
419
+ const isDefaultLoad = currentPage === 1 &&
420
+ currentPageLimit === pageLimit &&
421
+ !listParams.searchQuery &&
422
+ listParams.filterEnabled === undefined;
423
+ if (isDefaultLoad) {
424
+ (async () => {
425
+ try {
426
+ const { count, items } = await getCachedSubjects({
427
+ params: listParams,
428
+ });
429
+ dispatch({
430
+ type: SUBJECT_ACTION_TYPES.SET_ITEMS,
431
+ payload: { items: items || [], count: count || 0 },
432
+ });
433
+ }
434
+ catch (_a) {
435
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
436
+ }
437
+ })();
438
+ }
439
+ else {
440
+ // Bypass cache for pagination, pageLimit, filter and search changes.
441
+ // Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
442
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
443
+ }
444
+ }, [dispatch, listParams, schoolId, showToast, t]);
421
445
  // ============================================================================
422
446
  // RETURN
423
447
  // ============================================================================
@@ -195,7 +195,7 @@ export declare const useTeacherModule: () => {
195
195
  handleEdit: (row?: TableRow) => void;
196
196
  handleFilters: () => void;
197
197
  handleMoreActions: () => void;
198
- handlePageChange: (page: number) => void;
198
+ handlePageChange: (page: number | unknown) => void;
199
199
  handlePageLimitChange: (k: string, value: object) => void;
200
200
  handleSearch: (query: string) => void;
201
201
  handleSubmit: () => void;
@@ -143,6 +143,10 @@ export const useTeacherModule = () => {
143
143
  }), [state, schoolId]);
144
144
  const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
145
145
  const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
146
+ const isDefaultListState = state.currentPage === 1 &&
147
+ state.pageLimit === pageLimit &&
148
+ !debouncedQuery &&
149
+ state.filterEnabled === undefined;
146
150
  // ============================================================================
147
151
  // 1.4.3 UTILITIES
148
152
  // ============================================================================
@@ -306,11 +310,12 @@ export const useTeacherModule = () => {
306
310
  });
307
311
  }, [dispatch]);
308
312
  const handlePageChange = useCallback((page) => {
313
+ const nextPage = typeof page === "number" ? page : state.currentPage + 1;
309
314
  dispatch({
310
315
  type: TEACHER_ACTION_TYPES.SET_CURRENT_PAGE,
311
- payload: { currentPage: page },
316
+ payload: { currentPage: nextPage },
312
317
  });
313
- }, [dispatch]);
318
+ }, [dispatch, state.currentPage]);
314
319
  const handlePageLimitChange = useCallback((k, value) => {
315
320
  const val = Object.assign({}, value);
316
321
  dispatch({
@@ -350,9 +355,8 @@ export const useTeacherModule = () => {
350
355
  type: TEACHER_ACTION_TYPES.SET_CURRENT_PAGE,
351
356
  payload: { currentPage: 1 },
352
357
  });
353
- listFetchNow();
354
358
  closeDrawer();
355
- }, [dispatch, listFetchNow, closeDrawer]);
359
+ }, [dispatch, closeDrawer]);
356
360
  const clearFilters = useCallback(() => {
357
361
  dispatch({
358
362
  type: TEACHER_ACTION_TYPES.SET_FILTERS,
@@ -450,29 +454,32 @@ export const useTeacherModule = () => {
450
454
  // ============================================================================
451
455
  // 1.4.9 EFFECTS
452
456
  // ============================================================================
453
- // Initial load + re-fetch on page/search/filter change via cache
454
457
  useEffect(() => {
458
+ var _a;
455
459
  if (!schoolId)
456
460
  return;
457
- (async () => {
458
- try {
459
- const { count, items } = await getCachedTeachers({
460
- params: listParams,
461
- });
462
- dispatch({
463
- type: TEACHER_ACTION_TYPES.SET_ITEMS,
464
- payload: { items: items || [], count: count || 0 },
465
- });
466
- }
467
- catch (_a) {
468
- showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
469
- }
470
- })();
471
- }, [dispatch, listParams, schoolId, showToast, t]);
472
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
461
+ if (isDefaultListState) {
462
+ (async () => {
463
+ try {
464
+ const { count, items } = await getCachedTeachers({
465
+ params: listParams,
466
+ });
467
+ dispatch({
468
+ type: TEACHER_ACTION_TYPES.SET_ITEMS,
469
+ payload: { items: items || [], count: count || 0 },
470
+ });
471
+ }
472
+ catch (_a) {
473
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
474
+ }
475
+ })();
476
+ return;
477
+ }
478
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
479
+ }, [dispatch, isDefaultListState, listParams, schoolId, showToast, t]);
473
480
  useEffect(() => {
474
481
  listFetchNowRef.current = listFetchNow;
475
- });
482
+ }, [listFetchNow]);
476
483
  // ============================================================================
477
484
  // 1.4.10 RETURN
478
485
  // ============================================================================
@@ -125,7 +125,7 @@ export declare const useUserModule: () => {
125
125
  handleEdit: (row?: TableRow) => void;
126
126
  handleFilters: () => void;
127
127
  handleMoreActions: () => void;
128
- handlePageChange: (page: number) => void;
128
+ handlePageChange: (page: number | unknown) => void;
129
129
  handlePageLimitChange: (k: string, value: object) => void;
130
130
  handleSearch: (query: string) => void;
131
131
  handleSubmit: () => Promise<void>;
@@ -117,6 +117,10 @@ export const useUserModule = () => {
117
117
  }), [state, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
118
118
  const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
119
119
  const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
120
+ const isDefaultListState = state.currentPage === 1 &&
121
+ state.pageLimit === pageLimit &&
122
+ !debouncedQuery &&
123
+ state.filterEnabled === undefined;
120
124
  // ============================================================================
121
125
  // 1.4.3 UTILITIES
122
126
  // ============================================================================
@@ -314,11 +318,12 @@ export const useUserModule = () => {
314
318
  });
315
319
  }, [dispatch]);
316
320
  const handlePageChange = useCallback((page) => {
321
+ const nextPage = typeof page === "number" ? page : state.currentPage + 1;
317
322
  dispatch({
318
323
  type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
319
- payload: { currentPage: page },
324
+ payload: { currentPage: nextPage },
320
325
  });
321
- }, [dispatch]);
326
+ }, [dispatch, state.currentPage]);
322
327
  const handlePageLimitChange = useCallback((k, value) => {
323
328
  const val = Object.assign({}, value);
324
329
  dispatch({
@@ -358,9 +363,8 @@ export const useUserModule = () => {
358
363
  type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
359
364
  payload: { currentPage: 1 },
360
365
  });
361
- listFetchNow();
362
366
  closeDrawer();
363
- }, [dispatch, listFetchNow, closeDrawer]);
367
+ }, [dispatch, closeDrawer]);
364
368
  const clearFilters = useCallback(() => {
365
369
  dispatch({
366
370
  type: USER_ACTION_TYPES.SET_FILTERS,
@@ -550,27 +554,30 @@ export const useUserModule = () => {
550
554
  // ============================================================================
551
555
  // 1.4.9 EFFECTS
552
556
  // ============================================================================
553
- // Initial load + re-fetch on page/search/filter change via cache
554
557
  useEffect(() => {
558
+ var _a;
555
559
  if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
556
560
  return;
557
- (async () => {
558
- try {
559
- const { count, items } = await getCachedUsers({ params: listParams });
560
- dispatch({
561
- type: USER_ACTION_TYPES.SET_ITEMS,
562
- payload: { items: items || [], count: count || 0 },
563
- });
564
- }
565
- catch (_a) {
566
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
567
- }
568
- })();
569
- }, [dispatch, listParams, workspace === null || workspace === void 0 ? void 0 : workspace.id, showToast, t]);
570
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
561
+ if (isDefaultListState) {
562
+ (async () => {
563
+ try {
564
+ const { count, items } = await getCachedUsers({ params: listParams });
565
+ dispatch({
566
+ type: USER_ACTION_TYPES.SET_ITEMS,
567
+ payload: { items: items || [], count: count || 0 },
568
+ });
569
+ }
570
+ catch (_a) {
571
+ showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
572
+ }
573
+ })();
574
+ return;
575
+ }
576
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
577
+ }, [dispatch, isDefaultListState, listParams, workspace === null || workspace === void 0 ? void 0 : workspace.id, showToast, t]);
571
578
  useEffect(() => {
572
579
  listFetchNowRef.current = listFetchNow;
573
- });
580
+ }, [listFetchNow]);
574
581
  // ============================================================================
575
582
  // 1.4.10 RETURN
576
583
  // ============================================================================
@@ -137,7 +137,7 @@ export declare const useWorkspaceUserModule: () => {
137
137
  handleEdit: () => void;
138
138
  handleFilters: () => void;
139
139
  handleMoreActions: () => void;
140
- handlePageChange: (page: number) => void;
140
+ handlePageChange: (page: number | unknown) => void;
141
141
  handlePageLimitChange: (limit: number) => void;
142
142
  handleSearch: (query: string) => void;
143
143
  handleSubmit: () => void;