@appcorp/fusion-storybook 0.1.77 → 0.1.79

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.
@@ -115,7 +115,7 @@ export declare const useClassModule: () => {
115
115
  handleEdit: (row?: TableRow) => void;
116
116
  handleFilters: () => void;
117
117
  handleMoreActions: () => void;
118
- handlePageChange: (page: number) => void;
118
+ handlePageChange: (pageOrEvent?: unknown) => void;
119
119
  handlePageLimitChange: (k: string, value: object) => void;
120
120
  handleSearch: (query: string) => void;
121
121
  handleSubmit: () => void;
@@ -272,12 +272,19 @@ export const useClassModule = () => {
272
272
  payload: { drawer: CLASS_DRAWER.MORE_ACTIONS_DRAWER },
273
273
  });
274
274
  }, [dispatch]);
275
- const handlePageChange = useCallback((page) => {
275
+ const handlePageChange = useCallback((pageOrEvent) => {
276
+ // The factory passes handlePageChange directly as the Next button's onClick
277
+ // handler (receiving a MouseEvent), but wraps Previous as () => handlePageChange(currentPage - 1).
278
+ // We detect which case we're in: a valid number means an explicit page target
279
+ // (Previous path); anything else means "advance to next page".
280
+ const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
281
+ ? pageOrEvent
282
+ : state.currentPage + 1;
276
283
  dispatch({
277
284
  type: CLASS_ACTION_TYPES.SET_CURRENT_PAGE,
278
285
  payload: { currentPage: page },
279
286
  });
280
- }, [dispatch]);
287
+ }, [dispatch, state.currentPage]);
281
288
  const handlePageLimitChange = useCallback((k, value) => {
282
289
  const val = Object.assign({}, value);
283
290
  dispatch({
@@ -317,9 +324,8 @@ export const useClassModule = () => {
317
324
  type: CLASS_ACTION_TYPES.SET_CURRENT_PAGE,
318
325
  payload: { currentPage: 1 },
319
326
  });
320
- listFetchNow();
321
327
  closeDrawer();
322
- }, [dispatch, listFetchNow, closeDrawer]);
328
+ }, [dispatch, closeDrawer]);
323
329
  const clearFilters = useCallback(() => {
324
330
  dispatch({
325
331
  type: CLASS_ACTION_TYPES.SET_FILTERS,
@@ -417,8 +423,18 @@ export const useClassModule = () => {
417
423
  // ============================================================================
418
424
  // 1.4.9 EFFECTS
419
425
  // ============================================================================
420
- // Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes
426
+ // Always keep the ref current so the main effect can call the latest listFetchNow
427
+ // without including it in the dependency array (listFetchNow changes identity every
428
+ // render because useModuleEntityV2 passes an inline headers object to useFetch).
429
+ // Declared first so the ref is populated before the fetch effect runs.
421
430
  useEffect(() => {
431
+ listFetchNowRef.current = listFetchNow;
432
+ });
433
+ // Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
434
+ // listFetchNow is intentionally excluded from deps — it changes every render due to the
435
+ // inline headers object in useModuleEntityV2. We call it via the stable ref instead.
436
+ useEffect(() => {
437
+ var _a;
422
438
  if (!schoolId)
423
439
  return;
424
440
  const currentPage = Number(listParams.currentPage) || 1;
@@ -444,14 +460,11 @@ export const useClassModule = () => {
444
460
  })();
445
461
  }
446
462
  else {
447
- // Bypass cache for pagination, pageLimit, filter and search changes
448
- listFetchNow();
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);
449
466
  }
450
- }, [dispatch, listFetchNow, listParams, schoolId, showToast, t]);
451
- // Sync ref to always point at latest listFetchNow (avoids stale closure in callbacks)
452
- useEffect(() => {
453
- listFetchNowRef.current = listFetchNow;
454
- });
467
+ }, [dispatch, listParams, schoolId, showToast, t]);
455
468
  // ============================================================================
456
469
  // 1.4.10 RETURN
457
470
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",