mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 11:56:28 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user