@appcorp/fusion-storybook 0.5.11 → 0.5.15

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 (41) hide show
  1. package/base-modules/campus/context/use-campus-module.d.ts +57 -0
  2. package/base-modules/campus/context/use-campus-module.js +447 -0
  3. package/base-modules/campus/context.d.ts +21 -54
  4. package/base-modules/campus/context.js +18 -442
  5. package/base-modules/campus/filter.js +1 -1
  6. package/base-modules/campus/form.js +6 -4
  7. package/base-modules/campus/page.d.ts +0 -2
  8. package/base-modules/campus/page.js +10 -18
  9. package/base-modules/campus/validate.js +4 -1
  10. package/base-modules/campus/view.js +2 -2
  11. package/base-modules/class/context/use-class-module.d.ts +55 -0
  12. package/base-modules/class/context/use-class-module.js +421 -0
  13. package/base-modules/class/context.d.ts +27 -52
  14. package/base-modules/class/context.js +18 -415
  15. package/base-modules/class/filter.js +16 -6
  16. package/base-modules/class/form.js +19 -3
  17. package/base-modules/class/more-actions.js +48 -10
  18. package/base-modules/class/page.js +15 -5
  19. package/base-modules/class/validate.d.ts +2 -2
  20. package/base-modules/class/validate.js +7 -3
  21. package/base-modules/class/view.js +2 -4
  22. package/base-modules/discount-code/context/use-discount-code-module.d.ts +65 -0
  23. package/base-modules/discount-code/context/use-discount-code-module.js +402 -0
  24. package/base-modules/discount-code/context.d.ts +32 -80
  25. package/base-modules/discount-code/context.js +14 -430
  26. package/base-modules/discount-code/filter.d.ts +1 -10
  27. package/base-modules/discount-code/filter.js +34 -8
  28. package/base-modules/discount-code/form.js +9 -35
  29. package/base-modules/discount-code/page.js +39 -19
  30. package/base-modules/discount-code/validate.d.ts +2 -1
  31. package/base-modules/discount-code/validate.js +10 -3
  32. package/base-modules/discount-code/view.js +15 -4
  33. package/constants.d.ts +4 -2
  34. package/package.json +1 -1
  35. package/tsconfig.build.tsbuildinfo +1 -1
  36. package/types/user-management.d.ts +0 -1
  37. package/utils/resolve-rbac-permissions.js +10 -7
  38. package/base-modules/campus/more-actions.d.ts +0 -1
  39. package/base-modules/campus/more-actions.js +0 -40
  40. package/base-modules/discount-code/more-actions.d.ts +0 -9
  41. package/base-modules/discount-code/more-actions.js +0 -13
