@appcorp/fusion-storybook 0.5.9 → 0.5.13
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/attendance/context/use-attendance-module.d.ts +60 -0
- package/base-modules/attendance/context/use-attendance-module.js +449 -0
- package/base-modules/attendance/context.d.ts +36 -52
- package/base-modules/attendance/context.js +22 -376
- package/base-modules/attendance/date.d.ts +10 -0
- package/base-modules/attendance/date.js +23 -0
- package/base-modules/attendance/filter.js +22 -6
- package/base-modules/attendance/form.js +53 -42
- package/base-modules/attendance/more-actions.js +10 -233
- package/base-modules/attendance/page.js +45 -31
- package/base-modules/attendance/validate.d.ts +3 -1
- package/base-modules/attendance/validate.js +7 -2
- package/base-modules/attendance/view.js +18 -9
- package/base-modules/campus/context/use-campus-module.d.ts +57 -0
- package/base-modules/campus/context/use-campus-module.js +447 -0
- package/base-modules/campus/context.d.ts +21 -54
- package/base-modules/campus/context.js +18 -442
- package/base-modules/campus/filter.js +1 -1
- package/base-modules/campus/form.js +6 -4
- package/base-modules/campus/page.d.ts +0 -2
- package/base-modules/campus/page.js +10 -18
- package/base-modules/campus/validate.js +4 -1
- package/base-modules/campus/view.js +2 -2
- package/constants.d.ts +3 -3
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +0 -1
- package/utils/resolve-rbac-permissions.js +5 -4
- package/base-modules/campus/more-actions.d.ts +0 -1
- package/base-modules/campus/more-actions.js +0 -40
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
/**
|
|
3
|
-
* Campus
|
|
3
|
+
* Campus module — configuration + provider.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* `createGenericModule` owns the reducer/state; the business logic lives in
|
|
6
|
+
* `context/use-campus-module.ts` and is re-exported from here so components
|
|
7
|
+
* keep importing from `./context`.
|
|
8
8
|
*
|
|
9
9
|
* Exported utilities:
|
|
10
10
|
* - `CampusProvider` — provider component used by the page
|
|
@@ -12,22 +12,9 @@
|
|
|
12
12
|
* - `CAMPUS_DRAWER` — drawer type constants
|
|
13
13
|
* - `useCampusModule()` — hook that returns state, dispatch, and handlers
|
|
14
14
|
*/
|
|
15
|
-
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
16
|
-
import { useTheme } from "next-themes";
|
|
17
|
-
import { useTranslations } from "next-intl";
|
|
18
|
-
import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
|
|
19
|
-
import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
|
|
20
|
-
import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
|
|
21
|
-
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
22
15
|
import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
|
|
23
16
|
import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
24
|
-
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
25
|
-
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
26
|
-
import { toE164Phone } from "../../utils/to-e164-phone";
|
|
27
17
|
import { pageLimit } from "./constants";
|
|
28
|
-
import { CAMPUS_API_ROUTES } from "../../constants";
|
|
29
|
-
import { campusFormValidation } from "./validate";
|
|
30
|
-
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
31
18
|
// ============================================================================
|
|
32
19
|
// 1.1 DRAWER TYPES
|
|
33
20
|
// ============================================================================
|
|
@@ -37,6 +24,9 @@ export const CAMPUS_DRAWER = {
|
|
|
37
24
|
MORE_ACTIONS_DRAWER: DRAWER_TYPES.MORE_ACTIONS_DRAWER,
|
|
38
25
|
VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
|
|
39
26
|
};
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// 1.2 MODULE CONFIGURATION
|
|
29
|
+
// ============================================================================
|
|
40
30
|
const campusConfig = {
|
|
41
31
|
name: "Campus",
|
|
42
32
|
displayName: "Campus",
|
|
@@ -64,8 +54,14 @@ const campusConfig = {
|
|
|
64
54
|
phone: null,
|
|
65
55
|
schoolId: "",
|
|
66
56
|
state: null,
|
|
67
|
-
//
|
|
68
|
-
|
|
57
|
+
// Staged filter state: the drawer edits `filter*`; Apply copies them to
|
|
58
|
+
// `appliedFilter*`, which is what the list request uses.
|
|
59
|
+
filterEnabled: true,
|
|
60
|
+
appliedFilterEnabled: true,
|
|
61
|
+
// Usage counts (populated from the detail/list fetch)
|
|
62
|
+
classCount: 0,
|
|
63
|
+
teacherCount: 0,
|
|
64
|
+
studentCount: 0,
|
|
69
65
|
},
|
|
70
66
|
};
|
|
71
67
|
// ============================================================================
|
|
@@ -75,426 +71,6 @@ export const { actionTypes: CAMPUS_ACTION_TYPES, config: campusModuleConfig, ini
|
|
|
75
71
|
// ============================================================================
|
|
76
72
|
// 1.4 ENHANCED CAMPUS HOOK WITH API INTEGRATION
|
|
77
73
|
// ============================================================================
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// 1.4.1 STATE & CORE HOOKS
|
|
82
|
-
// ============================================================================
|
|
83
|
-
const context = useCampusContext();
|
|
84
|
-
const { dispatch } = context;
|
|
85
|
-
const state = context.state;
|
|
86
|
-
const t = useTranslations("campus");
|
|
87
|
-
const { theme } = useTheme();
|
|
88
|
-
const workspace = getCachedWorkspaceSync();
|
|
89
|
-
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
90
|
-
const listFetchNowRef = useRef(null);
|
|
91
|
-
// ============================================================================
|
|
92
|
-
// 1.4.2 API PARAMETERS
|
|
93
|
-
// ============================================================================
|
|
94
|
-
const listParams = useMemo(() => {
|
|
95
|
-
var _a;
|
|
96
|
-
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.filterEnabled !== undefined
|
|
97
|
-
? { filterEnabled: String(state.filterEnabled) }
|
|
98
|
-
: {})));
|
|
99
|
-
}, [
|
|
100
|
-
state.currentPage,
|
|
101
|
-
state.filterEnabled,
|
|
102
|
-
state.pageLimit,
|
|
103
|
-
debouncedQuery,
|
|
104
|
-
(_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
105
|
-
]);
|
|
106
|
-
const updateParams = useMemo(() => {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
return ({
|
|
109
|
-
address: state.address,
|
|
110
|
-
city: state.city,
|
|
111
|
-
code: state.code,
|
|
112
|
-
country: state.country,
|
|
113
|
-
enabled: state.enabled,
|
|
114
|
-
id: state.id,
|
|
115
|
-
name: state.name,
|
|
116
|
-
phone: toE164Phone(state.phone, (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country),
|
|
117
|
-
schoolId: state.schoolId || ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id) || "",
|
|
118
|
-
state: state.state,
|
|
119
|
-
});
|
|
120
|
-
}, [
|
|
121
|
-
state.address,
|
|
122
|
-
state.city,
|
|
123
|
-
state.code,
|
|
124
|
-
state.country,
|
|
125
|
-
state.enabled,
|
|
126
|
-
state.id,
|
|
127
|
-
state.name,
|
|
128
|
-
state.phone,
|
|
129
|
-
state.schoolId,
|
|
130
|
-
state.state,
|
|
131
|
-
(_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.country,
|
|
132
|
-
(_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id,
|
|
133
|
-
]);
|
|
134
|
-
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
135
|
-
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
136
|
-
// ============================================================================
|
|
137
|
-
// 1.4.3 UTILITIES
|
|
138
|
-
// ============================================================================
|
|
139
|
-
const showToast = useCallback((description, variant) => {
|
|
140
|
-
generateThemeToast({
|
|
141
|
-
description,
|
|
142
|
-
theme: theme,
|
|
143
|
-
variant,
|
|
144
|
-
});
|
|
145
|
-
}, [theme]);
|
|
146
|
-
const resetFormAndCloseDrawer = useCallback(() => {
|
|
147
|
-
dispatch({ type: CAMPUS_ACTION_TYPES.RESET_FORM });
|
|
148
|
-
dispatch({
|
|
149
|
-
type: CAMPUS_ACTION_TYPES.SET_ERRORS,
|
|
150
|
-
payload: { errors: {} },
|
|
151
|
-
});
|
|
152
|
-
dispatch({
|
|
153
|
-
type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
154
|
-
payload: { disabled: false },
|
|
155
|
-
});
|
|
156
|
-
dispatch({
|
|
157
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
158
|
-
payload: { drawer: null },
|
|
159
|
-
});
|
|
160
|
-
}, [dispatch]);
|
|
161
|
-
const resetRecordFormState = useCallback(() => {
|
|
162
|
-
var _a;
|
|
163
|
-
dispatch({
|
|
164
|
-
type: CAMPUS_ACTION_TYPES.SET_ERRORS,
|
|
165
|
-
payload: { errors: {} },
|
|
166
|
-
});
|
|
167
|
-
dispatch({
|
|
168
|
-
type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
169
|
-
payload: { disabled: false },
|
|
170
|
-
});
|
|
171
|
-
dispatch({
|
|
172
|
-
type: CAMPUS_ACTION_TYPES.SET_FORM_DATA,
|
|
173
|
-
payload: {
|
|
174
|
-
form: {
|
|
175
|
-
address: null,
|
|
176
|
-
city: null,
|
|
177
|
-
code: "",
|
|
178
|
-
country: null,
|
|
179
|
-
enabled: true,
|
|
180
|
-
filterEnabled: undefined,
|
|
181
|
-
id: "",
|
|
182
|
-
name: "",
|
|
183
|
-
phone: null,
|
|
184
|
-
schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "",
|
|
185
|
-
state: null,
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
});
|
|
189
|
-
}, [dispatch, (_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id]);
|
|
190
|
-
// ============================================================================
|
|
191
|
-
// 1.4.4 API CALLBACKS
|
|
192
|
-
// ============================================================================
|
|
193
|
-
const listCallback = useCallback(({ data, error }) => {
|
|
194
|
-
var _a, _b;
|
|
195
|
-
if (error) {
|
|
196
|
-
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (data) {
|
|
200
|
-
const response = data;
|
|
201
|
-
dispatch({
|
|
202
|
-
type: CAMPUS_ACTION_TYPES.SET_ITEMS,
|
|
203
|
-
payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}, [dispatch, showToast, t]);
|
|
207
|
-
const updateCallback = useCallback(({ data, error }) => {
|
|
208
|
-
var _a;
|
|
209
|
-
if (error) {
|
|
210
|
-
showToast(t("messagesUpdateFailed"), TOAST_VARIANT.ERROR);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (data) {
|
|
214
|
-
const isCreated = isCreatedOrUpdated(data);
|
|
215
|
-
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
216
|
-
resetFormAndCloseDrawer();
|
|
217
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
218
|
-
}
|
|
219
|
-
}, [resetFormAndCloseDrawer, showToast, t]);
|
|
220
|
-
const byIdCallback = useCallback(({ data, error }) => {
|
|
221
|
-
if (error) {
|
|
222
|
-
showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (data) {
|
|
226
|
-
const campus = data;
|
|
227
|
-
dispatch({
|
|
228
|
-
type: CAMPUS_ACTION_TYPES.SET_FORM_DATA,
|
|
229
|
-
payload: {
|
|
230
|
-
form: Object.assign(Object.assign({}, campus), { phone: formatPhoneDisplay(campus.phone) || "", filterEnabled: undefined }),
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}, [dispatch, showToast, t]);
|
|
235
|
-
const deleteCallback = useCallback(({ data, error }) => {
|
|
236
|
-
var _a;
|
|
237
|
-
if (error) {
|
|
238
|
-
showToast(t("messagesDeleteFailed"), TOAST_VARIANT.ERROR);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (data) {
|
|
242
|
-
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
243
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
244
|
-
}
|
|
245
|
-
}, [showToast, t]);
|
|
246
|
-
// ============================================================================
|
|
247
|
-
// 1.4.5 API HOOKS
|
|
248
|
-
// ============================================================================
|
|
249
|
-
const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
|
|
250
|
-
byIdCallback,
|
|
251
|
-
byIdParams,
|
|
252
|
-
deleteCallback,
|
|
253
|
-
deleteParams,
|
|
254
|
-
listCallback,
|
|
255
|
-
listParams,
|
|
256
|
-
listUrl: CAMPUS_API_ROUTES.UNIT,
|
|
257
|
-
searchQuery: debouncedQuery,
|
|
258
|
-
unitByIdUrl: CAMPUS_API_ROUTES.UNIT,
|
|
259
|
-
unitUrl: CAMPUS_API_ROUTES.UNIT,
|
|
260
|
-
updateCallback,
|
|
261
|
-
updateParams,
|
|
262
|
-
headers: {
|
|
263
|
-
"Content-Type": "application/json",
|
|
264
|
-
},
|
|
265
|
-
});
|
|
266
|
-
// ============================================================================
|
|
267
|
-
// 1.4.6 HANDLERS
|
|
268
|
-
// ============================================================================
|
|
269
|
-
const handleChange = useCallback((field, value) => {
|
|
270
|
-
let formatted = value;
|
|
271
|
-
if (field === "code" && typeof value === "string") {
|
|
272
|
-
formatted = value.toUpperCase();
|
|
273
|
-
}
|
|
274
|
-
dispatch({
|
|
275
|
-
type: CAMPUS_ACTION_TYPES.SET_ERRORS,
|
|
276
|
-
payload: { errors: {} },
|
|
277
|
-
});
|
|
278
|
-
dispatch({
|
|
279
|
-
type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
280
|
-
payload: { disabled: false },
|
|
281
|
-
});
|
|
282
|
-
dispatch({
|
|
283
|
-
type: CAMPUS_ACTION_TYPES.SET_INPUT_FIELD,
|
|
284
|
-
payload: { key: field, value: formatted !== null && formatted !== void 0 ? formatted : value },
|
|
285
|
-
});
|
|
286
|
-
}, [dispatch]);
|
|
287
|
-
const closeDrawer = useCallback(() => {
|
|
288
|
-
resetFormAndCloseDrawer();
|
|
289
|
-
}, [resetFormAndCloseDrawer]);
|
|
290
|
-
const handleCreate = useCallback(() => {
|
|
291
|
-
dispatch({
|
|
292
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
293
|
-
payload: { drawer: CAMPUS_DRAWER.FORM_DRAWER },
|
|
294
|
-
});
|
|
295
|
-
}, [dispatch]);
|
|
296
|
-
const handleView = useCallback((row) => {
|
|
297
|
-
resetRecordFormState();
|
|
298
|
-
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
299
|
-
dispatch({
|
|
300
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
301
|
-
payload: { drawer: CAMPUS_DRAWER.VIEW_DRAWER },
|
|
302
|
-
});
|
|
303
|
-
}, [byIdFetchNow, dispatch, resetRecordFormState]);
|
|
304
|
-
const handleEdit = useCallback((row) => {
|
|
305
|
-
resetRecordFormState();
|
|
306
|
-
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
307
|
-
dispatch({
|
|
308
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
309
|
-
payload: { drawer: CAMPUS_DRAWER.FORM_DRAWER },
|
|
310
|
-
});
|
|
311
|
-
}, [byIdFetchNow, dispatch, resetRecordFormState]);
|
|
312
|
-
const handleDelete = useCallback((row) => {
|
|
313
|
-
if (!confirm(t("messagesDeleteConfirmation")))
|
|
314
|
-
return;
|
|
315
|
-
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
316
|
-
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
|
|
317
|
-
});
|
|
318
|
-
}, [deleteFetchNow, t]);
|
|
319
|
-
const handleFilters = useCallback(() => {
|
|
320
|
-
dispatch({
|
|
321
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
322
|
-
payload: { drawer: CAMPUS_DRAWER.FILTER_DRAWER },
|
|
323
|
-
});
|
|
324
|
-
}, [dispatch]);
|
|
325
|
-
const handleMoreActions = useCallback(() => {
|
|
326
|
-
dispatch({
|
|
327
|
-
type: CAMPUS_ACTION_TYPES.SET_DRAWER,
|
|
328
|
-
payload: { drawer: CAMPUS_DRAWER.MORE_ACTIONS_DRAWER },
|
|
329
|
-
});
|
|
330
|
-
}, [dispatch]);
|
|
331
|
-
const handlePageChange = useCallback((pageOrEvent) => {
|
|
332
|
-
const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
|
|
333
|
-
? pageOrEvent
|
|
334
|
-
: state.currentPage + 1;
|
|
335
|
-
dispatch({
|
|
336
|
-
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
337
|
-
payload: { currentPage: page },
|
|
338
|
-
});
|
|
339
|
-
}, [dispatch, state.currentPage]);
|
|
340
|
-
const handlePageLimitChange = useCallback((k, value) => {
|
|
341
|
-
const val = Object.assign({}, value);
|
|
342
|
-
dispatch({
|
|
343
|
-
type: CAMPUS_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
344
|
-
payload: { pageLimit: Number(val.option) },
|
|
345
|
-
});
|
|
346
|
-
dispatch({
|
|
347
|
-
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
348
|
-
payload: { currentPage: 1 },
|
|
349
|
-
});
|
|
350
|
-
}, [dispatch]);
|
|
351
|
-
const handleSearch = useCallback((query) => {
|
|
352
|
-
dispatch({
|
|
353
|
-
type: CAMPUS_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
354
|
-
payload: { searchQuery: query },
|
|
355
|
-
});
|
|
356
|
-
}, [dispatch]);
|
|
357
|
-
const clearSearch = useCallback(() => {
|
|
358
|
-
dispatch({
|
|
359
|
-
type: CAMPUS_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
360
|
-
payload: { searchQuery: "" },
|
|
361
|
-
});
|
|
362
|
-
}, [dispatch]);
|
|
363
|
-
const applyFilters = useCallback(() => {
|
|
364
|
-
dispatch({
|
|
365
|
-
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
366
|
-
payload: { currentPage: 1 },
|
|
367
|
-
});
|
|
368
|
-
closeDrawer();
|
|
369
|
-
}, [dispatch, closeDrawer]);
|
|
370
|
-
const clearFilters = useCallback(() => {
|
|
371
|
-
dispatch({
|
|
372
|
-
type: CAMPUS_ACTION_TYPES.SET_FILTERS,
|
|
373
|
-
payload: { filters: { filterEnabled: undefined } },
|
|
374
|
-
});
|
|
375
|
-
dispatch({
|
|
376
|
-
type: CAMPUS_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
377
|
-
payload: { currentPage: 1 },
|
|
378
|
-
});
|
|
379
|
-
}, [dispatch]);
|
|
380
|
-
const toggleStatus = useCallback((row) => {
|
|
381
|
-
updateFetchNow(undefined, {
|
|
382
|
-
body: JSON.stringify(Object.assign(Object.assign({}, row), { enabled: !(row === null || row === void 0 ? void 0 : row.enabled) })),
|
|
383
|
-
});
|
|
384
|
-
}, [updateFetchNow]);
|
|
385
|
-
// ============================================================================
|
|
386
|
-
// 1.4.7 SUBMIT
|
|
387
|
-
// ============================================================================
|
|
388
|
-
const handleSubmit = useCallback(() => {
|
|
389
|
-
dispatch({
|
|
390
|
-
type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
391
|
-
payload: { disabled: true },
|
|
392
|
-
});
|
|
393
|
-
validateForm({
|
|
394
|
-
params: updateParams,
|
|
395
|
-
schema: campusFormValidation,
|
|
396
|
-
successCallback: () => {
|
|
397
|
-
updateFetchNow(undefined, {
|
|
398
|
-
body: JSON.stringify(updateParams),
|
|
399
|
-
});
|
|
400
|
-
},
|
|
401
|
-
errorCallback: (errors) => {
|
|
402
|
-
dispatch({
|
|
403
|
-
type: CAMPUS_ACTION_TYPES.SET_ERRORS,
|
|
404
|
-
payload: { errors },
|
|
405
|
-
});
|
|
406
|
-
dispatch({
|
|
407
|
-
type: CAMPUS_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
408
|
-
payload: { disabled: false },
|
|
409
|
-
});
|
|
410
|
-
showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
|
|
411
|
-
},
|
|
412
|
-
});
|
|
413
|
-
}, [dispatch, updateParams, t, showToast, updateFetchNow]);
|
|
414
|
-
// ============================================================================
|
|
415
|
-
// 1.4.8 HEADER & ROW ACTIONS
|
|
416
|
-
// ============================================================================
|
|
417
|
-
const headerActions = useMemo(() => [
|
|
418
|
-
{
|
|
419
|
-
enabled: false,
|
|
420
|
-
handleOnClick: handleMoreActions,
|
|
421
|
-
label: t("actionsButtonMoreActions"),
|
|
422
|
-
order: 0,
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
enabled: true,
|
|
426
|
-
handleOnClick: handleFilters,
|
|
427
|
-
label: t("actionsButtonFilters"),
|
|
428
|
-
order: 1,
|
|
429
|
-
},
|
|
430
|
-
{
|
|
431
|
-
enabled: true,
|
|
432
|
-
handleOnClick: handleCreate,
|
|
433
|
-
label: t("actionsButtonAdd"),
|
|
434
|
-
order: 2,
|
|
435
|
-
},
|
|
436
|
-
], [handleCreate, handleFilters, handleMoreActions, t]);
|
|
437
|
-
const rowActions = useMemo(() => [
|
|
438
|
-
{
|
|
439
|
-
enabled: true,
|
|
440
|
-
handleOnClick: handleView,
|
|
441
|
-
label: t("actionsButtonView"),
|
|
442
|
-
order: 1,
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
|
|
446
|
-
handleOnClick: handleEdit,
|
|
447
|
-
label: t("actionsButtonEdit"),
|
|
448
|
-
order: 2,
|
|
449
|
-
},
|
|
450
|
-
{
|
|
451
|
-
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === false,
|
|
452
|
-
handleOnClick: handleDelete,
|
|
453
|
-
label: t("actionsButtonDelete"),
|
|
454
|
-
order: 3,
|
|
455
|
-
variant: "destructive",
|
|
456
|
-
},
|
|
457
|
-
{
|
|
458
|
-
enabled: false,
|
|
459
|
-
handleOnClick: toggleStatus,
|
|
460
|
-
label: t("actionsButtonToggleStatus"),
|
|
461
|
-
order: 4,
|
|
462
|
-
},
|
|
463
|
-
], [handleDelete, handleEdit, handleView, t, toggleStatus]);
|
|
464
|
-
// ============================================================================
|
|
465
|
-
// 1.4.9 EFFECTS
|
|
466
|
-
// ============================================================================
|
|
467
|
-
useEffect(() => {
|
|
468
|
-
listFetchNowRef.current = listFetchNow;
|
|
469
|
-
}, [listFetchNow]);
|
|
470
|
-
useEffect(() => {
|
|
471
|
-
var _a;
|
|
472
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
473
|
-
}, [listParams]);
|
|
474
|
-
// ============================================================================
|
|
475
|
-
// 1.4.10 RETURN
|
|
476
|
-
// ============================================================================
|
|
477
|
-
return Object.assign(Object.assign({}, context), { applyFilters,
|
|
478
|
-
byIdLoading,
|
|
479
|
-
clearFilters,
|
|
480
|
-
clearSearch,
|
|
481
|
-
closeDrawer,
|
|
482
|
-
deleteLoading,
|
|
483
|
-
handleChange,
|
|
484
|
-
handleCreate,
|
|
485
|
-
handleDelete,
|
|
486
|
-
handleEdit,
|
|
487
|
-
handleFilters,
|
|
488
|
-
handleMoreActions,
|
|
489
|
-
handlePageChange,
|
|
490
|
-
handlePageLimitChange,
|
|
491
|
-
handleSearch,
|
|
492
|
-
handleSubmit,
|
|
493
|
-
handleView,
|
|
494
|
-
headerActions,
|
|
495
|
-
listFetchNow,
|
|
496
|
-
listLoading,
|
|
497
|
-
rowActions,
|
|
498
|
-
toggleStatus,
|
|
499
|
-
updateLoading });
|
|
500
|
-
};
|
|
74
|
+
// Re-exported for the page/components; the implementation lives in
|
|
75
|
+
// `context/use-campus-module.ts` so it stays unit-testable.
|
|
76
|
+
export { useCampusModule } from "./context/use-campus-module";
|
|
@@ -17,7 +17,7 @@ export const CampusFilter = () => {
|
|
|
17
17
|
: filterEnabled
|
|
18
18
|
? "true"
|
|
19
19
|
: "false";
|
|
20
|
-
return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("
|
|
20
|
+
return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
|
|
21
21
|
{ label: t("filterOptionAll"), value: "undefined" },
|
|
22
22
|
{ label: t("filterOptionEnabled"), value: "true" },
|
|
23
23
|
{ label: t("filterOptionDisabled"), value: "false" },
|
|
@@ -11,12 +11,14 @@ import { useCampusModule } from "./context";
|
|
|
11
11
|
import { useTranslations } from "next-intl";
|
|
12
12
|
import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
|
|
13
13
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
14
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
14
15
|
export const CampusForm = () => {
|
|
15
16
|
const { state, handleChange } = useCampusModule();
|
|
16
17
|
const { address, city, code, country, enabled, errors, name, phone, state: campusState, } = state;
|
|
17
18
|
const t = useTranslations("campus");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const workspace = getCachedWorkspaceSync();
|
|
20
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formCampusNameInfo"), label: t("formCampusNameLabel"), maxLength: 100, onChange: (e) => handleChange("name", e.target.value), placeholder: t("formCampusNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formCampusCodeInfo"), label: t("formCampusCodeLabel"), maxLength: 20, onChange: (e) => handleChange("code", e.target.value), placeholder: t("formCampusCodePlaceholder"), required: true, value: code }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "address", t }), id: "address", info: t("formAddressInfo"), label: t("formAddressLabel"), maxLength: 255, onChange: (e) => handleChange("address", e.target.value), placeholder: t("formAddressPlaceholder"), value: address || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "city", t }), id: "city", info: t("formCityInfo"), label: t("formCityLabel"), maxLength: 100, onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateInfo"), label: t("formStateLabel"), maxLength: 100, onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), value: campusState || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "country", t }), id: "country", info: t("formCountryInfo"), label: t("formCountryLabel"), maxLength: 100, onChange: (e) => handleChange("country", e.target.value), placeholder: t("formCountryPlaceholder"), value: country || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), maxLength: 30, onChange: (e) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return handleChange("phone", ((_b = formatPhone(e.target.value, (((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country) || "PK"))) === null || _b === void 0 ? void 0 : _b.international) || e.target.value);
|
|
23
|
+
}, placeholder: t("formPhonePlaceholder"), value: phone || "" }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formActiveCampusInfo"), label: t("formActiveCampusLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }));
|
|
22
24
|
};
|
|
@@ -16,8 +16,6 @@ interface Props {
|
|
|
16
16
|
drawerFilterTitle: string;
|
|
17
17
|
drawerFormDescription: string;
|
|
18
18
|
drawerFormTitle: string;
|
|
19
|
-
drawerMoreActionsDescription: string;
|
|
20
|
-
drawerMoreActionsTitle: string;
|
|
21
19
|
drawerViewDescription: string;
|
|
22
20
|
drawerViewTitle: string;
|
|
23
21
|
labelActions: string;
|
|
@@ -13,10 +13,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { useMemo } from "react";
|
|
14
14
|
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
15
15
|
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
16
|
-
import { useCampusModule, CampusProvider
|
|
16
|
+
import { useCampusModule, CampusProvider } from "./context";
|
|
17
17
|
import { CampusFilter } from "./filter";
|
|
18
18
|
import { CampusForm } from "./form";
|
|
19
|
-
import { CampusMoreActions } from "./more-actions";
|
|
20
19
|
import { CampusView } from "./view";
|
|
21
20
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
22
21
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
@@ -37,10 +36,9 @@ const tableBodyCols = [
|
|
|
37
36
|
const createComponentInstances = () => ({
|
|
38
37
|
filter: _jsx(CampusFilter, {}),
|
|
39
38
|
form: _jsx(CampusForm, {}),
|
|
40
|
-
moreActions: _jsx(CampusMoreActions, {}),
|
|
41
39
|
view: _jsx(CampusView, {}),
|
|
42
40
|
});
|
|
43
|
-
const createCampusConfig = ({ cancelLabel,
|
|
41
|
+
const createCampusConfig = ({ cancelLabel, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerViewDescription, drawerViewTitle, labelActions, labelCity, labelCode, labelEnabled, labelId, labelName, onClearFilters, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
|
|
44
42
|
const components = createComponentInstances();
|
|
45
43
|
return {
|
|
46
44
|
moduleName: "campus",
|
|
@@ -57,21 +55,19 @@ const createCampusConfig = ({ cancelLabel, dispatch, drawerFilterDescription, dr
|
|
|
57
55
|
drawerFilterTitle,
|
|
58
56
|
drawerFormDescription,
|
|
59
57
|
drawerFormTitle,
|
|
60
|
-
drawerMoreActionsDescription,
|
|
61
|
-
drawerMoreActionsTitle,
|
|
58
|
+
drawerMoreActionsDescription: "",
|
|
59
|
+
drawerMoreActionsTitle: "",
|
|
62
60
|
drawerViewDescription,
|
|
63
61
|
drawerViewTitle,
|
|
64
62
|
filterContent: components.filter,
|
|
65
63
|
formContent: components.form,
|
|
66
|
-
moreActionsContent:
|
|
64
|
+
moreActionsContent: null,
|
|
67
65
|
saveLabel,
|
|
68
66
|
searchPlaceholder,
|
|
69
67
|
tableDescription,
|
|
70
68
|
tableTitle,
|
|
71
69
|
viewContent: components.view,
|
|
72
|
-
onClearFilters
|
|
73
|
-
dispatch({ type: CAMPUS_ACTION_TYPES.RESET_FORM });
|
|
74
|
-
},
|
|
70
|
+
onClearFilters,
|
|
75
71
|
};
|
|
76
72
|
};
|
|
77
73
|
// ============================================================================
|
|
@@ -81,7 +77,7 @@ const GenericCampusPage = createGenericModulePage();
|
|
|
81
77
|
const CampusPageInner = (props) => {
|
|
82
78
|
const context = useCampusModule();
|
|
83
79
|
const campusConfig = useMemo(() => createCampusConfig({
|
|
84
|
-
|
|
80
|
+
onClearFilters: context.clearFilters,
|
|
85
81
|
cancelLabel: props.cancelLabel,
|
|
86
82
|
drawerFormTitle: props.drawerFormTitle,
|
|
87
83
|
drawerFormDescription: props.drawerFormDescription,
|
|
@@ -89,8 +85,6 @@ const CampusPageInner = (props) => {
|
|
|
89
85
|
drawerViewDescription: props.drawerViewDescription,
|
|
90
86
|
drawerFilterTitle: props.drawerFilterTitle,
|
|
91
87
|
drawerFilterDescription: props.drawerFilterDescription,
|
|
92
|
-
drawerMoreActionsTitle: props.drawerMoreActionsTitle,
|
|
93
|
-
drawerMoreActionsDescription: props.drawerMoreActionsDescription,
|
|
94
88
|
labelActions: props.labelActions,
|
|
95
89
|
labelCity: props.labelCity,
|
|
96
90
|
labelCode: props.labelCode,
|
|
@@ -102,7 +96,7 @@ const CampusPageInner = (props) => {
|
|
|
102
96
|
tableDescription: props.tableDescription,
|
|
103
97
|
tableTitle: props.tableTitle,
|
|
104
98
|
}), [
|
|
105
|
-
context.
|
|
99
|
+
context.clearFilters,
|
|
106
100
|
props.cancelLabel,
|
|
107
101
|
props.drawerFormTitle,
|
|
108
102
|
props.drawerFormDescription,
|
|
@@ -110,8 +104,6 @@ const CampusPageInner = (props) => {
|
|
|
110
104
|
props.drawerViewDescription,
|
|
111
105
|
props.drawerFilterTitle,
|
|
112
106
|
props.drawerFilterDescription,
|
|
113
|
-
props.drawerMoreActionsTitle,
|
|
114
|
-
props.drawerMoreActionsDescription,
|
|
115
107
|
props.labelActions,
|
|
116
108
|
props.labelCity,
|
|
117
109
|
props.labelCode,
|
|
@@ -125,10 +117,10 @@ const CampusPageInner = (props) => {
|
|
|
125
117
|
]);
|
|
126
118
|
const hasPermission = resolveRbacPermissions({
|
|
127
119
|
userRole: props.userRole,
|
|
128
|
-
moduleName: "
|
|
120
|
+
moduleName: "Campus",
|
|
129
121
|
});
|
|
130
122
|
if (!hasPermission) {
|
|
131
|
-
return _jsx(RbacNoAccess, { moduleName: "
|
|
123
|
+
return _jsx(RbacNoAccess, { moduleName: "Campus" });
|
|
132
124
|
}
|
|
133
125
|
return (_jsx("div", { className: "p-4", children: _jsx(GenericCampusPage, { overrideConfig: campusConfig, context: context, tableBodyCols: tableBodyCols }) }));
|
|
134
126
|
};
|
|
@@ -16,10 +16,13 @@ export const VALIDATION_KEYS = {
|
|
|
16
16
|
export const campusFormValidation = z.object({
|
|
17
17
|
name: z
|
|
18
18
|
.string()
|
|
19
|
+
.trim()
|
|
19
20
|
.min(1, VALIDATION_KEYS.nameRequired)
|
|
20
21
|
.max(100, VALIDATION_KEYS.nameMaxLength),
|
|
21
22
|
code: z
|
|
22
23
|
.string()
|
|
24
|
+
.trim()
|
|
25
|
+
.toUpperCase()
|
|
23
26
|
.min(1, VALIDATION_KEYS.codeRequired)
|
|
24
27
|
.max(20, VALIDATION_KEYS.codeMaxLength)
|
|
25
28
|
.regex(/^[A-Z0-9\-_]+$/, VALIDATION_KEYS.codeFormat)
|
|
@@ -49,6 +52,6 @@ export const campusFormValidation = z.object({
|
|
|
49
52
|
.max(30, VALIDATION_KEYS.phoneMaxLength)
|
|
50
53
|
.optional()
|
|
51
54
|
.nullable()
|
|
52
|
-
.transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
|
|
55
|
+
.transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
|
|
53
56
|
enabled: z.boolean().optional(),
|
|
54
57
|
});
|