From 6ffe7746c8b5c690de5b2c2e1a1503d8e47f9102 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan <43689091+ichsankurnia@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:37:39 +0700 Subject: [PATCH] Improve RBAC management and permissions UI Unify interactive and read-only role permission rows, refine role and menu forms and labels, and correct the access-permissions sidebar route. Update role payloads and admin-menu handling. --- app/admin/components/Breadcrumb.tsx | 19 +- .../component/ConfirmAsync.tsx | 2 +- .../action-permissions/component/index.tsx | 20 +- .../rbac/menu/component/ConfirmAsync.tsx | 2 +- app/admin/rbac/menu/component/Form.tsx | 118 +++++---- app/admin/rbac/menu/component/index.tsx | 35 +-- app/admin/rbac/user-role/[id]/page.tsx | 136 +++++------ .../rbac/user-role/component/ConfirmAsync.tsx | 7 +- .../component/MenuPermissionTree.tsx | 196 ++++----------- .../rbac/user-role/component/RoleForm.tsx | 78 +++--- app/admin/rbac/user-role/component/index.tsx | 22 +- app/admin/rbac/user-role/create/page.tsx | 3 +- app/admin/rbac/user-role/edit/[id]/page.tsx | 3 +- app/admin/rbac/user-role/page.tsx | 6 +- app/globals.css | 20 +- components/rbac/rbac-badge.tsx | 2 + components/rbac/role-permission-row.tsx | 223 ++++++++++++++++++ lib/data-sidebar.tsx | 2 +- lib/tabler-icons.ts | 2 + types/rbac.ts | 2 +- 20 files changed, 542 insertions(+), 356 deletions(-) create mode 100644 components/rbac/rbac-badge.tsx create mode 100644 components/rbac/role-permission-row.tsx diff --git a/app/admin/components/Breadcrumb.tsx b/app/admin/components/Breadcrumb.tsx index e78247f..3abdc7d 100644 --- a/app/admin/components/Breadcrumb.tsx +++ b/app/admin/components/Breadcrumb.tsx @@ -3,6 +3,21 @@ import { usePathname } from 'next/navigation'; import Link from 'next/link'; +const SEGMENT_LABELS: Record = { + 'rbac': 'RBAC', + 'action-pemission': 'Access Permissions', + 'action-permissions': 'Access Permissions', + 'menu': 'Menu Management', + 'user-role': 'Role Management', + 'create': 'Create', + 'edit': 'Edit', + 'administration': 'Administration', + 'company': 'Company', + 'user': 'User', + 'division': 'Division', + 'area': 'Area', +}; + export default function AdminBreadcrumb() { const pathname = usePathname(); @@ -12,6 +27,9 @@ export default function AdminBreadcrumb() { .slice(1); // skip 'admin' const formatSegment = (seg: string) => { + if (SEGMENT_LABELS[seg.toLowerCase()]) { + return SEGMENT_LABELS[seg.toLowerCase()]; + } return seg .split('-') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) @@ -55,4 +73,3 @@ export default function AdminBreadcrumb() { ); } - diff --git a/app/admin/rbac/action-permissions/component/ConfirmAsync.tsx b/app/admin/rbac/action-permissions/component/ConfirmAsync.tsx index a52010b..3d44162 100644 --- a/app/admin/rbac/action-permissions/component/ConfirmAsync.tsx +++ b/app/admin/rbac/action-permissions/component/ConfirmAsync.tsx @@ -64,7 +64,7 @@ const ConfirmAsync: FC = ({ title, description, onConfirm, okText, cancel {isLoading && ( )} - {okText || 'Continue'} + {okText || 'Delete'} diff --git a/app/admin/rbac/action-permissions/component/index.tsx b/app/admin/rbac/action-permissions/component/index.tsx index d89d75c..85d1a50 100644 --- a/app/admin/rbac/action-permissions/component/index.tsx +++ b/app/admin/rbac/action-permissions/component/index.tsx @@ -1,6 +1,7 @@ 'use client'; import { ChangeEvent, FC, useEffect, useState } from 'react'; +import { useRouter } from 'next/navigation'; import { MoreHorizontalIcon } from 'lucide-react'; import { Table } from 'antd'; import { TableProps, type ColumnsType } from 'antd/es/table'; @@ -27,6 +28,7 @@ const ComponentPermissionPage: FC = ({ data }) => { const [searchText, setSearchText] = useState(''); const axios = useAxiosAuth(); + const router = useRouter(); useEffect(() => { if (data && Array.isArray(data)) { @@ -63,7 +65,7 @@ const ComponentPermissionPage: FC = ({ data }) => { const columns: ColumnsType = [ { - title: 'Num', + title: 'No', dataIndex: 'key', width: 70, align: 'center', @@ -91,7 +93,7 @@ const ComponentPermissionPage: FC = ({ data }) => { ), }, { - title: 'Action', + title: 'Actions', key: 'action', width: 80, align: 'center', @@ -101,7 +103,7 @@ const ComponentPermissionPage: FC = ({ data }) => { @@ -111,20 +113,20 @@ const ComponentPermissionPage: FC = ({ data }) => { setShowFormDialog(true); }} > - Edit + Edit Permission - Delete + Delete Permission handleDelete(record.id)} - onOkSuccess={() => { }} + onOkSuccess={() => router.refresh()} /> ), @@ -168,7 +170,7 @@ const ComponentPermissionPage: FC = ({ data }) => { }} > - Create New Permission + Create Permission @@ -183,7 +185,7 @@ const ComponentPermissionPage: FC = ({ data }) => {

No permissions found

- {searchText ? 'Try adjusting your search criteria.' : 'Click "Create New Permission" to add the first permission.'} + {searchText ? 'Try adjusting your search criteria.' : 'Click "Create Permission" to add the first permission.'}

), diff --git a/app/admin/rbac/menu/component/ConfirmAsync.tsx b/app/admin/rbac/menu/component/ConfirmAsync.tsx index 29051b2..d93bdba 100644 --- a/app/admin/rbac/menu/component/ConfirmAsync.tsx +++ b/app/admin/rbac/menu/component/ConfirmAsync.tsx @@ -64,7 +64,7 @@ const ConfirmAsync: FC = ({ title, description, onConfirm, okText, cancel {isLoading && ( )} - {okText || 'Continue'} + {okText || 'Delete'} diff --git a/app/admin/rbac/menu/component/Form.tsx b/app/admin/rbac/menu/component/Form.tsx index d96fb56..c839683 100644 --- a/app/admin/rbac/menu/component/Form.tsx +++ b/app/admin/rbac/menu/component/Form.tsx @@ -15,7 +15,7 @@ import { Icons } from "@/components/Icons"; import { type IMenu } from "./type"; import { toast } from "sonner"; import { TABLER_ICON_OPTIONS } from "@/lib/tabler-icons"; -import RbacBadge from "@/components/ui/rbac-badge"; +import RbacBadge from "@/components/rbac/rbac-badge"; import { Plus, X } from "lucide-react"; import PermissionForm from "../../action-permissions/component/Form"; @@ -48,7 +48,8 @@ function getDescendantIds(targetId: number, menus: IMenu[]): Set { export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) { const [isLoading, setIsLoading] = useState(false); const [selectedIcon, setSelectedIcon] = useState(''); - const [showPermissionForm, setShowPermissionForm] = useState(false) + const [isAdminMenu, setIsAdminMenu] = useState(false); + const [showPermissionForm, setShowPermissionForm] = useState(false); const [form] = Form.useForm(); const router = useRouter(); const axios = useAxiosAuth(); @@ -89,24 +90,27 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) return { label, value: item.id!, - isAdmin: item.is_admin_menu, + isAdmin: Boolean(item.is_admin_menu), }; }); }, [menuList, isUpdate, data]); useEffect(() => { if (data) { + const adminStatus = Boolean(data.is_admin_menu); + setIsAdminMenu(adminStatus); form.setFieldsValue({ ...data, menu_parent_id: data.menu_parent_id ?? null, - is_admin_menu: data.is_admin_menu ?? false, + is_menu_admin: adminStatus, action: data.action ?? [], }); setSelectedIcon(data.icon || ''); } else { form.resetFields(); + setIsAdminMenu(false); form.setFieldsValue({ - is_admin_menu: false, + is_menu_admin: false, menu_parent_id: null, action: [], }); @@ -120,7 +124,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) path_url: values.path_url?.trim(), description: values.description?.trim() || '', icon: values.icon?.trim() || '', - is_admin_menu: Boolean(values.is_admin_menu), + is_admin_menu: Boolean(isAdminMenu), menu_parent_id: values.menu_parent_id ? Number(values.menu_parent_id) : null, action: Array.isArray(values.action) ? values.action : [], }; @@ -141,7 +145,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) return; } - toast.success('Menu successfully created.'); + toast.success('Menu created successfully.'); router.refresh(); if (onCancel) onCancel(); } catch (error: any) { @@ -164,7 +168,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) return; } - toast.success('Menu successfully updated.'); + toast.success('Menu updated successfully.'); router.refresh(); if (onCancel) onCancel(); } catch (error: any) { @@ -180,10 +184,10 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
- {isUpdate ? 'Edit Menu' : 'Create New Menu'} + {isUpdate ? 'Edit Menu' : 'Create Menu'} - Configure menu routing, hierarchy, tabler icon, and assigned permissions. + Configure menu routing, hierarchy, icon, and assigned permissions. @@ -198,20 +202,24 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) - - (option?.label ?? '').toLowerCase().includes(input.toLowerCase()) }} + getPopupContainer={(triggerNode: any) => triggerNode.parentNode} options={[ - { label: '— Root Menu (None) —', value: null as any }, + { label: '(None) - Root Menu', value: null as any }, ...validParentOptions.map(p => ({ - label: `${p.label} ${p.isAdmin ? ' (Admin)' : ''}`, + label: `${p.label} ${p.isAdmin ? '(Admin)' : ''}`, value: p.value, })), ]} @@ -231,8 +239,8 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) } > - triggerNode.parentNode} onChange={(val) => setSelectedIcon(val || '')} options={TABLER_ICON_OPTIONS.map(opt => ({ label: ( @@ -247,39 +255,56 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) /> -
+ {/* Admin Menu Switch with HIS Primary Color */} +
- - Admin Panel Menu + + Admin Menu - When enabled, this menu is treated as part of the Admin Panel and governed by Allow Admin Panel permission. + When enabled, this menu belongs to the Admin Panel and requires admin panel privileges.
- - + + { + setIsAdminMenu(checked); + form.setFieldValue('is_menu_admin', checked); + }} + style={{ + backgroundColor: isAdminMenu ? '#EA512C' : undefined, + }} + className="[&.ant-switch-checked]:bg-[#EA512C]! [&.ant-switch-checked:hover]:bg-[#EA512C]/90!" + />
+ {/* Action / Permissions Multi-select Container */}
- + } - placeholder="Cari menu atau permission..." + placeholder="Search menu or permission..." value={searchQuery} onChange={(e) => setSearchQuery(e.target.value)} allowClear className="h-9" />
-
- Gunakan tombol - Semua - atau centang permission per menu +
+ Tip: Click + + Select All + + to quickly grant all permissions for that menu
@@ -272,19 +179,19 @@ export const MenuPermissionTree: FC = ({ Non-Admin Menus (General Application)
- - {menus.filter(m => !m.is_admin_menu).length} menu + + {menus.filter(m => !(m.is_admin_menu)).length} menus -
- {nonAdminTree.length > 0 ? ( +
+ {nonAdminTree.length > 0 ? nonAdminTree.map(node => renderNode(node)) - ) : ( + :
- Belum ada menu Non-Admin yang terdaftar. + No non-admin menus available.
- )} + }
@@ -298,19 +205,19 @@ export const MenuPermissionTree: FC = ({ Admin Menus (Admin Panel) - - {menus.filter(m => Boolean(m.is_admin_menu)).length} menu + + {menus.filter(m => Boolean(m.is_admin_menu)).length} menus -
- {adminTree.length > 0 ? ( +
+ {adminTree.length > 0 ? adminTree.map(node => renderNode(node)) - ) : ( + :
- Belum ada menu Admin Panel yang terdaftar. + No admin panel menus available.
- )} + }
)} @@ -319,4 +226,3 @@ export const MenuPermissionTree: FC = ({ }; export default MenuPermissionTree; - diff --git a/app/admin/rbac/user-role/component/RoleForm.tsx b/app/admin/rbac/user-role/component/RoleForm.tsx index eb2a631..8720375 100644 --- a/app/admin/rbac/user-role/component/RoleForm.tsx +++ b/app/admin/rbac/user-role/component/RoleForm.tsx @@ -75,11 +75,12 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { } }); } else if (Array.isArray(initialData.privilege) && initialData.privilege.length > 0) { - // Support legacy privilege format initialData.privilege.forEach((item: any) => { const mId = item.menu_id || item.id; if (mId && Array.isArray(item.action)) { - initialSelection[mId] = item.action.map((a: any) => (typeof a === 'string' ? a : a.name || a.code || String(a))); + initialSelection[mId] = item.action.map((a: any) => + typeof a === 'string' ? a : a.name || a.code || String(a) + ); } }); } @@ -105,7 +106,8 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { setSelectedPermissions((prev) => { const next = { ...prev }; menus.forEach((m) => { - if (m.is_admin_menu && m.id !== undefined && next[m.id]) { + const isAdmin = Boolean(m.is_admin_menu); + if (isAdmin && m.id !== undefined && next[m.id]) { delete next[m.id]; } }); @@ -182,7 +184,8 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { if (!menu || !actions || actions.length === 0) return; // Rule: If allow_admin_panel is false, exclude Admin menus - if (menu.is_admin_menu && !allowAdminPanel) { + const isAdmin = Boolean(menu.is_admin_menu); + if (isAdmin && !allowAdminPanel) { return; } @@ -197,19 +200,18 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { menu_id: menu.id!, menu_name: menu.name, menu_path: menu.path_url || '#', - is_admin_menu: Boolean(menu.is_admin_menu), + is_admin_menu: isAdmin, action: safeActions, }); } }); const payload: Record = { + code: values.name?.trim().replace(/\s/g, '_').toUpperCase(), name: values.name?.trim(), description: values.description?.trim() || '', allow_admin_panel: Boolean(allowAdminPanel), - allow_admin: Boolean(allowAdminPanel), // For backward compatibility with legacy endpoints role_detail: roleDetail, - privilege: roleDetail, // For backward compatibility with legacy endpoints }; if (!isUpdate) { @@ -223,7 +225,7 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { return; } - toast.success('Role successfully created.'); + toast.success('Role created successfully.'); router.push('/admin/rbac/user-role'); router.refresh(); } else { @@ -237,7 +239,7 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { return; } - toast.success('Role successfully updated.'); + toast.success('Role updated successfully.'); router.push('/admin/rbac/user-role'); router.refresh(); } @@ -262,11 +264,11 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => {
- {isUpdate ? 'Edit User Role' : 'Create New User Role'} + {isUpdate ? 'Edit Role' : 'Create Role'} {isUpdate - ? `Configure role permissions for role ID ${roleId}` + ? `Update role permissions and configuration for role ID ${roleId}` : 'Define role details and assign hierarchical menu access'}
@@ -275,7 +277,7 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => {
{/* Form Body */} - + {/* Section A: General Information */} - Informasi Umum (General Information) + General Information - Masukkan nama peran, deskripsi, dan hak akses admin panel + Enter role name, description, and admin panel privileges -
+
- + -
-
+
+
Allow Admin Panel - Mengizinkan role ini mengakses menu administrasi dan admin panel + Grants this role access to administration and admin panel menus
- +
- @@ -347,14 +354,14 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => {
- Detil Hak Akses & Access Permissions + Menu Permissions & Access Rights - Atur izin akses untuk setiap menu yang tersedia dalam aplikasi + Configure access permissions for each menu available in the application
- {Object.keys(selectedPermissions).length} menu dikonfigurasi + {Object.keys(selectedPermissions).length} menus configured
@@ -362,7 +369,7 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { {menuLoading ? (
- Memuat struktur menu dari server... + Loading menu structure from server...
) : ( = ({ isUpdate, roleId, initialData }) => { {/* Bottom Action Bar */}
-
@@ -402,14 +409,14 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { - Konfirmasi Simpan Role? + Save Role Configuration? - Konfigurasi hak akses role ini akan disimpan dan langsung berlaku bagi pengguna yang memiliki role ini. + These permission settings will be saved and immediately applied to users assigned to this role. setShowConfirm(false)}> - Batal + Cancel = ({ isUpdate, roleId, initialData }) => { }} > {isLoading && } - Lanjutkan + Save Changes @@ -431,4 +438,3 @@ export const RoleForm: FC = ({ isUpdate, roleId, initialData }) => { }; export default RoleForm; - diff --git a/app/admin/rbac/user-role/component/index.tsx b/app/admin/rbac/user-role/component/index.tsx index aa0c971..fdb9629 100644 --- a/app/admin/rbac/user-role/component/index.tsx +++ b/app/admin/rbac/user-role/component/index.tsx @@ -24,6 +24,7 @@ const ComponentRolePage: FC = ({ data }) => { const [searchText, setSearchText] = useState(''); const axios = useAxiosAuth(); + const router = useRouter(); useEffect(() => { if (data && Array.isArray(data)) { @@ -56,7 +57,7 @@ const ComponentRolePage: FC = ({ data }) => { const columns: ColumnsType = [ { - title: 'Num', + title: 'No', dataIndex: 'key', width: 70, align: 'center', @@ -118,8 +119,8 @@ const ComponentRolePage: FC = ({ data }) => { const count = Array.isArray(details) ? details.length : Array.isArray(record.privilege) - ? record.privilege.length - : 0; + ? record.privilege.length + : 0; return ( {count} menus @@ -137,7 +138,7 @@ const ComponentRolePage: FC = ({ data }) => { ), }, { - title: 'Action', + title: 'Actions', key: 'action', width: 80, align: 'center', @@ -147,13 +148,13 @@ const ComponentRolePage: FC = ({ data }) => { - View Detail + View Details @@ -170,7 +171,7 @@ const ComponentRolePage: FC = ({ data }) => { handleDelete(record.id!)} onOkSuccess={() => { }} /> @@ -200,7 +201,7 @@ const ComponentRolePage: FC = ({ data }) => {
@@ -212,7 +213,7 @@ const ComponentRolePage: FC = ({ data }) => { className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold" > - Create New Role + Create Role
@@ -228,7 +229,7 @@ const ComponentRolePage: FC = ({ data }) => {

No roles found

- {searchText ? 'Try adjusting your search query.' : 'Click "Create New Role" to define user access roles.'} + {searchText ? 'Try adjusting your search query.' : 'Click "Create Role" to define a new user role.'}

), @@ -239,4 +240,3 @@ const ComponentRolePage: FC = ({ data }) => { }; export default ComponentRolePage; - diff --git a/app/admin/rbac/user-role/create/page.tsx b/app/admin/rbac/user-role/create/page.tsx index d9e6a21..1f285f9 100644 --- a/app/admin/rbac/user-role/create/page.tsx +++ b/app/admin/rbac/user-role/create/page.tsx @@ -2,11 +2,10 @@ import { type Metadata } from 'next'; import RoleForm from '../component/RoleForm'; export const metadata: Metadata = { - title: "Create User Role | Admin", + title: "Create Role | Admin", description: "Create a new user role with custom menu permissions", }; export default function CreateRolePage() { return ; } - diff --git a/app/admin/rbac/user-role/edit/[id]/page.tsx b/app/admin/rbac/user-role/edit/[id]/page.tsx index 805dd0d..f47e80c 100644 --- a/app/admin/rbac/user-role/edit/[id]/page.tsx +++ b/app/admin/rbac/user-role/edit/[id]/page.tsx @@ -6,7 +6,7 @@ import { type IRole } from '../../component/type'; export const dynamic = 'force-dynamic'; export const metadata: Metadata = { - title: "Edit User Role | Admin", + title: "Edit Role | Admin", description: "Update role permissions and configuration", }; @@ -22,7 +22,6 @@ async function getRoleData(id: string): Promise { return res; } } catch { - // Fallback: search in role list try { const list = await fetchData('/role', 'no-cache'); const roles = Array.isArray(list) ? list : (list?.role || list?.roles || []); diff --git a/app/admin/rbac/user-role/page.tsx b/app/admin/rbac/user-role/page.tsx index 3ab2094..77eb3d2 100644 --- a/app/admin/rbac/user-role/page.tsx +++ b/app/admin/rbac/user-role/page.tsx @@ -9,7 +9,7 @@ const ComponentPage = lazy(() => import('./component')); export const dynamic = 'force-dynamic'; export const metadata: Metadata = { - title: "User Role Management | Admin", + title: "Role Management | Admin", description: "Manage system user roles, admin panel access, and menu permissions", }; @@ -34,9 +34,9 @@ export default async function UserRolePage() {
- User Role + Role Management - List of registered user roles and permission sets + List of registered user roles and permission configurations
diff --git a/app/globals.css b/app/globals.css index ba99181..869ba1c 100644 --- a/app/globals.css +++ b/app/globals.css @@ -183,16 +183,26 @@ /* END SCROLLBAR */ } -.ant-select { - /* display: flex; */ - /* justify-content: center; */ - /* align-items: center; */ - /* padding: 19.35px 12px !important; */ +.ant-select:not(.ant-select-multiple) { font-size: 0.875rem !important/* 14px */; line-height: 1.25rem !important/* 20px */; height: 40px !important; } +.ant-select-multiple { + font-size: 0.875rem !important; + line-height: 1.25rem !important; + min-height: 40px !important; + height: auto !important; +} + +.ant-select-multiple .ant-select-selector { + min-height: 40px !important; + height: auto !important; + padding-top: 4px !important; + padding-bottom: 4px !important; +} + /* .ant-select-selection-search{ display: flex; justify-content: center; diff --git a/components/rbac/rbac-badge.tsx b/components/rbac/rbac-badge.tsx new file mode 100644 index 0000000..b797663 --- /dev/null +++ b/components/rbac/rbac-badge.tsx @@ -0,0 +1,2 @@ +export * from '@/components/ui/rbac-badge'; +export { default } from '@/components/ui/rbac-badge'; diff --git a/components/rbac/role-permission-row.tsx b/components/rbac/role-permission-row.tsx new file mode 100644 index 0000000..71904e0 --- /dev/null +++ b/components/rbac/role-permission-row.tsx @@ -0,0 +1,223 @@ +'use client'; + +import React, { FC } from 'react'; +import { Checkbox } from 'antd'; +import { ChevronDown, ChevronRight } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import RbacBadge from '@/components/rbac/rbac-badge'; +import { cn } from '@/lib/utils'; + +export interface IRolePermissionNode { + id: number; + name: string; + path_url?: string; + icon?: string; + is_menu_admin?: boolean; + level: number; + hasChildren?: boolean; + isCollapsed?: boolean; + action?: string[]; +} + +export interface IRolePermissionRowProps { + node: IRolePermissionNode; + mode?: 'interactive' | 'readonly'; + selectedActions?: string[]; + index?: number; + onToggleCollapse?: () => void; + onPermissionToggle?: (actionName: string, checked: boolean) => void; + onSelectAll?: () => void; + onClearAll?: () => void; +} + +export const RolePermissionRow: FC = ({ + node, + mode = 'interactive', + selectedActions = [], + index, + onToggleCollapse, + onPermissionToggle, + onSelectAll, + onClearAll, +}) => { + const isInteractive = mode === 'interactive'; + const assignedActions = node.action || []; + const currentSelected = selectedActions; + + const isAllSelected = assignedActions.length > 0 && assignedActions.every(a => currentSelected.includes(a)); + const hasAnySelected = currentSelected.length > 0; + const isIndeterminate = hasAnySelected && !isAllSelected; + + const indentPx = node.level * 22; + const actionsIndentPx = indentPx + (isInteractive ? 40 : 28); + + return ( +
+ {/* Top row: Hierarchy, Menu Identifier & Row Actions */} +
+
+ {/* Expand / Collapse Control */} + {node.hasChildren ? ( + + ) : ( + + )} + + {/* Submenu Level Marker */} + {node.level > 0 && ( + + ↳ + + )} + + {/* Checkbox (interactive) or Row Index (readonly) */} + {isInteractive ? ( + assignedActions.length > 0 && ( + { + if (e.target.checked) { + onSelectAll?.(); + } else { + onClearAll?.(); + } + }} + className="shrink-0" + /> + ) + ) : ( + index !== undefined && ( + + {index + 1} + + ) + )} + + {/* Icon, Title, Path & Admin Badge */} +
+ {node.icon ? ( + + + + ) : ( + + # + + )} + + + {node.name} + + + {node.path_url && ( + + {node.path_url} + + )} + + {node.is_menu_admin && ( + + Admin + + )} +
+
+ + {/* Right: Summary Count & Row Select/Clear Action */} +
+ {isInteractive ? ( + assignedActions.length > 0 && ( + <> + + {currentSelected.length} / {assignedActions.length} selected + + + + ) + ) : ( + + {currentSelected.length} permissions + + )} +
+
+ + {/* Bottom: Dedicated indented permission badges container */} +
+ {assignedActions.length > 0 ? ( +
+ {assignedActions.map(action => { + const isChecked = currentSelected.includes(action); + + if (isInteractive) { + return ( + + ); + } + + // Readonly view + return ( + + ); + })} +
+ ) : ( + + No permissions assigned + + )} +
+
+ ); +}; + +export default RolePermissionRow; diff --git a/lib/data-sidebar.tsx b/lib/data-sidebar.tsx index aa5b42e..6358d3b 100644 --- a/lib/data-sidebar.tsx +++ b/lib/data-sidebar.tsx @@ -36,7 +36,7 @@ const SIDEBAR_MENU = [ submenuItems: [ { title: "Access Permissions", - path: '/rbac/action-pemission' + path: '/rbac/action-permissions' }, { title: "Menu Management", diff --git a/lib/tabler-icons.ts b/lib/tabler-icons.ts index 435ff0a..4037a74 100644 --- a/lib/tabler-icons.ts +++ b/lib/tabler-icons.ts @@ -59,11 +59,13 @@ export const TABLER_ICON_OPTIONS: ITablerIconOption[] = [ { label: 'File Text', value: 'ti ti-file-text', category: 'Reports' }, { label: 'File Spreadsheet', value: 'ti ti-file-spreadsheet', category: 'Reports' }, { label: 'File Description', value: 'ti ti-file-description', category: 'Reports' }, + { label: 'Notes', value: 'ti ti-notes', category: 'Reports' }, // Communication & Badges { label: 'Id Badge', value: 'ti ti-id-badge', category: 'Security' }, { label: 'Credit Card', value: 'ti ti-credit-card', category: 'Security' }, { label: 'Scan', value: 'ti ti-scan', category: 'Security' }, + { label: 'Face id', value: 'ti ti-face-id', category: 'Security' }, { label: 'Fingerprint', value: 'ti ti-fingerprint', category: 'Security' }, { label: 'Bell', value: 'ti ti-bell', category: 'General' }, ]; diff --git a/types/rbac.ts b/types/rbac.ts index cfb09fa..72df0bb 100644 --- a/types/rbac.ts +++ b/types/rbac.ts @@ -18,7 +18,7 @@ export interface IMenu { path_url: string; description?: string; icon?: string; - is_admin_menu?: boolean; + is_admin_menu: boolean; menu_parent_id?: number | null; action?: string[]; status?: {