@appcorp/fusion-storybook 0.5.19 → 0.5.23
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/fee-structure/context/fee-structure-api-provider.js +48 -18
- package/base-modules/fee-structure/context/shared.d.ts +5 -0
- package/base-modules/fee-structure/context/shared.js +3 -0
- package/base-modules/fee-structure/context/use-fee-structure-module.d.ts +1 -0
- package/base-modules/fee-structure/context/use-fee-structure-module.js +35 -26
- package/base-modules/fee-structure/form.js +16 -48
- package/base-modules/fee-structure/more-actions.js +68 -14
- package/base-modules/fee-structure/page.js +52 -25
- package/base-modules/fee-structure/validate.d.ts +8 -1
- package/base-modules/fee-structure/validate.js +6 -1
- package/base-modules/fee-structure/view.js +20 -4
- package/base-modules/rbac/assign-permissions.js +5 -3
- package/base-modules/rbac/context.d.ts +8 -1
- package/base-modules/rbac/context.js +92 -65
- package/base-modules/rbac/page.js +6 -8
- package/base-modules/school/cache.js +0 -1
- package/base-modules/school/context.d.ts +0 -2
- package/base-modules/school/context.js +77 -18
- package/base-modules/school/drawer.js +1 -3
- package/base-modules/school/form.js +4 -23
- package/base-modules/school/page.js +2 -2
- package/base-modules/section/context.d.ts +6 -0
- package/base-modules/section/context.js +66 -34
- package/base-modules/section/form.js +2 -2
- package/base-modules/section/more-actions.js +71 -16
- package/base-modules/section/page.js +7 -3
- package/constants.d.ts +8 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +8 -4
- package/base-modules/rbac/filter.d.ts +0 -1
- package/base-modules/rbac/filter.js +0 -20
- package/base-modules/rbac/more-actions.d.ts +0 -1
- package/base-modules/rbac/more-actions.js +0 -12
- package/base-modules/school/filter.d.ts +0 -1
- package/base-modules/school/filter.js +0 -13
- package/base-modules/school/more-actions.d.ts +0 -1
- package/base-modules/school/more-actions.js +0 -13
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"use client";
|
|
20
20
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
21
|
import { useMemo } from "react";
|
|
22
|
+
import { useTranslations } from "next-intl";
|
|
22
23
|
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
23
24
|
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
24
25
|
import { useFeeStructureModule, FeeStructureProvider, FeeStructureApiProvider, } from "./context";
|
|
@@ -32,32 +33,56 @@ import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
|
32
33
|
// ============================================================================
|
|
33
34
|
// TABLE COLUMN CONFIGURATION (static — no runtime deps)
|
|
34
35
|
// ============================================================================
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const createTableBodyCols = (t) => {
|
|
37
|
+
const feeTypeLabels = {
|
|
38
|
+
TUITION: t("formOptionTuition"),
|
|
39
|
+
ADMISSION: t("formOptionAdmission"),
|
|
40
|
+
EXAM: t("formOptionExam"),
|
|
41
|
+
LIBRARY: t("formOptionLibrary"),
|
|
42
|
+
LABORATORY: t("formOptionLaboratory"),
|
|
43
|
+
TRANSPORT: t("formOptionTransport"),
|
|
44
|
+
SPORTS: t("formOptionSports"),
|
|
45
|
+
MISCELLANEOUS: t("formOptionMiscellaneous"),
|
|
46
|
+
LATE: t("formOptionLateFee"),
|
|
47
|
+
};
|
|
48
|
+
const frequencyLabels = {
|
|
49
|
+
Monthly: t("formOptionMonthly"),
|
|
50
|
+
Quarterly: t("formOptionQuarterly"),
|
|
51
|
+
"Semi-Annual": t("formOptionSemiAnnual"),
|
|
52
|
+
Annual: t("formOptionAnnual"),
|
|
53
|
+
"One-time": t("formOptionOneTime"),
|
|
54
|
+
};
|
|
55
|
+
return [
|
|
56
|
+
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
57
|
+
{ componentType: COMPONENT_TYPE.BOLD_TEXT, key: "name" },
|
|
58
|
+
{
|
|
59
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
60
|
+
key: "feeType",
|
|
61
|
+
textFormatter: (value) => { var _a; return (_a = feeTypeLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : String(value !== null && value !== void 0 ? value : ""); },
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
65
|
+
key: "amount",
|
|
66
|
+
textFormatter: (_, row) => {
|
|
67
|
+
var _a, _b, _c, _d;
|
|
68
|
+
const currency = (_c = (_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.currency) !== null && _c !== void 0 ? _c : "";
|
|
69
|
+
return `${currency} ${Number((_d = row.amount) !== null && _d !== void 0 ? _d : 0).toFixed(2)}`;
|
|
70
|
+
},
|
|
46
71
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
{
|
|
73
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
74
|
+
key: "frequency",
|
|
75
|
+
textFormatter: (value) => { var _a; return ((_a = frequencyLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : String(value !== null && value !== void 0 ? value : "")) || "N/A"; },
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
79
|
+
key: "description",
|
|
80
|
+
textFormatter: (_, row) => row.description || "N/A",
|
|
81
|
+
},
|
|
82
|
+
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
83
|
+
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
84
|
+
];
|
|
85
|
+
};
|
|
61
86
|
// ============================================================================
|
|
62
87
|
// COMPONENT FACTORY (creates JSX elements when config is created, not during render)
|
|
63
88
|
// ============================================================================
|
|
@@ -110,6 +135,8 @@ const GenericFeeStructurePage = createGenericModulePage();
|
|
|
110
135
|
// ============================================================================
|
|
111
136
|
const FeeStructurePageInner = (props) => {
|
|
112
137
|
const context = useFeeStructureModule();
|
|
138
|
+
const t = useTranslations("feeStructure");
|
|
139
|
+
const tableBodyCols = useMemo(() => createTableBodyCols(t), [t]);
|
|
113
140
|
const feeStructureConfig = useMemo(() => createFeeStructureConfig({
|
|
114
141
|
clearFilters: context.clearFilters,
|
|
115
142
|
drawerButtonCancel: props.drawerButtonCancel,
|
|
@@ -9,6 +9,7 @@ export declare const VALIDATION_KEYS: {
|
|
|
9
9
|
readonly name: "validationFeeStructureNameRequired";
|
|
10
10
|
readonly feeType: "validationFeeStructureFeeTypeRequired";
|
|
11
11
|
readonly amountPositive: "validationFeeStructureAmountPositive";
|
|
12
|
+
readonly frequency: "validationFeeStructureFrequencyInvalid";
|
|
12
13
|
readonly idForUpdate: "validationFeeStructureIdForUpdateRequired";
|
|
13
14
|
};
|
|
14
15
|
export declare const feeStructureFormValidation: z.ZodObject<{
|
|
@@ -16,7 +17,13 @@ export declare const feeStructureFormValidation: z.ZodObject<{
|
|
|
16
17
|
feeType: z.ZodEnum<typeof FEE_TYPE>;
|
|
17
18
|
amount: z.ZodNumber;
|
|
18
19
|
classId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
19
|
-
frequency: z.ZodNullable<z.ZodOptional<z.
|
|
20
|
+
frequency: z.ZodUnion<[z.ZodNullable<z.ZodOptional<z.ZodEnum<{
|
|
21
|
+
Monthly: "Monthly";
|
|
22
|
+
Quarterly: "Quarterly";
|
|
23
|
+
"Semi-Annual": "Semi-Annual";
|
|
24
|
+
Annual: "Annual";
|
|
25
|
+
"One-time": "One-time";
|
|
26
|
+
}>>>, z.ZodLiteral<"">]>;
|
|
20
27
|
description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
21
28
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
22
29
|
}, z.core.$strip>;
|
|
@@ -12,6 +12,7 @@ export const VALIDATION_KEYS = {
|
|
|
12
12
|
name: "validationFeeStructureNameRequired",
|
|
13
13
|
feeType: "validationFeeStructureFeeTypeRequired",
|
|
14
14
|
amountPositive: "validationFeeStructureAmountPositive",
|
|
15
|
+
frequency: "validationFeeStructureFrequencyInvalid",
|
|
15
16
|
idForUpdate: "validationFeeStructureIdForUpdateRequired",
|
|
16
17
|
};
|
|
17
18
|
export const feeStructureFormValidation = z.object({
|
|
@@ -19,7 +20,11 @@ export const feeStructureFormValidation = z.object({
|
|
|
19
20
|
feeType: z.nativeEnum(FEE_TYPE, { error: VALIDATION_KEYS.feeType }),
|
|
20
21
|
amount: z.number().positive(VALIDATION_KEYS.amountPositive),
|
|
21
22
|
classId: z.string().optional().nullable(),
|
|
22
|
-
frequency: z
|
|
23
|
+
frequency: z
|
|
24
|
+
.enum(["Monthly", "Quarterly", "Semi-Annual", "Annual", "One-time"])
|
|
25
|
+
.optional()
|
|
26
|
+
.nullable()
|
|
27
|
+
.or(z.literal("")),
|
|
23
28
|
description: z.string().optional().nullable(),
|
|
24
29
|
enabled: z.boolean().optional(),
|
|
25
30
|
});
|
|
@@ -14,13 +14,29 @@ import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
|
14
14
|
import { useTranslations } from "next-intl";
|
|
15
15
|
import { formatValue } from "@react-pakistan/util-functions/general/format-value";
|
|
16
16
|
export const FeeStructureView = () => {
|
|
17
|
-
var _a;
|
|
17
|
+
var _a, _b, _c;
|
|
18
18
|
const { state } = useFeeStructureModule();
|
|
19
19
|
const { amount, description, enabled, feeType, frequency, name } = state;
|
|
20
20
|
const t = useTranslations("feeStructure");
|
|
21
21
|
const workspace = getCachedWorkspaceSync();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const feeTypeLabels = {
|
|
23
|
+
TUITION: t("formOptionTuition"),
|
|
24
|
+
ADMISSION: t("formOptionAdmission"),
|
|
25
|
+
EXAM: t("formOptionExam"),
|
|
26
|
+
LIBRARY: t("formOptionLibrary"),
|
|
27
|
+
LABORATORY: t("formOptionLaboratory"),
|
|
28
|
+
TRANSPORT: t("formOptionTransport"),
|
|
29
|
+
SPORTS: t("formOptionSports"),
|
|
30
|
+
MISCELLANEOUS: t("formOptionMiscellaneous"),
|
|
31
|
+
LATE: t("formOptionLateFee"),
|
|
32
|
+
};
|
|
33
|
+
const frequencyLabels = {
|
|
34
|
+
Monthly: t("formOptionMonthly"),
|
|
35
|
+
Quarterly: t("formOptionQuarterly"),
|
|
36
|
+
"Semi-Annual": t("formOptionSemiAnnual"),
|
|
37
|
+
Annual: t("formOptionAnnual"),
|
|
38
|
+
"One-time": t("formOptionOneTime"),
|
|
39
|
+
};
|
|
40
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(DollarSign, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionFeeStructureDetails") })] }), _jsx(CardDescription, { children: t("viewSectionFeeStructureRecordDetails") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formNameLabel") }), _jsx("p", { className: "text-base font-semibold", children: formatValue(name) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formFeeTypeLabel") }), _jsx(Badge, { variant: "secondary", children: (_a = feeTypeLabels[String(feeType !== null && feeType !== void 0 ? feeType : "")]) !== null && _a !== void 0 ? _a : formatValue(feeType) })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formAmountLabel") }), _jsxs("p", { className: "text-base", children: [(_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.currency, " ", Number(amount !== null && amount !== void 0 ? amount : 0).toFixed(2)] })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formFrequencyLabel") }), _jsx("p", { className: "text-base", children: (_c = frequencyLabels[String(frequency !== null && frequency !== void 0 ? frequency : "")]) !== null && _c !== void 0 ? _c : formatValue(frequency) })] })] }) })] }), description ? (_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionAdditionalDetails") })] }), _jsx(CardDescription, { children: t("viewFieldOptionalNotes") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsx("p", { className: "text-base", children: description }) })] })) : null, _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CheckCircle2, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewFieldStatus") })] }), _jsx(CardDescription, { children: t("viewFieldRecordState") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: [enabled ? (_jsx(CheckCircle2, { className: "h-3 w-3" })) : (_jsx(XCircle, { className: "h-3 w-3" })), enabled ? t("badgeActive") : t("badgeInactive")] }) })] })] }));
|
|
25
41
|
};
|
|
26
42
|
FeeStructureView.displayName = "FeeStructureView";
|
|
@@ -31,6 +31,9 @@ export const AssignPermissions = () => {
|
|
|
31
31
|
[ACCESS_LEVEL.READ_WRITE]: t("formOptionReadWrite"),
|
|
32
32
|
};
|
|
33
33
|
const assignedIds = new Set(state.rolePermissions.map((rp) => rp.permissionId));
|
|
34
|
+
if (state.availablePermissionsLoading) {
|
|
35
|
+
return (_jsx("p", { className: "text-muted-foreground text-sm", children: t("viewTextLoadingPermissions") }));
|
|
36
|
+
}
|
|
34
37
|
// Group permissions by module name
|
|
35
38
|
const grouped = state.availablePermissions.reduce((acc, perm) => {
|
|
36
39
|
if (!acc[perm.module])
|
|
@@ -44,14 +47,13 @@ export const AssignPermissions = () => {
|
|
|
44
47
|
}) }), modules.length === 0 ? (_jsx("div", { className: "rounded-md border border-dashed p-6 text-center", children: _jsx("p", { className: "text-muted-foreground text-sm", children: t("viewTextNoPermissionsFound") }) })) : (modules.map((module) => (_jsxs("div", { children: [_jsxs("div", { className: "mb-3 flex items-center gap-3", children: [_jsx("p", { className: "text-sm font-semibold tracking-wide capitalize", children: module }), _jsx(Separator, { className: "flex-1" })] }), _jsx("div", { className: "space-y-1 pl-1", children: grouped[module].map((perm) => {
|
|
45
48
|
const isAssigned = assignedIds.has(perm.id);
|
|
46
49
|
return (_jsxs("div", { className: [
|
|
47
|
-
"flex
|
|
50
|
+
"flex items-center gap-3 rounded-md px-3 py-2",
|
|
48
51
|
"hover:bg-muted transition-colors select-none",
|
|
49
52
|
state.togglingPermission
|
|
50
53
|
? "pointer-events-none opacity-50"
|
|
51
54
|
: "",
|
|
52
55
|
]
|
|
53
56
|
.filter(Boolean)
|
|
54
|
-
.join(" "),
|
|
55
|
-
handleTogglePermission(perm.id), children: [_jsx(EnhancedCheckbox, { label: perm.module, checked: isAssigned, onCheckedChange: () => handleTogglePermission(perm.id), disabled: state.togglingPermission }), _jsx(Badge, { variant: ACCESS_LEVEL_VARIANT[perm.access], className: "shrink-0 text-xs", children: ACCESS_LEVEL_LABELS[perm.access] })] }, perm.id));
|
|
57
|
+
.join(" "), children: [_jsx(EnhancedCheckbox, { id: `perm-${perm.id}`, label: `${perm.module} — ${ACCESS_LEVEL_LABELS[perm.access]}`, checked: isAssigned, onCheckedChange: () => handleTogglePermission(perm.id), disabled: state.togglingPermission }), _jsx(Badge, { variant: ACCESS_LEVEL_VARIANT[perm.access], className: "shrink-0 text-xs", children: ACCESS_LEVEL_LABELS[perm.access] })] }, perm.id));
|
|
56
58
|
}) })] }, module))))] }));
|
|
57
59
|
};
|
|
@@ -26,6 +26,7 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
26
26
|
name: string;
|
|
27
27
|
rolePermissions: RolePermissionBE[];
|
|
28
28
|
availablePermissions: PermissionBE[];
|
|
29
|
+
availablePermissionsLoading: boolean;
|
|
29
30
|
togglingPermission: boolean;
|
|
30
31
|
count: number;
|
|
31
32
|
items: RoleBE[];
|
|
@@ -43,6 +44,7 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
43
44
|
name: string;
|
|
44
45
|
rolePermissions: RolePermissionBE[];
|
|
45
46
|
availablePermissions: PermissionBE[];
|
|
47
|
+
availablePermissionsLoading: boolean;
|
|
46
48
|
togglingPermission: boolean;
|
|
47
49
|
count: number;
|
|
48
50
|
items: RoleBE[];
|
|
@@ -62,6 +64,7 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
62
64
|
name: string;
|
|
63
65
|
rolePermissions: RolePermissionBE[];
|
|
64
66
|
availablePermissions: PermissionBE[];
|
|
67
|
+
availablePermissionsLoading: boolean;
|
|
65
68
|
togglingPermission: boolean;
|
|
66
69
|
count: number;
|
|
67
70
|
items: RoleBE[];
|
|
@@ -79,6 +82,7 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
79
82
|
name: string;
|
|
80
83
|
rolePermissions: RolePermissionBE[];
|
|
81
84
|
availablePermissions: PermissionBE[];
|
|
85
|
+
availablePermissionsLoading: boolean;
|
|
82
86
|
togglingPermission: boolean;
|
|
83
87
|
count: number;
|
|
84
88
|
items: RoleBE[];
|
|
@@ -96,6 +100,7 @@ export declare const RBAC_ACTION_TYPES: {
|
|
|
96
100
|
name: string;
|
|
97
101
|
rolePermissions: RolePermissionBE[];
|
|
98
102
|
availablePermissions: PermissionBE[];
|
|
103
|
+
availablePermissionsLoading: boolean;
|
|
99
104
|
togglingPermission: boolean;
|
|
100
105
|
count: number;
|
|
101
106
|
items: RoleBE[];
|
|
@@ -123,7 +128,7 @@ export declare const useRbacModule: () => {
|
|
|
123
128
|
resetRecordFormState: () => void;
|
|
124
129
|
handleCreate: () => void;
|
|
125
130
|
handleDelete: (row?: TableRow) => void;
|
|
126
|
-
handleEdit: (row?: TableRow) =>
|
|
131
|
+
handleEdit: (row?: TableRow) => void;
|
|
127
132
|
handleFilters: () => void;
|
|
128
133
|
handleMoreActions: () => void;
|
|
129
134
|
handleNextClick: () => void;
|
|
@@ -134,6 +139,7 @@ export declare const useRbacModule: () => {
|
|
|
134
139
|
handleSubmit: () => void;
|
|
135
140
|
handleTogglePermission: (permissionId: string) => Promise<void>;
|
|
136
141
|
handleView: (row?: TableRow) => void;
|
|
142
|
+
loadAvailablePermissions: () => Promise<void>;
|
|
137
143
|
headerActions: {
|
|
138
144
|
enabled: boolean;
|
|
139
145
|
handleOnClick: () => void;
|
|
@@ -154,6 +160,7 @@ export declare const useRbacModule: () => {
|
|
|
154
160
|
name: string;
|
|
155
161
|
rolePermissions: RolePermissionBE[];
|
|
156
162
|
availablePermissions: PermissionBE[];
|
|
163
|
+
availablePermissionsLoading: boolean;
|
|
157
164
|
togglingPermission: boolean;
|
|
158
165
|
count: number;
|
|
159
166
|
items: RoleBE[];
|
|
@@ -22,6 +22,7 @@ import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
|
22
22
|
import { useTheme } from "next-themes";
|
|
23
23
|
import { useTranslations } from "next-intl";
|
|
24
24
|
import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
|
|
25
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
25
26
|
import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
|
|
26
27
|
import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
|
|
27
28
|
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
@@ -55,6 +56,7 @@ const rbacConfig = {
|
|
|
55
56
|
// Permission State
|
|
56
57
|
rolePermissions: [],
|
|
57
58
|
availablePermissions: [],
|
|
59
|
+
availablePermissionsLoading: false,
|
|
58
60
|
togglingPermission: false,
|
|
59
61
|
// List Data
|
|
60
62
|
count: 0,
|
|
@@ -94,18 +96,16 @@ export const useRbacModule = () => {
|
|
|
94
96
|
// ============================================================================
|
|
95
97
|
// 1.4.2 API PARAMETERS
|
|
96
98
|
// ============================================================================
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const updateParams = useMemo(() => ({
|
|
103
|
-
|
|
104
|
-
name: state.name,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
108
|
-
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
99
|
+
const workspace = getCachedWorkspaceSync();
|
|
100
|
+
const workspaceId = (workspace === null || workspace === void 0 ? void 0 : workspace.id) || "";
|
|
101
|
+
const listParams = useMemo(() => (Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit,
|
|
102
|
+
// Custom roles for this workspace + the global system roles.
|
|
103
|
+
workspaceId, includeSystem: "true" }, (debouncedQuery ? { searchQuery: debouncedQuery } : {}))), [state.currentPage, state.pageLimit, debouncedQuery, workspaceId]);
|
|
104
|
+
const updateParams = useMemo(() => (Object.assign(Object.assign({}, (state.id ? { id: state.id } : {})), {
|
|
105
|
+
// Required for create and used by the API to authorize updates/deletes.
|
|
106
|
+
workspaceId, name: state.name, description: state.description })), [state.id, state.name, state.description, workspaceId]);
|
|
107
|
+
const byIdParams = useMemo(() => ({ id: state.id, workspaceId }), [state.id, workspaceId]);
|
|
108
|
+
const deleteParams = useMemo(() => ({ id: state.id, workspaceId }), [state.id, workspaceId]);
|
|
109
109
|
// ============================================================================
|
|
110
110
|
// 1.4.3 UTILITIES
|
|
111
111
|
// ============================================================================
|
|
@@ -127,6 +127,33 @@ export const useRbacModule = () => {
|
|
|
127
127
|
payload: { drawer: null },
|
|
128
128
|
});
|
|
129
129
|
}, [dispatch]);
|
|
130
|
+
const loadAvailablePermissions = useCallback(async () => {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
dispatch({
|
|
133
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
134
|
+
payload: { key: "availablePermissionsLoading", value: true },
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
const res = await fetch(`${RBAC_API_ROUTES.PERMISSIONS_LIST}?currentPage=1&pageLimit=500`, { headers: { "Content-Type": "application/json" } });
|
|
138
|
+
const data = (await res.json().catch(() => ({})));
|
|
139
|
+
if (!res.ok) {
|
|
140
|
+
throw new Error((_a = data.error) !== null && _a !== void 0 ? _a : t("messagesFetchFailed"));
|
|
141
|
+
}
|
|
142
|
+
dispatch({
|
|
143
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
144
|
+
payload: { key: "availablePermissions", value: (_b = data.items) !== null && _b !== void 0 ? _b : [] },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
showToast(error instanceof Error ? error.message : t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
dispatch({
|
|
152
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
153
|
+
payload: { key: "availablePermissionsLoading", value: false },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}, [dispatch, showToast, t]);
|
|
130
157
|
// ============================================================================
|
|
131
158
|
// 1.4.4 API CALLBACKS
|
|
132
159
|
// ============================================================================
|
|
@@ -147,21 +174,26 @@ export const useRbacModule = () => {
|
|
|
147
174
|
}
|
|
148
175
|
}, [dispatch, showToast, t]);
|
|
149
176
|
const updateCallback = useCallback(({ data, error }) => {
|
|
150
|
-
var _a;
|
|
177
|
+
var _a, _b;
|
|
151
178
|
if (error) {
|
|
152
|
-
|
|
179
|
+
dispatch({
|
|
180
|
+
type: RBAC_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
181
|
+
payload: { disableSaveButton: false },
|
|
182
|
+
});
|
|
183
|
+
showToast((_a = data === null || data === void 0 ? void 0 : data.error) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
153
184
|
return;
|
|
154
185
|
}
|
|
155
186
|
if (data) {
|
|
156
187
|
const isCreated = isCreatedOrUpdated(data);
|
|
157
188
|
showToast(isCreated ? t("messagesRoleCreated") : t("messagesRoleUpdated"), TOAST_VARIANT.SUCCESS);
|
|
158
189
|
resetFormAndCloseDrawer();
|
|
159
|
-
(
|
|
190
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
160
191
|
}
|
|
161
|
-
}, [resetFormAndCloseDrawer, showToast, t]);
|
|
192
|
+
}, [dispatch, resetFormAndCloseDrawer, showToast, t]);
|
|
162
193
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
194
|
+
var _a;
|
|
163
195
|
if (error) {
|
|
164
|
-
showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
196
|
+
showToast((_a = data === null || data === void 0 ? void 0 : data.error) !== null && _a !== void 0 ? _a : t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
165
197
|
return;
|
|
166
198
|
}
|
|
167
199
|
if (data) {
|
|
@@ -172,14 +204,14 @@ export const useRbacModule = () => {
|
|
|
172
204
|
}
|
|
173
205
|
}, [dispatch, showToast, t]);
|
|
174
206
|
const deleteCallback = useCallback(({ data, error }) => {
|
|
175
|
-
var _a;
|
|
207
|
+
var _a, _b;
|
|
176
208
|
if (error) {
|
|
177
|
-
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
209
|
+
showToast((_a = data === null || data === void 0 ? void 0 : data.error) !== null && _a !== void 0 ? _a : t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
178
210
|
return;
|
|
179
211
|
}
|
|
180
212
|
if (data) {
|
|
181
213
|
showToast(t("messagesRoleDeleted"), TOAST_VARIANT.SUCCESS);
|
|
182
|
-
(
|
|
214
|
+
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
183
215
|
}
|
|
184
216
|
}, [showToast, t]);
|
|
185
217
|
// ============================================================================
|
|
@@ -276,30 +308,31 @@ export const useRbacModule = () => {
|
|
|
276
308
|
payload: { drawer: RBAC_DRAWER.VIEW_DRAWER },
|
|
277
309
|
});
|
|
278
310
|
}, [byIdFetchNow, dispatch, resetRecordFormState]);
|
|
279
|
-
const handleEdit = useCallback(
|
|
311
|
+
const handleEdit = useCallback((row) => {
|
|
280
312
|
resetRecordFormState();
|
|
281
313
|
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
282
|
-
// loadAvailablePermissions is declared below in 1.4.7
|
|
283
|
-
// await loadAvailablePermissions();
|
|
284
314
|
dispatch({
|
|
285
315
|
type: RBAC_ACTION_TYPES.SET_DRAWER,
|
|
286
316
|
payload: { drawer: RBAC_DRAWER.FORM_DRAWER },
|
|
287
317
|
});
|
|
288
|
-
|
|
318
|
+
// The drawer opens immediately; the catalog renders its loading state.
|
|
319
|
+
void loadAvailablePermissions();
|
|
320
|
+
}, [byIdFetchNow, dispatch, loadAvailablePermissions, resetRecordFormState]);
|
|
289
321
|
const handleDelete = useCallback((row) => {
|
|
290
322
|
if (!confirm(t("messagesDeleteConfirmation")))
|
|
291
323
|
return;
|
|
292
324
|
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
293
|
-
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
|
|
325
|
+
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, workspaceId }),
|
|
294
326
|
});
|
|
295
|
-
}, [deleteFetchNow, t]);
|
|
327
|
+
}, [deleteFetchNow, t, workspaceId]);
|
|
296
328
|
// header actions
|
|
297
329
|
const handleCreate = useCallback(() => {
|
|
330
|
+
resetRecordFormState();
|
|
298
331
|
dispatch({
|
|
299
332
|
type: RBAC_ACTION_TYPES.SET_DRAWER,
|
|
300
333
|
payload: { drawer: RBAC_DRAWER.FORM_DRAWER },
|
|
301
334
|
});
|
|
302
|
-
}, [dispatch]);
|
|
335
|
+
}, [dispatch, resetRecordFormState]);
|
|
303
336
|
const handleFilters = useCallback(() => {
|
|
304
337
|
dispatch({
|
|
305
338
|
type: RBAC_ACTION_TYPES.SET_DRAWER,
|
|
@@ -396,37 +429,41 @@ export const useRbacModule = () => {
|
|
|
396
429
|
// }
|
|
397
430
|
// }, [dispatch, showToast, t]);
|
|
398
431
|
const handleTogglePermission = useCallback(async (permissionId) => {
|
|
432
|
+
var _a, _b;
|
|
399
433
|
const existing = state.rolePermissions.find((rp) => rp.permissionId === permissionId);
|
|
400
434
|
dispatch({
|
|
401
435
|
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
402
436
|
payload: { key: "togglingPermission", value: true },
|
|
403
437
|
});
|
|
404
438
|
try {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
});
|
|
439
|
+
const res = await fetch(RBAC_API_ROUTES.ROLE_PERMISSION_UNIT, {
|
|
440
|
+
method: existing ? "DELETE" : "PUT",
|
|
441
|
+
headers: { "Content-Type": "application/json" },
|
|
442
|
+
body: JSON.stringify(existing ? { id: existing.id } : { roleId: state.id, permissionId }),
|
|
443
|
+
});
|
|
444
|
+
const body = (await res.json().catch(() => ({})));
|
|
445
|
+
if (!res.ok) {
|
|
446
|
+
throw new Error((_a = body.error) !== null && _a !== void 0 ? _a : t("messagesFetchFailed"));
|
|
414
447
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
448
|
+
// Reflect the change immediately; the refetch below reconciles.
|
|
449
|
+
const next = existing
|
|
450
|
+
? state.rolePermissions.filter((rp) => rp.permissionId !== permissionId)
|
|
451
|
+
: [
|
|
452
|
+
...state.rolePermissions,
|
|
453
|
+
{
|
|
454
|
+
id: (_b = body.id) !== null && _b !== void 0 ? _b : permissionId,
|
|
455
|
+
permissionId,
|
|
456
|
+
allowed: true,
|
|
421
457
|
},
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
458
|
+
];
|
|
459
|
+
dispatch({
|
|
460
|
+
type: RBAC_ACTION_TYPES.SET_INPUT_FIELD,
|
|
461
|
+
payload: { key: "rolePermissions", value: next },
|
|
462
|
+
});
|
|
426
463
|
await (byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: state.id } }));
|
|
427
464
|
}
|
|
428
|
-
catch (
|
|
429
|
-
showToast(t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
465
|
+
catch (error) {
|
|
466
|
+
showToast(error instanceof Error ? error.message : t("messagesFetchFailed"), TOAST_VARIANT.ERROR);
|
|
430
467
|
}
|
|
431
468
|
finally {
|
|
432
469
|
dispatch({
|
|
@@ -440,24 +477,12 @@ export const useRbacModule = () => {
|
|
|
440
477
|
// ============================================================================
|
|
441
478
|
const headerActions = useMemo(() => [
|
|
442
479
|
{
|
|
443
|
-
enabled:
|
|
444
|
-
handleOnClick: handleMoreActions,
|
|
445
|
-
label: t("actionsButtonMoreActions"),
|
|
446
|
-
order: 0,
|
|
447
|
-
},
|
|
448
|
-
{
|
|
449
|
-
enabled: false,
|
|
450
|
-
handleOnClick: handleFilters,
|
|
451
|
-
label: t("actionsButtonFilters"),
|
|
452
|
-
order: 1,
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
enabled: false,
|
|
480
|
+
enabled: true,
|
|
456
481
|
handleOnClick: handleCreate,
|
|
457
482
|
label: t("actionsButtonAddItem"),
|
|
458
|
-
order:
|
|
483
|
+
order: 0,
|
|
459
484
|
},
|
|
460
|
-
], [handleCreate,
|
|
485
|
+
], [handleCreate, t]);
|
|
461
486
|
const rowActions = useMemo(() => [
|
|
462
487
|
{
|
|
463
488
|
enabled: true,
|
|
@@ -466,16 +491,17 @@ export const useRbacModule = () => {
|
|
|
466
491
|
order: 1,
|
|
467
492
|
},
|
|
468
493
|
{
|
|
469
|
-
enabled:
|
|
494
|
+
enabled: (row) => !(row === null || row === void 0 ? void 0 : row.isSystem),
|
|
470
495
|
handleOnClick: handleEdit,
|
|
471
496
|
label: t("actionsButtonEdit"),
|
|
472
497
|
order: 2,
|
|
473
498
|
},
|
|
474
499
|
{
|
|
475
|
-
enabled:
|
|
500
|
+
enabled: (row) => !(row === null || row === void 0 ? void 0 : row.isSystem),
|
|
476
501
|
handleOnClick: handleDelete,
|
|
477
502
|
label: t("actionsButtonDelete"),
|
|
478
503
|
order: 4,
|
|
504
|
+
variant: "destructive",
|
|
479
505
|
},
|
|
480
506
|
], [handleDelete, handleEdit, handleView, t]);
|
|
481
507
|
// ============================================================================
|
|
@@ -514,6 +540,7 @@ export const useRbacModule = () => {
|
|
|
514
540
|
handleSubmit,
|
|
515
541
|
handleTogglePermission,
|
|
516
542
|
handleView,
|
|
543
|
+
loadAvailablePermissions,
|
|
517
544
|
headerActions,
|
|
518
545
|
listError,
|
|
519
546
|
listFetchNow,
|
|
@@ -21,9 +21,7 @@ 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
23
|
import { RBAC_ACTION_TYPES, RbacProvider, useRbacModule } from "./context";
|
|
24
|
-
import { RbacFilter } from "./filter";
|
|
25
24
|
import { RbacForm } from "./form";
|
|
26
|
-
import { RbacMoreActions } from "./more-actions";
|
|
27
25
|
import { RbacView } from "./view";
|
|
28
26
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
29
27
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
@@ -56,9 +54,7 @@ const tableBodyCols = [
|
|
|
56
54
|
// COMPONENT FACTORY (creates JSX elements when config is created, not during render)
|
|
57
55
|
// ============================================================================
|
|
58
56
|
const createComponentInstances = () => ({
|
|
59
|
-
filter: _jsx(RbacFilter, {}),
|
|
60
57
|
form: _jsx(RbacForm, {}),
|
|
61
|
-
moreActions: _jsx(RbacMoreActions, {}),
|
|
62
58
|
view: _jsx(RbacView, {}),
|
|
63
59
|
});
|
|
64
60
|
const createRbacConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderDescription, tableColumnHeaderId, tableColumnHeaderName, tableColumnHeaderPermissions, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
|
|
@@ -73,10 +69,10 @@ const createRbacConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, draw
|
|
|
73
69
|
drawerMoreActionsTitle,
|
|
74
70
|
drawerViewDescription,
|
|
75
71
|
drawerViewTitle,
|
|
76
|
-
filterContent:
|
|
72
|
+
filterContent: null,
|
|
77
73
|
formContent: components.form,
|
|
78
74
|
moduleName: "rbac",
|
|
79
|
-
moreActionsContent:
|
|
75
|
+
moreActionsContent: null,
|
|
80
76
|
onClearFilters: () => {
|
|
81
77
|
dispatch({ type: RBAC_ACTION_TYPES.RESET_FORM });
|
|
82
78
|
},
|
|
@@ -142,12 +138,14 @@ const RbacPageInner = (props) => {
|
|
|
142
138
|
props.tableSearchPlaceholder,
|
|
143
139
|
props.tableTitle,
|
|
144
140
|
]);
|
|
141
|
+
// Role management is an admin surface (matches the API's admins-only
|
|
142
|
+
// policy), not the broader workspace-settings gate.
|
|
145
143
|
const hasPermission = resolveRbacPermissions({
|
|
146
144
|
userRole: props.userRole,
|
|
147
|
-
moduleName: "
|
|
145
|
+
moduleName: "Role Based Access Control",
|
|
148
146
|
});
|
|
149
147
|
if (!hasPermission) {
|
|
150
|
-
return _jsx(RbacNoAccess, { moduleName: "
|
|
148
|
+
return _jsx(RbacNoAccess, { moduleName: "Role Based Access Control" });
|
|
151
149
|
}
|
|
152
150
|
return (_jsx("div", { className: "p-4", children: _jsx(GenericRbacPage, { context: context, overrideConfig: rbacConfig, tableBodyCols: tableBodyCols }) }));
|
|
153
151
|
};
|
|
@@ -12,7 +12,6 @@ import { LS_KEYS } from "../../constants";
|
|
|
12
12
|
const CACHE_CONFIG = {
|
|
13
13
|
cacheKey: LS_KEYS.ACCOUNT_SCHOOL,
|
|
14
14
|
apiUrl: SCHOOL_API_ROUTES.UNIT,
|
|
15
|
-
responseKey: "item",
|
|
16
15
|
};
|
|
17
16
|
// ============================================================================
|
|
18
17
|
// CACHE WRAPPERS
|