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.
This commit is contained in:
Ichsan Kurniawan
2026-11-05 20:37:39 +07:00
parent 751b28fab2
commit 6ffe7746c8
20 changed files with 542 additions and 356 deletions
+61 -75
View File
@@ -5,23 +5,41 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
import fetchData from '@/lib/fetchData';
import { Button } from '@/components/ui/button';
import { type IRole, type IRoleDetail } from '../component/type';
import RbacBadge from '@/components/ui/rbac-badge';
import { PencilLine } from 'lucide-react';
import RolePermissionRow from '@/components/rbac/role-permission-row';
export const dynamic = 'force-dynamic';
export const metadata: Metadata = {
title: "Detail Hak Akses & Kewenangan | Admin",
description: "Detail of user role and authorized menu actions",
title: "Role Permission Details | Admin",
description: "Detailed overview of role permissions and authorized menu actions",
};
type Props = {
params: Promise<{ id: string }>;
};
async function getRoleData(id: string): Promise<IRole | undefined> {
try {
const res = await fetchData(`/role/${id}`, 'no-cache');
if (res) {
if (res.role) return res.role;
return res;
}
} catch {
try {
const list = await fetchData('/role', 'no-cache');
const roles = Array.isArray(list) ? list : (list?.role || list?.roles || []);
return roles.find((r: any) => String(r.id) === String(id));
} catch {
return undefined;
}
}
return undefined;
}
const UserRoleDetailPage: FC<Props> = async ({ params }) => {
const { id } = await params;
const data: IRole | undefined = await fetchData(`/role/${id}`, 'no-cache');;
const data: IRole | undefined = await getRoleData(id);
const isAdminAllowed = Boolean(data?.allow_admin_panel ?? data?.allow_admin);
const roleDetails: IRoleDetail[] = Array.isArray(data?.role_detail)
@@ -31,7 +49,7 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
menu_id: p.menu_id || p.id,
menu_name: p.menu_name || p.name,
menu_path: p.menu_path || p.path || '#',
is_admin_menu: Boolean(p.is_admin_menu),
is_admin_menu: Boolean(p.is_admin_menu ?? p.is_menu_admin),
action: Array.isArray(p.action) ? p.action : [],
}))
: [];
@@ -48,45 +66,45 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
</Button>
</Link>
<div>
<CardTitle className="text-xl">Access and Permissions</CardTitle>
<CardTitle className="text-xl">Role Permission Details</CardTitle>
<CardDescription className="mt-1">
Informasi detail konfigurasi hak akses dan izin menu untuk peran ini
Detailed overview of role permissions and authorized menu actions
</CardDescription>
</div>
</div>
<Link href={`/admin/rbac/user-role/edit/${id}`}>
<Button className="bg-his hover:bg-his/90 text-white font-medium">
<PencilLine className='size-3.5' /> Edit Role
<i className="ti ti-edit mr-2 text-base" /> Edit Role
</Button>
</Link>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 p-4 rounded-lg bg-zinc-50/60 dark:bg-zinc-900/40 border border-zinc-200 dark:border-zinc-800">
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Kode Peran
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
Role Code
</span>
<span className="font-mono font-bold text-sm text-zinc-900 dark:text-zinc-100">
{data?.code || `ROLE-${id}`}
</span>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Nama Hak Akses
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
Role Name
</span>
<span className="font-bold text-sm text-zinc-900 dark:text-zinc-100">
<span className="font-bold text-sm text-zinc-900 dark:text-zinc-100 uppercase">
{data?.name || '-'}
</span>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Akses Admin Panel
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
Admin Panel Access
</span>
<div>
{isAdminAllowed ? (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-emerald-500/10 text-emerald-600 border border-emerald-500/20 dark:bg-emerald-500/20 dark:text-emerald-300">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
Admin Panel
Web CMS & Admin Panel
</span>
) : (
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-zinc-500/10 text-zinc-500 border border-zinc-500/20 dark:bg-zinc-500/20 dark:text-zinc-400">
@@ -97,22 +115,22 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
</div>
</div>
<div className="flex flex-col space-y-1">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
Status
</span>
<div>
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-green-500/10 text-green-600 border border-green-500/20">
<span className="w-1.5 h-1.5 rounded-full bg-green-500" />
{data?.status?.name || 'Aktif'}
{data?.status?.name || 'Active'}
</span>
</div>
</div>
<div className="flex flex-col space-y-1 md:col-span-2">
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
Deskripsi
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
Description
</span>
<span className="text-sm text-zinc-700 dark:text-zinc-300">
{data?.description || 'Tidak ada deskripsi.'}
{data?.description || 'No description provided.'}
</span>
</div>
</div>
@@ -126,70 +144,38 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
<div className="flex items-center gap-2">
<i className="ti ti-checklist text-lg text-his" />
<CardTitle className="text-base font-semibold">
Daftar Izin Menu & Aksi ({roleDetails.length} Menu Diizinkan)
Authorized Menu Permissions ({roleDetails.length} Menus Allowed)
</CardTitle>
</div>
</div>
</CardHeader>
<CardContent className="p-0">
{roleDetails.length > 0 ? (
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b border-zinc-200 dark:border-zinc-800 bg-zinc-50 dark:bg-zinc-900 text-left text-xs font-semibold text-muted-foreground tracking-wider">
<th className="py-3 px-4 w-14 text-center">No</th>
<th className="py-3 px-4">Menu Aplikasi (Hierarki)</th>
<th className="py-3 px-4">Aksi yang Diizinkan</th>
</tr>
</thead>
<tbody className="divide-y divide-zinc-200 dark:divide-zinc-800">
{roleDetails.map((detail, idx) => (
<tr key={idx} className="hover:bg-zinc-50/50 dark:hover:bg-zinc-900/30 transition-colors">
<td className="py-3.5 px-4 text-center text-xs text-muted-foreground font-medium">
{idx + 1}
</td>
<td className="py-3.5 px-4">
<div className="flex items-center gap-2">
<div>
<span className="font-semibold text-zinc-900 dark:text-zinc-100 text-xs sm:text-sm">
{detail.menu_name}
</span>
<span className="text-xs font-mono text-muted-foreground block">
{detail.menu_path}
</span>
</div>
{detail.is_admin_menu && (
<span className="text-[10px] font-semibold px-1.5 py-0.5 rounded bg-rose-500/10 text-rose-600 dark:text-rose-400">
Admin
</span>
)}
</div>
</td>
<td className="py-3.5 px-4">
<div className="flex flex-wrap gap-1.5">
{detail.action && detail.action.length > 0 ? (
detail.action.map(action => (
<RbacBadge key={action} permission={action} size="sm" />
))
) : (
<span className="text-xs text-muted-foreground italic">
Akses Menu Saja (Tanpa Aksi Spesifik)
</span>
)}
</div>
</td>
</tr>
))}
</tbody>
</table>
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
{roleDetails.map((detail, idx) => (
<RolePermissionRow
key={detail.menu_id || idx}
node={{
id: detail.menu_id,
name: detail.menu_name,
path_url: detail.menu_path,
is_menu_admin: detail.is_admin_menu,
level: 0,
action: detail.action,
}}
mode="readonly"
index={idx}
selectedActions={detail.action || []}
/>
))}
</div>
) : (
<div className="py-12 text-center text-muted-foreground">
<i className="ti ti-lock-open text-3xl mb-2 text-zinc-400 block" />
<p className="text-sm font-medium">Belum ada menu atau izin yang dikonfigurasi untuk role ini.</p>
<p className="text-sm font-medium">No menus or permissions have been configured for this role.</p>
<Link href={`/admin/rbac/user-role/edit/${id}`} className="mt-3 inline-block">
<Button size="sm" variant="outline">
Konfigurasi Hak Akses Sekarang
Configure Permissions Now
</Button>
</Link>
</div>
@@ -42,7 +42,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
const showSuccess = () => {
router.refresh();
toast.success(contentSuccess || 'Role successfully removed.');
toast.success(contentSuccess || 'Role deleted successfully.');
if (onOkSuccess) onOkSuccess();
};
@@ -55,7 +55,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
<AlertDialogHeader>
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
<AlertDialogDescription>
{description || 'This action cannot be undone. This will permanently remove this role from our system.'}
{description || 'This action cannot be undone. This will permanently remove this role from the system.'}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -64,7 +64,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
{isLoading && (
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
)}
{okText || 'Continue'}
{okText || 'Delete'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
@@ -72,4 +72,3 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
};
export default ConfirmAsync;
@@ -1,11 +1,10 @@
'use client';
import React, { FC, useState, useMemo } from 'react';
import { Checkbox, Input } from 'antd';
import { ChevronDown, ChevronRight, Search, Shield, ShieldCheck } from 'lucide-react';
import { Input } from 'antd';
import { Search, Shield, ShieldCheck } from 'lucide-react';
import { type IMenu } from './type';
import RbacBadge from '@/components/ui/rbac-badge';
import { Button } from '@/components/ui/button';
import RolePermissionRow from '@/components/rbac/role-permission-row';
export interface IMenuPermissionTreeProps {
menus: IMenu[];
@@ -71,7 +70,7 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
// Separate Non-Admin and Admin menus
const { nonAdminTree, adminTree } = useMemo(() => {
const nonAdminList = menus.filter(m => !m.is_admin_menu);
const nonAdminList = menus.filter(m => !(m.is_admin_menu));
const adminList = menus.filter(m => Boolean(m.is_admin_menu));
return {
@@ -106,7 +105,7 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
return matches;
}, [menus, searchQuery]);
// Renders a single menu row and recursively its children
// Renders a single menu row and recursively its children using unified RolePermissionRow
const renderNode = (node: TreeNode) => {
if (node.id === undefined) return null;
if (searchMatchIds && !searchMatchIds.has(node.id)) {
@@ -114,127 +113,33 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
}
const isCollapsed = collapsedIds.has(node.id);
const hasChildren = node.children && node.children.length > 0;
const hasChildren = Boolean(node.children && node.children.length > 0);
const assignedActions = node.action || [];
const currentSelectedActions = selectedPermissions[node.id] || [];
const isAllSelected = assignedActions.length > 0 && assignedActions.every(a => currentSelectedActions.includes(a));
const hasAnySelected = currentSelectedActions.length > 0;
const isIndeterminate = hasAnySelected && !isAllSelected;
return (
<React.Fragment key={node.id}>
<div
className={`flex flex-col sm:flex-row sm:items-center justify-between py-3 px-3 sm:px-4 border-b border-zinc-200 dark:border-zinc-800 transition-colors ${node.level === 0
? 'bg-zinc-50/70 dark:bg-zinc-900/60 font-semibold'
: 'bg-white dark:bg-zinc-950/40 hover:bg-zinc-50/50 dark:hover:bg-zinc-900/30'
}`}
>
{/* Left: Menu Name, Hierarchy Indent & Parent indicator */}
<div
className="flex items-center gap-2 sm:gap-3 flex-1 min-w-0 mb-2 sm:mb-0"
style={{ paddingLeft: `${node.level * 24}px` }}
>
{hasChildren ? (
<button
type="button"
onClick={() => toggleCollapse(node.id!)}
className="w-5 h-5 flex items-center justify-center text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 rounded"
>
{isCollapsed ? <ChevronRight size={15} /> : <ChevronDown size={15} />}
</button>
) : (
<span className="w-5" />
)}
{node.level > 0 && (
<span className="text-zinc-400 dark:text-zinc-600 font-mono text-xs select-none">
↳
</span>
)}
<div className="flex items-center gap-2 min-w-0">
{assignedActions.length > 0 && (
<Checkbox
checked={isAllSelected}
indeterminate={isIndeterminate}
onChange={(e) => {
if (e.target.checked) {
onMenuSelectAll(node.id!, assignedActions);
} else {
onMenuClearAll(node.id!);
}
}}
/>
)}
<div>
<div className="flex items-center gap-2">
{node.icon && <i className={`${node.icon} text-sm text-zinc-500`} />}
<span className="text-xs sm:text-sm font-medium text-zinc-900 dark:text-zinc-100 truncate">
{node.name}
</span>
{node.is_admin_menu && (
<span className="text-[10px] uppercase font-semibold px-1.5 py-0.2 rounded bg-indigo-500/10 text-indigo-600 dark:text-indigo-400">
Admin
</span>
)}
</div>
<span className="text-[11px] font-mono text-zinc-400 dark:text-zinc-500 block truncate">
{node.path_url || '#'}
</span>
</div>
</div>
</div>
{/* Right: Available Actions Checkboxes & Row Select All button */}
<div className="flex items-center flex-wrap gap-2 sm:gap-3 sm:ml-4">
{assignedActions.length > 0 ? (
<>
<div className="flex flex-wrap items-center gap-2">
{assignedActions.map(action => {
const isChecked = currentSelectedActions.includes(action);
return (
<label
key={action}
className={`inline-flex items-center gap-1.5 px-2 py-1 rounded border text-xs cursor-pointer select-none transition-all ${isChecked
? 'bg-zinc-100 dark:bg-zinc-800 border-zinc-300 dark:border-zinc-700 shadow-xs'
: 'bg-transparent border-transparent hover:border-zinc-200 dark:hover:border-zinc-800 opacity-65 hover:opacity-100'
}`}
>
<Checkbox
checked={isChecked}
onChange={(e) =>
onPermissionToggle(node.id!, action, e.target.checked)
}
/>
<RbacBadge permission={action} size="sm" />
</label>
);
})}
</div>
<Button
type="button"
variant="outline"
size="sm"
className="h-7 text-xs px-2.5 ml-2"
onClick={() => {
if (isAllSelected) {
onMenuClearAll(node.id!);
} else {
onMenuSelectAll(node.id!, assignedActions);
}
}}
>
{isAllSelected ? 'Batal' : 'Semua'}
</Button>
</>
) : (
<span className="text-xs text-zinc-400 italic px-2">
Tidak ada aksi terkonfigurasi
</span>
)}
</div>
</div>
<RolePermissionRow
node={{
id: node.id,
name: node.name,
path_url: node.path_url,
icon: node.icon,
is_menu_admin: Boolean(node.is_admin_menu),
level: node.level,
hasChildren,
isCollapsed,
action: assignedActions,
}}
mode="interactive"
selectedActions={currentSelectedActions}
onToggleCollapse={() => toggleCollapse(node.id!)}
onPermissionToggle={(actionName, checked) =>
onPermissionToggle(node.id!, actionName, checked)
}
onSelectAll={() => onMenuSelectAll(node.id!, assignedActions)}
onClearAll={() => onMenuClearAll(node.id!)}
/>
{/* Render children recursively if not collapsed */}
{hasChildren && !isCollapsed && node.children!.map(child => renderNode(child))}
@@ -244,22 +149,24 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
return (
<div className="flex flex-col space-y-6">
{/* Search Bar */}
<div className="flex items-center justify-between gap-4">
<div className="w-full sm:w-72">
{/* Search Bar & Instruction */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div className="w-full sm:w-64 md:w-72">
<Input
prefix={<Search size={14} className="text-muted-foreground mr-1" />}
placeholder="Cari menu atau permission..."
placeholder="Search menu or permission..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
allowClear
className="h-9"
/>
</div>
<div className="hidden sm:flex items-center gap-2 text-xs text-muted-foreground">
<span>Gunakan tombol</span>
<span className="px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-800 font-mono text-[11px] font-medium">Semua</span>
<span>atau centang permission per menu</span>
<div className="text-xs text-muted-foreground flex items-center gap-1.5">
<span>Tip: Click</span>
<span className="px-1.5 py-0.5 rounded bg-zinc-100 dark:bg-zinc-800 font-mono text-[11px] font-semibold text-zinc-700 dark:text-zinc-300">
Select All
</span>
<span>to quickly grant all permissions for that menu</span>
</div>
</div>
@@ -272,19 +179,19 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
Non-Admin Menus (General Application)
</h4>
</div>
<span className="text-xs text-muted-foreground font-medium">
{menus.filter(m => !m.is_admin_menu).length} menu
<span className="text-xs text-muted-foreground font-mono font-medium">
{menus.filter(m => !(m.is_admin_menu)).length} menus
</span>
</div>
<div className="divide-y divide-zinc-200 dark:divide-zinc-800">
{nonAdminTree.length > 0 ? (
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
{nonAdminTree.length > 0 ?
nonAdminTree.map(node => renderNode(node))
) : (
:
<div className="py-8 text-center text-xs text-muted-foreground">
Belum ada menu Non-Admin yang terdaftar.
No non-admin menus available.
</div>
)}
}
</div>
</div>
@@ -298,19 +205,19 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
Admin Menus (Admin Panel)
</h4>
</div>
<span className="text-xs text-muted-foreground font-medium">
{menus.filter(m => Boolean(m.is_admin_menu)).length} menu
<span className="text-xs text-muted-foreground font-mono font-medium">
{menus.filter(m => Boolean(m.is_admin_menu)).length} menus
</span>
</div>
<div className="divide-y divide-zinc-200 dark:divide-zinc-800">
{adminTree.length > 0 ? (
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
{adminTree.length > 0 ?
adminTree.map(node => renderNode(node))
) : (
:
<div className="py-8 text-center text-xs text-muted-foreground">
Belum ada menu Admin Panel yang terdaftar.
No admin panel menus available.
</div>
)}
}
</div>
</div>
)}
@@ -319,4 +226,3 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
};
export default MenuPermissionTree;
+42 -36
View File
@@ -75,11 +75,12 @@ export const RoleForm: FC<Props> = ({ 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<Props> = ({ 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<Props> = ({ 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<Props> = ({ 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<string, any> = {
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<Props> = ({ 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<Props> = ({ 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<Props> = ({ isUpdate, roleId, initialData }) => {
</Link>
<div>
<CardTitle className="text-xl">
{isUpdate ? 'Edit User Role' : 'Create New User Role'}
{isUpdate ? 'Edit Role' : 'Create Role'}
</CardTitle>
<CardDescription className="mt-1">
{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'}
</CardDescription>
</div>
@@ -275,7 +277,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
<div className="flex items-center gap-2 self-end sm:self-auto">
<Link href="/admin/rbac/user-role">
<Button variant="outline" size="sm" disabled={isLoading}>
Batal
Cancel
</Button>
</Link>
<Button
@@ -285,57 +287,62 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
disabled={isLoading || menuLoading}
>
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
Simpan Perubahan
Save Changes
</Button>
</div>
</CardHeader>
</Card>
{/* Form Body */}
<Form form={form} layout="vertical" scrollToFirstError>
<Form form={form} layout="vertical" scrollToFirstError size='small'>
{/* Section A: General Information */}
<Card className="mb-6">
<CardHeader className="pb-4">
<CardTitle className="text-base font-semibold">
Informasi Umum (General Information)
General Information
</CardTitle>
<CardDescription>
Masukkan nama peran, deskripsi, dan hak akses admin panel
Enter role name, description, and admin panel privileges
</CardDescription>
</CardHeader>
<CardContent>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 gap-y-0">
<Form.Item
name="name"
label="Role Name"
rules={[{ required: true, message: 'Role name is required!' }]}
>
<Input className="input font-medium" placeholder="e.g. Team Leader or SYSADMIN" />
<Input className="input font-medium" placeholder="e.g. Team Leader or Administrator" />
</Form.Item>
<div className="p-3.5 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-zinc-50/60 dark:bg-zinc-900/40 flex items-center justify-between">
<div>
<div className="p-3.5 rounded-lg -mt-5!">
<div className='mb-2'>
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 block">
Allow Admin Panel
</span>
<span className="text-xs text-muted-foreground block mt-0.5">
Mengizinkan role ini mengakses menu administrasi dan admin panel
Grants this role access to administration and admin panel menus
</span>
</div>
<Form.Item name="allow_admin_panel" valuePropName="checked" className="mb-0">
<Form.Item name="allow_admin_panel" valuePropName="checked">
<Switch
size='medium'
checked={allowAdminPanel}
onChange={handleAdminToggle}
style={{
backgroundColor: allowAdminPanel ? '#EA512C' : undefined,
}}
className="[&.ant-switch-checked]:bg-his! [&.ant-switch-checked:hover]:bg-his/90!"
/>
</Form.Item>
</div>
</div>
<Form.Item name="description" label="Description" className="mt-2 mb-0">
<Input.TextArea
<Input.TextArea size='large'
className="input"
rows={2}
placeholder="Deskripsi tugas dan tanggung jawab role ini..."
placeholder="Describe role responsibilities and permission scope..."
/>
</Form.Item>
</CardContent>
@@ -347,14 +354,14 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<div>
<CardTitle className="text-base font-semibold">
Detil Hak Akses & Access Permissions
Menu Permissions & Access Rights
</CardTitle>
<CardDescription className="mt-1">
Atur izin akses untuk setiap menu yang tersedia dalam aplikasi
Configure access permissions for each menu available in the application
</CardDescription>
</div>
<div className="text-xs text-muted-foreground bg-zinc-100 dark:bg-zinc-800 px-2.5 py-1 rounded self-start sm:self-auto font-mono">
{Object.keys(selectedPermissions).length} menu dikonfigurasi
{Object.keys(selectedPermissions).length} menus configured
</div>
</div>
</CardHeader>
@@ -362,7 +369,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
{menuLoading ? (
<div className="py-12 flex flex-col items-center justify-center text-muted-foreground">
<Icons.spinner className="h-6 w-6 animate-spin mb-3 text-his" />
<span className="text-sm">Memuat struktur menu dari server...</span>
<span className="text-sm">Loading menu structure from server...</span>
</div>
) : (
<MenuPermissionTree
@@ -380,8 +387,8 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
{/* Bottom Action Bar */}
<div className="mt-6 flex justify-end items-center gap-3">
<Link href="/admin/rbac/user-role">
<Button variant="outline" type="button" disabled={isLoading}>
Batal
<Button variant="outline" type="button" disabled={isLoading} className='text-zinc-800! dark:text-white'>
Cancel
</Button>
</Link>
<Button
@@ -391,7 +398,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
disabled={isLoading || menuLoading}
>
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
Simpan Perubahan
Save Changes
</Button>
</div>
</Form>
@@ -402,14 +409,14 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
<AlertDialog open={true}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Konfirmasi Simpan Role?</AlertDialogTitle>
<AlertDialogTitle>Save Role Configuration?</AlertDialogTitle>
<AlertDialogDescription>
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.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>
Batal
Cancel
</AlertDialogCancel>
<AlertDialogAction
disabled={isLoading}
@@ -420,7 +427,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
}}
>
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
Lanjutkan
Save Changes
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
@@ -431,4 +438,3 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
};
export default RoleForm;
+11 -11
View File
@@ -24,6 +24,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
const [searchText, setSearchText] = useState('');
const axios = useAxiosAuth();
const router = useRouter();
useEffect(() => {
if (data && Array.isArray(data)) {
@@ -56,7 +57,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
const columns: ColumnsType<IRole> = [
{
title: 'Num',
title: 'No',
dataIndex: 'key',
width: 70,
align: 'center',
@@ -118,8 +119,8 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
const count = Array.isArray(details)
? details.length
: Array.isArray(record.privilege)
? record.privilege.length
: 0;
? record.privilege.length
: 0;
return (
<span className="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-zinc-100 dark:bg-zinc-800 text-zinc-700 dark:text-zinc-300">
{count} menus
@@ -137,7 +138,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
),
},
{
title: 'Action',
title: 'Actions',
key: 'action',
width: 80,
align: 'center',
@@ -147,13 +148,13 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon" className="h-8 w-8">
<MoreHorizontalIcon className="h-4 w-4" />
<span className="sr-only">Role Action</span>
<span className="sr-only">Role Actions</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem asChild>
<Link href={`/admin/rbac/user-role/${record.id}`}>
View Detail
View Details
</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
@@ -170,7 +171,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
</DropdownMenu>
<ConfirmAsync
title="Delete Role?"
description={`Are you sure you want to delete role "${record.name}"? Users with this role may lose their access permissions.`}
description={`Are you sure you want to delete role "${record.name}"? Users assigned to this role will lose their permissions.`}
onConfirm={() => handleDelete(record.id!)}
onOkSuccess={() => { }}
/>
@@ -200,7 +201,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
<div className="flex flex-1 items-center space-x-2 w-full sm:w-auto">
<Input
placeholder="Search role name, code, description..."
className="h-8 w-full sm:w-64"
className="h-8 w-full sm:w-[280px]"
value={searchText}
onChange={handleSearch}
/>
@@ -212,7 +213,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
>
<PlusCircledIcon className="mr-2 h-4 w-4" />
Create New Role
Create Role
</Button>
</Link>
</div>
@@ -228,7 +229,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
<ShieldCheck className="h-8 w-8 mx-auto mb-2 text-zinc-400" />
<p className="text-sm font-medium">No roles found</p>
<p className="text-xs text-zinc-400 mt-1">
{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.'}
</p>
</div>
),
@@ -239,4 +240,3 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
};
export default ComponentRolePage;
+1 -2
View File
@@ -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 <RoleForm isUpdate={false} />;
}
+1 -2
View File
@@ -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<IRole | undefined> {
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 || []);
+3 -3
View File
@@ -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() {
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0">
<div>
<CardTitle>User Role</CardTitle>
<CardTitle>Role Management</CardTitle>
<CardDescription className="mt-1">
List of registered user roles and permission sets
List of registered user roles and permission configurations
</CardDescription>
</div>
</CardHeader>