@appcorp/fusion-storybook 0.1.70 → 0.1.73
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/campus/context.js +3 -1
- package/base-modules/campus/form.js +1 -1
- package/base-modules/rbac/context.d.ts +1 -21
- package/base-modules/rbac/context.js +15 -30
- package/base-modules/rbac/form.js +4 -2
- package/base-modules/rbac/page.js +2 -8
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -414,7 +414,9 @@ export const useCampusModule = () => {
|
|
|
414
414
|
return;
|
|
415
415
|
(async () => {
|
|
416
416
|
try {
|
|
417
|
-
const { count, items } = await getCachedCampuses({
|
|
417
|
+
const { count, items } = await getCachedCampuses({
|
|
418
|
+
params: listParams,
|
|
419
|
+
});
|
|
418
420
|
dispatch({
|
|
419
421
|
type: CAMPUS_ACTION_TYPES.SET_ITEMS,
|
|
420
422
|
payload: { items: items || [], count: count || 0 },
|
|
@@ -11,7 +11,7 @@ import { useCampusModule } from "./context";
|
|
|
11
11
|
import { useTranslations } from "next-intl";
|
|
12
12
|
export const CampusForm = () => {
|
|
13
13
|
const { state, handleChange } = useCampusModule();
|
|
14
|
-
const { address, city, code, country, enabled, errors, name, phone, state: campusState } = state;
|
|
14
|
+
const { address, city, code, country, enabled, errors, name, phone, state: campusState, } = state;
|
|
15
15
|
const t = useTranslations("campus");
|
|
16
16
|
return (_jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: errors.name, id: "name", info: t("campusNameInfo"), label: t("campusName"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("campusNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: errors.code, id: "code", info: t("campusCodeInfo"), label: t("campusCode"), onChange: (e) => handleChange("code", e.target.value), placeholder: t("campusCodePlaceholder"), required: true, value: code }), _jsx(EnhancedInput, { error: errors.address, id: "address", label: t("address"), onChange: (e) => handleChange("address", e.target.value), placeholder: t("addressPlaceholder"), value: address || "" }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsx(EnhancedInput, { error: errors.city, id: "city", label: t("city"), onChange: (e) => handleChange("city", e.target.value), placeholder: t("cityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: errors.state, id: "state", label: t("state"), onChange: (e) => handleChange("state", e.target.value), placeholder: t("statePlaceholder"), value: campusState || "" })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsx(EnhancedInput, { error: errors.country, id: "country", label: t("country"), onChange: (e) => handleChange("country", e.target.value), placeholder: t("countryPlaceholder"), value: country || "" }), _jsx(EnhancedInput, { error: errors.phone, id: "phone", label: t("phone"), onChange: (e) => handleChange("phone", e.target.value), placeholder: t("phonePlaceholder"), value: phone || "" })] }), _jsx(EnhancedCheckbox, { label: t("activeCampus"), defaultChecked: enabled, onCheckedChange: (checked) => handleChange("enabled", checked) })] }) }));
|
|
17
17
|
};
|
|
@@ -4,7 +4,6 @@ export declare const RBAC_DRAWER: {
|
|
|
4
4
|
readonly FORM_DRAWER: string;
|
|
5
5
|
readonly VIEW_DRAWER: string;
|
|
6
6
|
readonly MORE_ACTIONS_DRAWER: string;
|
|
7
|
-
readonly ASSIGN_PERMISSIONS_DRAWER: string;
|
|
8
7
|
};
|
|
9
8
|
export declare const RBAC_ACTION_TYPES: {
|
|
10
9
|
readonly RESET_FORM: "RESET_FORM";
|
|
@@ -106,24 +105,6 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
106
105
|
drawer: null;
|
|
107
106
|
modal: null;
|
|
108
107
|
}>;
|
|
109
|
-
/**
|
|
110
|
-
* Extended action types for permission-specific state mutations.
|
|
111
|
-
*/
|
|
112
|
-
export declare const RBAC_EXTENDED_ACTION_TYPES: {
|
|
113
|
-
readonly SET_AVAILABLE_PERMISSIONS: "SET_AVAILABLE_PERMISSIONS";
|
|
114
|
-
readonly SET_TOGGLING_PERMISSION: "SET_TOGGLING_PERMISSION";
|
|
115
|
-
readonly RESET_FORM: "RESET_FORM";
|
|
116
|
-
readonly SET_CURRENT_PAGE: "SET_CURRENT_PAGE";
|
|
117
|
-
readonly SET_PAGE_LIMIT: "SET_PAGE_LIMIT";
|
|
118
|
-
readonly SET_SEARCH_QUERY: "SET_SEARCH_QUERY";
|
|
119
|
-
readonly SET_DRAWER: "SET_DRAWER";
|
|
120
|
-
readonly SET_ITEMS: "SET_ITEMS";
|
|
121
|
-
readonly SET_FORM_DATA: "SET_FORM_DATA";
|
|
122
|
-
readonly SET_DISABLE_SAVE_BUTTON: "SET_DISABLE_SAVE_BUTTON";
|
|
123
|
-
readonly SET_INPUT_FIELD: "SET_INPUT_FIELD";
|
|
124
|
-
readonly SET_ERRORS: "SET_ERRORS";
|
|
125
|
-
readonly SET_FILTERS: "SET_FILTERS";
|
|
126
|
-
};
|
|
127
108
|
/**
|
|
128
109
|
* Backward-compatible alias used by dashboard-providers.tsx
|
|
129
110
|
*/
|
|
@@ -140,9 +121,8 @@ export declare const useRbacModule: () => {
|
|
|
140
121
|
handleChange: (key: string, value: string | number | boolean | undefined) => void;
|
|
141
122
|
handleCreate: () => void;
|
|
142
123
|
handleDelete: (row?: unknown) => void;
|
|
143
|
-
handleEdit: (row?: unknown) => void
|
|
124
|
+
handleEdit: (row?: unknown) => Promise<void>;
|
|
144
125
|
handleFilters: () => void;
|
|
145
|
-
handleManagePermissions: (row?: unknown) => Promise<void>;
|
|
146
126
|
handleMoreActions: () => void;
|
|
147
127
|
handleNextClick: () => void;
|
|
148
128
|
handlePageChange: (page: number) => void;
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* - `RbacProvider` — provider component used by the page
|
|
16
16
|
* - `RbacStateContextProvider` — backward-compat alias
|
|
17
17
|
* - `RBAC_ACTION_TYPES` — action type constants (from factory)
|
|
18
|
-
* - `RBAC_EXTENDED_ACTION_TYPES` — extended action types for permissions
|
|
19
18
|
* - `RBAC_DRAWER` — drawer type constants
|
|
20
19
|
* - `useRbacModule()` — hook that returns state, dispatch, and handlers
|
|
21
20
|
*/
|
|
@@ -39,7 +38,6 @@ export const RBAC_DRAWER = {
|
|
|
39
38
|
FORM_DRAWER: DRAWER_TYPES.FORM_DRAWER,
|
|
40
39
|
VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
|
|
41
40
|
MORE_ACTIONS_DRAWER: DRAWER_TYPES.MORE_ACTIONS_DRAWER,
|
|
42
|
-
ASSIGN_PERMISSIONS_DRAWER: "ASSIGN_PERMISSIONS_DRAWER",
|
|
43
41
|
};
|
|
44
42
|
const rbacConfig = {
|
|
45
43
|
name: "Rbac",
|
|
@@ -73,10 +71,6 @@ const rbacConfig = {
|
|
|
73
71
|
// 1.3 CREATE RBAC MODULE
|
|
74
72
|
// ============================================================================
|
|
75
73
|
export const { actionTypes: RBAC_ACTION_TYPES, config: rbacModuleConfig, initialState: initialRbacState, Provider: RbacProvider, reducer: rbacReducer, useContext: useRbacContext, } = createGenericModule(rbacConfig);
|
|
76
|
-
/**
|
|
77
|
-
* Extended action types for permission-specific state mutations.
|
|
78
|
-
*/
|
|
79
|
-
export const RBAC_EXTENDED_ACTION_TYPES = Object.assign(Object.assign({}, RBAC_ACTION_TYPES), { SET_AVAILABLE_PERMISSIONS: "SET_AVAILABLE_PERMISSIONS", SET_TOGGLING_PERMISSION: "SET_TOGGLING_PERMISSION" });
|
|
80
74
|
/**
|
|
81
75
|
* Backward-compatible alias used by dashboard-providers.tsx
|
|
82
76
|
*/
|
|
@@ -267,9 +261,14 @@ export const useRbacModule = () => {
|
|
|
267
261
|
payload: { drawer: RBAC_DRAWER.VIEW_DRAWER },
|
|
268
262
|
});
|
|
269
263
|
}, [byIdFetchNow, dispatch]);
|
|
270
|
-
const handleEdit = useCallback(
|
|
264
|
+
const handleEdit = useCallback(
|
|
265
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
266
|
+
async (row) => {
|
|
271
267
|
const record = row;
|
|
272
268
|
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: record === null || record === void 0 ? void 0 : record.id } });
|
|
269
|
+
// loadAvailablePermissions is declared below in 1.4.7
|
|
270
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
271
|
+
await loadAvailablePermissions();
|
|
273
272
|
dispatch({
|
|
274
273
|
type: RBAC_ACTION_TYPES.SET_DRAWER,
|
|
275
274
|
payload: { drawer: RBAC_DRAWER.FORM_DRAWER },
|
|
@@ -372,29 +371,22 @@ export const useRbacModule = () => {
|
|
|
372
371
|
if (!res.ok)
|
|
373
372
|
throw new Error("Failed to load permissions");
|
|
374
373
|
const data = (await res.json());
|
|
374
|
+
// Use SET_INPUT_FIELD — the generic reducer handles it via state[key] = value.
|
|
375
|
+
// Custom action types hit the reducer's default case and are silently ignored.
|
|
375
376
|
dispatch({
|
|
376
|
-
type:
|
|
377
|
-
payload: {
|
|
377
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
378
|
+
payload: { key: "availablePermissions", value: data.items },
|
|
378
379
|
});
|
|
379
380
|
}
|
|
380
381
|
catch (_a) {
|
|
381
382
|
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
382
383
|
}
|
|
383
384
|
}, [dispatch, showToast, t]);
|
|
384
|
-
const handleManagePermissions = useCallback(async (row) => {
|
|
385
|
-
const record = row;
|
|
386
|
-
await (byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: record === null || record === void 0 ? void 0 : record.id } }));
|
|
387
|
-
await loadAvailablePermissions();
|
|
388
|
-
dispatch({
|
|
389
|
-
type: RBAC_ACTION_TYPES.SET_DRAWER,
|
|
390
|
-
payload: { drawer: RBAC_DRAWER.ASSIGN_PERMISSIONS_DRAWER },
|
|
391
|
-
});
|
|
392
|
-
}, [byIdFetchNow, dispatch, loadAvailablePermissions]);
|
|
393
385
|
const handleTogglePermission = useCallback(async (permissionId) => {
|
|
394
386
|
const existing = state.rolePermissions.find((rp) => rp.permissionId === permissionId);
|
|
395
387
|
dispatch({
|
|
396
|
-
type:
|
|
397
|
-
payload: {
|
|
388
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
389
|
+
payload: { key: "togglingPermission", value: true },
|
|
398
390
|
});
|
|
399
391
|
try {
|
|
400
392
|
if (existing) {
|
|
@@ -426,8 +418,8 @@ export const useRbacModule = () => {
|
|
|
426
418
|
}
|
|
427
419
|
finally {
|
|
428
420
|
dispatch({
|
|
429
|
-
type:
|
|
430
|
-
payload: {
|
|
421
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
422
|
+
payload: { key: "togglingPermission", value: false },
|
|
431
423
|
});
|
|
432
424
|
}
|
|
433
425
|
}, [byIdFetchNow, dispatch, showToast, state.id, state.rolePermissions, t]);
|
|
@@ -467,19 +459,13 @@ export const useRbacModule = () => {
|
|
|
467
459
|
label: t("actionsButtonEdit"),
|
|
468
460
|
order: 2,
|
|
469
461
|
},
|
|
470
|
-
{
|
|
471
|
-
enabled: true,
|
|
472
|
-
handleOnClick: handleManagePermissions,
|
|
473
|
-
label: t("actionsButtonManagePermissions"),
|
|
474
|
-
order: 3,
|
|
475
|
-
},
|
|
476
462
|
{
|
|
477
463
|
enabled: true,
|
|
478
464
|
handleOnClick: handleDelete,
|
|
479
465
|
label: t("actionsButtonDelete"),
|
|
480
466
|
order: 4,
|
|
481
467
|
},
|
|
482
|
-
], [handleDelete, handleEdit,
|
|
468
|
+
], [handleDelete, handleEdit, handleView, t]);
|
|
483
469
|
// ============================================================================
|
|
484
470
|
// 1.4.9 EFFECTS
|
|
485
471
|
// ============================================================================
|
|
@@ -520,7 +506,6 @@ export const useRbacModule = () => {
|
|
|
520
506
|
handleDelete,
|
|
521
507
|
handleEdit,
|
|
522
508
|
handleFilters,
|
|
523
|
-
handleManagePermissions,
|
|
524
509
|
handleMoreActions,
|
|
525
510
|
handleNextClick,
|
|
526
511
|
handlePageChange,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
4
|
* RBAC Form Component
|
|
5
5
|
*
|
|
6
6
|
* Create/edit form for roles.
|
|
7
7
|
*/
|
|
8
8
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
9
|
+
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
9
10
|
import { useRbacModule } from "./context";
|
|
11
|
+
import { AssignPermissions } from "./assign-permissions";
|
|
10
12
|
export const RbacForm = () => {
|
|
11
13
|
const { state, handleChange } = useRbacModule();
|
|
12
|
-
return (
|
|
14
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "name", label: "Role Name", required: true, type: "text", value: state.name || "", onChange: (e) => handleChange("name", e.target.value), error: state.errors.name, placeholder: "e.g. Class Teacher, Admin, Accountant", info: "A unique, descriptive name for this role" }), _jsx(EnhancedInput, { id: "description", label: "Description", type: "text", value: state.description || "", onChange: (e) => handleChange("description", e.target.value || undefined), error: state.errors.description, placeholder: "Brief description of what this role can do", info: "Optional description to clarify the role's purpose" })] }), state.id && (_jsxs(_Fragment, { children: [_jsx(Separator, {}), _jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-sm font-medium", children: "Permissions" }), _jsx(AssignPermissions, {})] })] }))] }));
|
|
13
15
|
};
|
|
@@ -16,16 +16,15 @@
|
|
|
16
16
|
* - `RbacPage` — root component that wraps with RbacProvider
|
|
17
17
|
*/
|
|
18
18
|
"use client";
|
|
19
|
-
import { jsx as _jsx
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
20
|
import { useMemo } from "react";
|
|
21
21
|
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
22
22
|
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
23
|
-
import { RBAC_ACTION_TYPES, RbacProvider, useRbacModule
|
|
23
|
+
import { RBAC_ACTION_TYPES, RbacProvider, useRbacModule } from "./context";
|
|
24
24
|
import { RbacFilter } from "./filter";
|
|
25
25
|
import { RbacForm } from "./form";
|
|
26
26
|
import { RbacMoreActions } from "./more-actions";
|
|
27
27
|
import { RbacView } from "./view";
|
|
28
|
-
import { AssignPermissions } from "./assign-permissions";
|
|
29
28
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
30
29
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
31
30
|
// ============================================================================
|
|
@@ -61,7 +60,6 @@ const createComponentInstances = () => ({
|
|
|
61
60
|
form: _jsx(RbacForm, {}),
|
|
62
61
|
moreActions: _jsx(RbacMoreActions, {}),
|
|
63
62
|
view: _jsx(RbacView, {}),
|
|
64
|
-
assignPermissions: _jsx(AssignPermissions, {}),
|
|
65
63
|
});
|
|
66
64
|
const createRbacConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, drawerTitleRbac, tableColumnHeaderActions, tableColumnHeaderDescription, tableColumnHeaderId, tableColumnHeaderName, tableColumnHeaderPermissions, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
|
|
67
65
|
const components = createComponentInstances();
|
|
@@ -133,10 +131,6 @@ const RbacPageInner = (props) => {
|
|
|
133
131
|
if (!hasPermission) {
|
|
134
132
|
return _jsx(RbacNoAccess, { moduleName: "Workspace" });
|
|
135
133
|
}
|
|
136
|
-
// If the assign-permissions drawer is open, render it inline instead
|
|
137
|
-
if (context.state.drawer === RBAC_DRAWER.ASSIGN_PERMISSIONS_DRAWER) {
|
|
138
|
-
return (_jsxs("div", { className: "p-4", children: [_jsx("div", { className: "mb-4 flex items-center gap-2", children: _jsx("button", { className: "text-muted-foreground text-sm underline", onClick: () => context.closeDrawer(), children: "\u2190 Back to roles" }) }), _jsx(AssignPermissions, {})] }));
|
|
139
|
-
}
|
|
140
134
|
return (_jsx("div", { className: "p-4", children: _jsx(GenericRbacPage, { context: context, overrideConfig: rbacConfig, tableBodyCols: tableBodyCols }) }));
|
|
141
135
|
};
|
|
142
136
|
export const RbacPage = (props) => (_jsx(RbacProvider, { children: _jsx(RbacPageInner, Object.assign({}, props)) }));
|