@@ -0,0 +1,57 @@
1
+ import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
2
+ import { CampusBE } from "../../../type";
3
+ export declare const useCampusModule: () => {
4
+ applyFilters: () => void;
5
+ byIdLoading: boolean;
6
+ clearFilters: () => void;
7
+ clearSearch: () => void;
8
+ closeDrawer: () => void;
9
+ deleteLoading: boolean;
10
+ handleChange: (field: string, value: string | number | boolean | undefined | null) => void;
11
+ handleCreate: () => void;
12
+ handleDelete: (row?: TableRow) => void;
13
+ handleEdit: (row?: TableRow) => void;
14
+ handleFilters: () => void;
15
+ handlePageChange: (pageOrEvent?: unknown) => void;
16
+ handlePageLimitChange: (k: string, value: object) => void;
17
+ handleSearch: (query: string) => void;
18
+ handleSubmit: () => void;
19
+ handleView: (row?: TableRow) => void;
20
+ headerActions: {
21
+ enabled: boolean;
22
+ handleOnClick: () => void;
23
+ label: string;
24
+ order: number;
25
+ }[];
26
+ listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
27
+ listLoading: boolean;
28
+ rowActions: RowAction[];
29
+ updateLoading: boolean;
30
+ handleCloseDrawer?: () => void;
31
+ state: {
32
+ items: CampusBE[];
33
+ count: number;
34
+ currentPage: number;
35
+ pageLimit: number;
36
+ searchQuery: string;
37
+ disableSaveButton: boolean;
38
+ drawer: string | null;
39
+ errors: Record<string, string>;
40
+ address: string | null;
41
+ city: string | null;
42
+ code: string;
43
+ country: string | null;
44
+ enabled: boolean;
45
+ id: string;
46
+ name: string;
47
+ phone: string | null;
48
+ schoolId: string;
49
+ state: string | null;
50
+ filterEnabled: boolean | undefined;
51
+ appliedFilterEnabled: boolean | undefined;
52
+ classCount: number;
53
+ teacherCount: number;
54
+ studentCount: number;
55
+ };
56
+ dispatch: React.Dispatch<any>;
57
+ };
@@ -0,0 +1,447 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ /**
14
+ * Campus module business logic.
15
+ *
16
+ * Lives beside the module config so it can be unit-tested without pulling in
17
+ * the page/components (and their ESM-only UI package).
18
+ */
19
+ import { useCallback, useEffect, useMemo, useRef } from "react";
20
+ import { useTheme } from "next-themes";
21
+ import { useTranslations } from "next-intl";
22
+ import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
23
+ import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
24
+ import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
25
+ import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
26
+ import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
27
+ import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
28
+ import { toE164Phone } from "../../../utils/to-e164-phone";
29
+ import { CAMPUS_API_ROUTES } from "../../../constants";
30
+ import { campusFormValidation } from "../validate";
31
+ import { getCachedWorkspaceSync } from "../../workspace/cache";
32
+ import { CAMPUS_ACTION_TYPES, CAMPUS_DRAWER, useCampusContext, } from "../context";
33
+ // ============================================================================
34
+ // ENHANCED CAMPUS HOOK WITH API INTEGRATION
35
+ // ============================================================================
36
+ export const useCampusModule = () => {
37
+ var _a, _b, _c, _d, _e, _f;
38
+ // ============================================================================
39
+ // 1.4.1 STATE & CORE HOOKS
40
+ // ============================================================================
41
+ const context = useCampusContext();
42
+ const { dispatch } = context;
43
+ const state = context.state;
44
+ const t = useTranslations("campus");
45
+ const { theme } = useTheme();
46
+ const workspace = getCachedWorkspaceSync();
47
+ const debouncedQuery = useDebounce(state.searchQuery, 800);
48
+ const listFetchNowRef = useRef(null);
49
+ // ============================================================================
50
+ // 1.4.2 API PARAMETERS
51
+ // ============================================================================
52
+ const listParams = useMemo(() => {
53
+ var _a;
54
+ return (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "" }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
55
+ ? { filterEnabled: String(state.appliedFilterEnabled) }
56
+ : {})));
57
+ }, [
58
+ state.appliedFilterEnabled,
59
+ state.currentPage,
60
+ state.pageLimit,
61
+ debouncedQuery,
62
+ (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
63
+ ]);
64
+ const updateParams = useMemo(() => {
65
+ var _a, _b;
66
+ return ({
67
+ address: state.address,
68
+ city: state.city,
69
+ code: state.code,
70
+ country: state.country,
71
+ enabled: state.enabled,
72
+ id: state.id,
73
+ name: state.name,
74
+ phone: toE164Phone(state.phone, (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country),
75
+ schoolId: state.schoolId || ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id) || "",
76
+ state: state.state,
77
+ });
78
+ }, [
79
+ state.address,
80
+ state.city,
81
+ state.code,
82
+ state.country,
83
+ state.enabled,
84
+ state.id,
85
+ state.name,
86
+ state.phone,
87
+ state.schoolId,
88
+ state.state,
89
+ (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.country,
90
+ (_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id,
91
+ ]);
92
+ // Single-record calls must carry the tenant: the API/tenant guard cannot
93
+ // scope an id-only request.
94
+ const byIdParams = useMemo(() => { var _a; return ({ id: state.id, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id }); }, [state.id, (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id]);
95
+ const deleteParams = useMemo(() => { var _a; return ({ id: state.id, schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id }); }, [state.id, (_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.id]);
96
+ // ============================================================================
97
+ // 1.4.3 UTILITIES
98
+ // ============================================================================
99
+ const showToast = useCallback((description, variant) => {
100
+ generateThemeToast({
101
+ description,
102
+ theme: theme,
103
+ variant,
104
+ });
105
+ }, [theme]);
106
+ /**
107
+ * Clear the form fields without touching the list filters (RESET_FORM would
108
+ * also reset the applied filter, so saving a record would drop it), and
109
+ * pre-fill the location with the school's address.
110
+ */
111
+ const resetFormFields = useCallback(() => {
112
+ var _a, _b, _c;
113
+ const school = workspace === null || workspace === void 0 ? void 0 : workspace.school;
114
+ dispatch({
115
+ type: CAMPUS_ACTION_TYPES.SET_FORM_DATA,
116
+ payload: {
117
+ form: {
118
+ address: null,
119
+ city: (_a = school === null || school === void 0 ? void 0 : school.city) !== null && _a !== void 0 ? _a : null,
120
+ code: "",
121
+ country: (_b = school === null || school === void 0 ? void 0 : school.country) !== null && _b !== void 0 ? _b : null,
122
+ enabled: true,
123
+ id: "",
124
+ name: "",
125
+ phone: null,
126
+ schoolId: (school === null || school === void 0 ? void 0 : school.id) || "",
127
+ state: (_c = school === null || school === void 0 ? void 0 : school.state) !== null && _c !== void 0 ? _c : null,
128
+ },
129
+ },
130
+ });
131
+ dispatch({
132
+ type: CAMPUS_ACTION_TYPES.SET_ERRORS,
133
+ payload: { errors: {} },
134
+ });
135
+ dispatch({
136
+ type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
137
+ payload: { disabled: false },
138
+ });
139
+ }, [dispatch, workspace === null || workspace === void 0 ? void 0 : workspace.school]);
140
+ const resetFormAndCloseDrawer = useCallback(() => {
141
+ resetFormFields();
142
+ dispatch({
143
+ type: CAMPUS_ACTION_TYPES.SET_DRAWER,
144
+ payload: { drawer: null },
145
+ });
146
+ }, [dispatch, resetFormFields]);
147
+ const resetRecordFormState = useCallback(() => {
148
+ resetFormFields();
149
+ }, [resetFormFields]);
150
+ // ============================================================================
151
+ // 1.4.4 API CALLBACKS
152
+ // ============================================================================
153
+ const listCallback = useCallback(({ data, error }) => {
154
+ var _a, _b;
155
+ if (error) {
156
+ showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
157
+ return;
158
+ }
159
+ if (data) {
160
+ const response = data;
161
+ dispatch({
162
+ type: CAMPUS_ACTION_TYPES.SET_ITEMS,
163
+ payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
164
+ });
165
+ }
166
+ }, [dispatch, showToast, t]);
167
+ const updateCallback = useCallback(({ data, error }) => {
168
+ if (error) {
169
+ showToast(t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
170
+ return;
171
+ }
172
+ if (data) {
173
+ const isCreated = isCreatedOrUpdated(data);
174
+ showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
175
+ // `useModuleEntityV2` already schedules a debounced list refresh.
176
+ resetFormAndCloseDrawer();
177
+ }
178
+ }, [resetFormAndCloseDrawer, showToast, t]);
179
+ const byIdCallback = useCallback(({ data, error }) => {
180
+ var _a, _b, _c, _d, _e, _f;
181
+ if (error) {
182
+ showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
183
+ return;
184
+ }
185
+ if (data) {
186
+ const campus = data;
187
+ dispatch({
188
+ type: CAMPUS_ACTION_TYPES.SET_FORM_DATA,
189
+ payload: {
190
+ form: Object.assign(Object.assign({}, campus), { classCount: (_b = (_a = campus._count) === null || _a === void 0 ? void 0 : _a.classes) !== null && _b !== void 0 ? _b : 0, teacherCount: (_d = (_c = campus._count) === null || _c === void 0 ? void 0 : _c.teachers) !== null && _d !== void 0 ? _d : 0, studentCount: (_f = (_e = campus._count) === null || _e === void 0 ? void 0 : _e.studentProfiles) !== null && _f !== void 0 ? _f : 0, phone: formatPhoneDisplay(campus.phone) || "" }),
191
+ },
192
+ });
193
+ }
194
+ }, [dispatch, showToast, t]);
195
+ const deleteCallback = useCallback(({ data, error }) => {
196
+ if (error) {
197
+ showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
198
+ return;
199
+ }
200
+ if (data) {
201
+ showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
202
+ }
203
+ }, [showToast, t]);
204
+ // ============================================================================
205
+ // 1.4.5 API HOOKS
206
+ // ============================================================================
207
+ const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
208
+ byIdCallback,
209
+ byIdParams,
210
+ deleteCallback,
211
+ deleteParams,
212
+ listCallback,
213
+ listParams,
214
+ listUrl: CAMPUS_API_ROUTES.UNIT,
215
+ searchQuery: debouncedQuery,
216
+ unitByIdUrl: CAMPUS_API_ROUTES.UNIT,
217
+ unitUrl: CAMPUS_API_ROUTES.UNIT,
218
+ updateCallback,
219
+ updateParams,
220
+ headers: {
221
+ "Content-Type": "application/json",
222
+ },
223
+ });
224
+ // ============================================================================
225
+ // 1.4.6 HANDLERS
226
+ // ============================================================================
227
+ const handleChange = useCallback((field, value) => {
228
+ let formatted = value;
229
+ if (field === "code" && typeof value === "string") {
230
+ formatted = value.toUpperCase();
231
+ }
232
+ dispatch({
233
+ type: CAMPUS_ACTION_TYPES.SET_ERRORS,
234
+ payload: { errors: {} },
235
+ });
236
+ dispatch({
237
+ type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
238
+ payload: { disabled: false },
239
+ });
240
+ dispatch({
241
+ type: CAMPUS_ACTION_TYPES.SET_INPUT_FIELD,
242
+ payload: { key: field, value: formatted !== null && formatted !== void 0 ? formatted : value },
243
+ });
244
+ }, [dispatch]);
245
+ const closeDrawer = useCallback(() => {
246
+ resetFormAndCloseDrawer();
247
+ }, [resetFormAndCloseDrawer]);
248
+ const handleCreate = useCallback(() => {
249
+ // Never carry a previous record's id/values into a new entry.
250
+ resetFormFields();
251
+ dispatch({
252
+ type: CAMPUS_ACTION_TYPES.SET_DRAWER,
253
+ payload: { drawer: CAMPUS_DRAWER.FORM_DRAWER },
254
+ });
255
+ }, [dispatch, resetFormFields]);
256
+ const handleView = useCallback((row) => {
257
+ resetRecordFormState();
258
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
259
+ dispatch({
260
+ type: CAMPUS_ACTION_TYPES.SET_DRAWER,
261
+ payload: { drawer: CAMPUS_DRAWER.VIEW_DRAWER },
262
+ });
263
+ }, [byIdFetchNow, dispatch, resetRecordFormState]);
264
+ const handleEdit = useCallback((row) => {
265
+ resetRecordFormState();
266
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
267
+ dispatch({
268
+ type: CAMPUS_ACTION_TYPES.SET_DRAWER,
269
+ payload: { drawer: CAMPUS_DRAWER.FORM_DRAWER },
270
+ });
271
+ }, [byIdFetchNow, dispatch, resetRecordFormState]);
272
+ const handleDelete = useCallback((row) => {
273
+ var _a;
274
+ if (!confirm(t("messagesDeleteConfirmation")))
275
+ return;
276
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
277
+ body: JSON.stringify({
278
+ id: row === null || row === void 0 ? void 0 : row.id,
279
+ schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
280
+ }),
281
+ });
282
+ }, [deleteFetchNow, t, (_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id]);
283
+ const handleFilters = useCallback(() => {
284
+ dispatch({
285
+ type: CAMPUS_ACTION_TYPES.SET_DRAWER,
286
+ payload: { drawer: CAMPUS_DRAWER.FILTER_DRAWER },
287
+ });
288
+ }, [dispatch]);
289
+ const handlePageChange = useCallback((pageOrEvent) => {
290
+ const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
291
+ ? pageOrEvent
292
+ : state.currentPage + 1;
293
+ dispatch({
294
+ type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
295
+ payload: { currentPage: page },
296
+ });
297
+ }, [dispatch, state.currentPage]);
298
+ const handlePageLimitChange = useCallback((k, value) => {
299
+ const val = Object.assign({}, value);
300
+ dispatch({
301
+ type: CAMPUS_ACTION_TYPES.SET_PAGE_LIMIT,
302
+ payload: { pageLimit: Number(val.option) },
303
+ });
304
+ dispatch({
305
+ type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
306
+ payload: { currentPage: 1 },
307
+ });
308
+ }, [dispatch]);
309
+ const handleSearch = useCallback((query) => {
310
+ dispatch({
311
+ type: CAMPUS_ACTION_TYPES.SET_SEARCH_QUERY,
312
+ payload: { searchQuery: query },
313
+ });
314
+ }, [dispatch]);
315
+ const clearSearch = useCallback(() => {
316
+ dispatch({
317
+ type: CAMPUS_ACTION_TYPES.SET_SEARCH_QUERY,
318
+ payload: { searchQuery: "" },
319
+ });
320
+ }, [dispatch]);
321
+ const applyFilters = useCallback(() => {
322
+ dispatch({
323
+ type: CAMPUS_ACTION_TYPES.SET_FILTERS,
324
+ payload: { filters: { appliedFilterEnabled: state.filterEnabled } },
325
+ });
326
+ dispatch({
327
+ type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
328
+ payload: { currentPage: 1 },
329
+ });
330
+ closeDrawer();
331
+ }, [dispatch, closeDrawer, state.filterEnabled]);
332
+ const clearFilters = useCallback(() => {
333
+ // RESET_FORM restores the initial filter (enabled only) and keeps the
334
+ // loaded items/page; the new params trigger the refetch.
335
+ dispatch({ type: CAMPUS_ACTION_TYPES.RESET_FORM });
336
+ dispatch({
337
+ type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
338
+ payload: { currentPage: 1 },
339
+ });
340
+ }, [dispatch]);
341
+ // ============================================================================
342
+ // 1.4.7 SUBMIT
343
+ // ============================================================================
344
+ const handleSubmit = useCallback(() => {
345
+ dispatch({
346
+ type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
347
+ payload: { disabled: true },
348
+ });
349
+ validateForm({
350
+ params: updateParams,
351
+ schema: campusFormValidation,
352
+ successCallback: () => {
353
+ // `id` is only present when editing; a blank one would make the API
354
+ // treat the request as a create.
355
+ const { id } = updateParams, createParams = __rest(updateParams, ["id"]);
356
+ updateFetchNow(undefined, {
357
+ body: JSON.stringify(id ? updateParams : createParams),
358
+ });
359
+ },
360
+ errorCallback: (errors) => {
361
+ dispatch({
362
+ type: CAMPUS_ACTION_TYPES.SET_ERRORS,
363
+ payload: { errors },
364
+ });
365
+ dispatch({
366
+ type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
367
+ payload: { disabled: false },
368
+ });
369
+ showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
370
+ },
371
+ });
372
+ }, [dispatch, updateParams, t, showToast, updateFetchNow]);
373
+ // ============================================================================
374
+ // 1.4.8 HEADER & ROW ACTIONS
375
+ // ============================================================================
376
+ const headerActions = useMemo(() => [
377
+ {
378
+ enabled: true,
379
+ handleOnClick: handleFilters,
380
+ label: t("actionsButtonFilters"),
381
+ order: 1,
382
+ },
383
+ {
384
+ enabled: true,
385
+ handleOnClick: handleCreate,
386
+ label: t("actionsButtonAdd"),
387
+ order: 2,
388
+ },
389
+ ], [handleCreate, handleFilters, t]);
390
+ const rowActions = useMemo(() => [
391
+ {
392
+ enabled: true,
393
+ handleOnClick: handleView,
394
+ label: t("actionsButtonView"),
395
+ order: 1,
396
+ },
397
+ {
398
+ // Always editable so a disabled campus can be re-enabled.
399
+ enabled: true,
400
+ handleOnClick: handleEdit,
401
+ label: t("actionsButtonEdit"),
402
+ order: 2,
403
+ },
404
+ {
405
+ // Only active records can be soft-deleted.
406
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
407
+ handleOnClick: handleDelete,
408
+ label: t("actionsButtonDelete"),
409
+ order: 3,
410
+ variant: "destructive",
411
+ },
412
+ ], [handleDelete, handleEdit, handleView, t]);
413
+ // ============================================================================
414
+ // 1.4.9 EFFECTS
415
+ // ============================================================================
416
+ useEffect(() => {
417
+ listFetchNowRef.current = listFetchNow;
418
+ }, [listFetchNow]);
419
+ useEffect(() => {
420
+ var _a;
421
+ (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
422
+ }, [listParams]);
423
+ // ============================================================================
424
+ // 1.4.10 RETURN
425
+ // ============================================================================
426
+ return Object.assign(Object.assign({}, context), { applyFilters,
427
+ byIdLoading,
428
+ clearFilters,
429
+ clearSearch,
430
+ closeDrawer,
431
+ deleteLoading,
432
+ handleChange,
433
+ handleCreate,
434
+ handleDelete,
435
+ handleEdit,
436
+ handleFilters,
437
+ handlePageChange,
438
+ handlePageLimitChange,
439
+ handleSearch,
440
+ handleSubmit,
441
+ handleView,
442
+ headerActions,
443
+ listFetchNow,
444
+ listLoading,
445
+ rowActions,
446
+ updateLoading });
447
+ };
@@ -1,5 +1,4 @@
1
1
  import { CampusBE } from "../../type";
2
- import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
3
2
  export declare const CAMPUS_DRAWER: {
4
3
  readonly FILTER_DRAWER: string;
5
4
  readonly FORM_DRAWER: string;
@@ -38,6 +37,10 @@ export declare const CAMPUS_ACTION_TYPES: {
38
37
  schoolId: string;
39
38
  state: string | null;
40
39
  filterEnabled: boolean | undefined;
40
+ appliedFilterEnabled: boolean | undefined;
41
+ classCount: number;
42
+ teacherCount: number;
43
+ studentCount: number;
41
44
  }>, initialCampusState: {
42
45
  items: CampusBE[];
43
46
  count: number;
@@ -58,6 +61,10 @@ export declare const CAMPUS_ACTION_TYPES: {
58
61
  schoolId: string;
59
62
  state: string | null;
60
63
  filterEnabled: boolean | undefined;
64
+ appliedFilterEnabled: boolean | undefined;
65
+ classCount: number;
66
+ teacherCount: number;
67
+ studentCount: number;
61
68
  }, CampusProvider: import("react").FC<{
62
69
  children: React.ReactNode;
63
70
  }>, campusReducer: (state: {
@@ -80,6 +87,10 @@ export declare const CAMPUS_ACTION_TYPES: {
80
87
  schoolId: string;
81
88
  state: string | null;
82
89
  filterEnabled: boolean | undefined;
90
+ appliedFilterEnabled: boolean | undefined;
91
+ classCount: number;
92
+ teacherCount: number;
93
+ studentCount: number;
83
94
  }, action: any) => {
84
95
  items: CampusBE[];
85
96
  count: number;
@@ -100,6 +111,10 @@ export declare const CAMPUS_ACTION_TYPES: {
100
111
  schoolId: string;
101
112
  state: string | null;
102
113
  filterEnabled: boolean | undefined;
114
+ appliedFilterEnabled: boolean | undefined;
115
+ classCount: number;
116
+ teacherCount: number;
117
+ studentCount: number;
103
118
  }, useCampusContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
104
119
  items: CampusBE[];
105
120
  count: number;
@@ -120,57 +135,9 @@ export declare const CAMPUS_ACTION_TYPES: {
120
135
  schoolId: string;
121
136
  state: string | null;
122
137
  filterEnabled: boolean | undefined;
138
+ appliedFilterEnabled: boolean | undefined;
139
+ classCount: number;
140
+ teacherCount: number;
141
+ studentCount: number;
123
142
  }>;
124
- export declare const useCampusModule: () => {
125
- applyFilters: () => void;
126
- byIdLoading: boolean;
127
- clearFilters: () => void;
128
- clearSearch: () => void;
129
- closeDrawer: () => void;
130
- deleteLoading: boolean;
131
- handleChange: (field: string, value: string | number | boolean | undefined | null) => void;
132
- handleCreate: () => void;
133
- handleDelete: (row?: TableRow) => void;
134
- handleEdit: (row?: TableRow) => void;
135
- handleFilters: () => void;
136
- handleMoreActions: () => void;
137
- handlePageChange: (pageOrEvent?: unknown) => void;
138
- handlePageLimitChange: (k: string, value: object) => void;
139
- handleSearch: (query: string) => void;
140
- handleSubmit: () => void;
141
- handleView: (row?: TableRow) => void;
142
- headerActions: {
143
- enabled: boolean;
144
- handleOnClick: () => void;
145
- label: string;
146
- order: number;
147
- }[];
148
- listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
149
- listLoading: boolean;
150
- rowActions: RowAction[];
151
- toggleStatus: (row?: TableRow) => void;
152
- updateLoading: boolean;
153
- handleCloseDrawer?: () => void;
154
- state: {
155
- items: CampusBE[];
156
- count: number;
157
- currentPage: number;
158
- pageLimit: number;
159
- searchQuery: string;
160
- disableSaveButton: boolean;
161
- drawer: string | null;
162
- errors: Record<string, string>;
163
- address: string | null;
164
- city: string | null;
165
- code: string;
166
- country: string | null;
167
- enabled: boolean;
168
- id: string;
169
- name: string;
170
- phone: string | null;
171
- schoolId: string;
172
- state: string | null;
173
- filterEnabled: boolean | undefined;
174
- };
175
- dispatch: React.Dispatch<any>;
176
- };
143
+ export { useCampusModule } from "./context/use-campus-module";