@appcorp/fusion-storybook 0.2.38 → 0.2.40
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.
|
@@ -25,7 +25,6 @@ import { formatNumber } from "@react-pakistan/util-functions/general/format-numb
|
|
|
25
25
|
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
26
26
|
import { CAMPUS_API_ROUTES, pageLimit } from "./constants";
|
|
27
27
|
import { campusFormValidation } from "./validate";
|
|
28
|
-
import { getCachedCampuses, invalidateCampusesCache } from "./cache";
|
|
29
28
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
30
29
|
// ============================================================================
|
|
31
30
|
// 1.1 DRAWER TYPES
|
|
@@ -86,8 +85,8 @@ export const useCampusModule = () => {
|
|
|
86
85
|
const { theme } = useTheme();
|
|
87
86
|
const workspace = getCachedWorkspaceSync();
|
|
88
87
|
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
89
|
-
const listFetchNowRef = useRef(null);
|
|
90
88
|
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
89
|
+
const listFetchNowRef = useRef(null);
|
|
91
90
|
// ============================================================================
|
|
92
91
|
// 1.4.2 API PARAMETERS
|
|
93
92
|
// ============================================================================
|
|
@@ -192,7 +191,6 @@ export const useCampusModule = () => {
|
|
|
192
191
|
}
|
|
193
192
|
if (data) {
|
|
194
193
|
const isCreated = isCreatedOrUpdated(data);
|
|
195
|
-
invalidateCampusesCache();
|
|
196
194
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
197
195
|
resetFormAndCloseDrawer();
|
|
198
196
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
@@ -220,7 +218,6 @@ export const useCampusModule = () => {
|
|
|
220
218
|
return;
|
|
221
219
|
}
|
|
222
220
|
if (data) {
|
|
223
|
-
invalidateCampusesCache();
|
|
224
221
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
225
222
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
226
223
|
}
|
|
@@ -243,7 +240,6 @@ export const useCampusModule = () => {
|
|
|
243
240
|
updateParams,
|
|
244
241
|
headers: {
|
|
245
242
|
"Content-Type": "application/json",
|
|
246
|
-
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
247
243
|
},
|
|
248
244
|
});
|
|
249
245
|
// ============================================================================
|
|
@@ -447,44 +443,13 @@ export const useCampusModule = () => {
|
|
|
447
443
|
// ============================================================================
|
|
448
444
|
// 1.4.9 EFFECTS
|
|
449
445
|
// ============================================================================
|
|
450
|
-
// Keep the latest fetch function in a ref so the fetch effect can call it
|
|
451
|
-
// without depending on listFetchNow's unstable identity.
|
|
452
446
|
useEffect(() => {
|
|
453
447
|
listFetchNowRef.current = listFetchNow;
|
|
454
|
-
});
|
|
455
|
-
// Initial load via cache; re-fetch directly from API on page/pageLimit/filter/search changes.
|
|
448
|
+
}, [listFetchNow]);
|
|
456
449
|
useEffect(() => {
|
|
457
450
|
var _a;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const currentPage = Number(listParams.currentPage) || 1;
|
|
461
|
-
const currentPageLimit = Number(listParams.pageLimit) || pageLimit;
|
|
462
|
-
const isDefaultLoad = currentPage === 1 &&
|
|
463
|
-
currentPageLimit === pageLimit &&
|
|
464
|
-
!listParams.searchQuery &&
|
|
465
|
-
listParams.filterEnabled === undefined;
|
|
466
|
-
if (isDefaultLoad) {
|
|
467
|
-
(async () => {
|
|
468
|
-
try {
|
|
469
|
-
const { count, items } = await getCachedCampuses({
|
|
470
|
-
params: listParams,
|
|
471
|
-
});
|
|
472
|
-
dispatch({
|
|
473
|
-
type: CAMPUS_ACTION_TYPES.SET_ITEMS,
|
|
474
|
-
payload: { items: items || [], count: count || 0 },
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
catch (_a) {
|
|
478
|
-
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
479
|
-
}
|
|
480
|
-
})();
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
// Bypass cache for pagination, pageLimit, filter and search changes.
|
|
484
|
-
// Use ref to avoid the infinite-loop caused by listFetchNow's unstable identity.
|
|
485
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
486
|
-
}
|
|
487
|
-
}, [dispatch, listParams, schoolId, showToast, t]);
|
|
451
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
452
|
+
}, [listParams]);
|
|
488
453
|
// ============================================================================
|
|
489
454
|
// 1.4.10 RETURN
|
|
490
455
|
// ============================================================================
|