mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +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:
@@ -3,6 +3,21 @@
|
||||
import { usePathname } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
|
||||
const SEGMENT_LABELS: Record<string, string> = {
|
||||
'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() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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<Props> = ({ data }) => {
|
||||
const [searchText, setSearchText] = useState('');
|
||||
|
||||
const axios = useAxiosAuth();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (data && Array.isArray(data)) {
|
||||
@@ -63,7 +65,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
|
||||
const columns: ColumnsType<IPermission> = [
|
||||
{
|
||||
title: 'Num',
|
||||
title: 'No',
|
||||
dataIndex: 'key',
|
||||
width: 70,
|
||||
align: 'center',
|
||||
@@ -91,7 +93,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
title: 'Actions',
|
||||
key: 'action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
@@ -101,7 +103,7 @@ const ComponentPermissionPage: 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">Action</span>
|
||||
<span className="sr-only">Actions</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
@@ -111,20 +113,20 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
setShowFormDialog(true);
|
||||
}}
|
||||
>
|
||||
Edit
|
||||
Edit Permission
|
||||
</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||
Delete
|
||||
Delete Permission
|
||||
</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
title="Delete Access Permission?"
|
||||
title="Delete Permission"
|
||||
description={`Are you sure you want to delete permission "${record.name}"? This may affect menus and roles using this permission.`}
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
onOkSuccess={() => { }}
|
||||
onOkSuccess={() => router.refresh()}
|
||||
/>
|
||||
</AlertDialog>
|
||||
),
|
||||
@@ -168,7 +170,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Permission
|
||||
Create Permission
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -183,7 +185,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
||||
<i className="ti ti-shield-lock text-3xl mb-2 text-zinc-400 block" />
|
||||
<p className="text-sm font-medium">No permissions found</p>
|
||||
<p className="text-xs text-zinc-400 mt-1">
|
||||
{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.'}
|
||||
</p>
|
||||
</div>
|
||||
),
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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<number> {
|
||||
export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [selectedIcon, setSelectedIcon] = useState<string>('');
|
||||
const [showPermissionForm, setShowPermissionForm] = useState(false)
|
||||
const [isAdminMenu, setIsAdminMenu] = useState<boolean>(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)
|
||||
<Form form={form} onFinish={handleSubmit} layout="vertical">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="dark:text-white">
|
||||
{isUpdate ? 'Edit Menu' : 'Create New Menu'}
|
||||
{isUpdate ? 'Edit Menu' : 'Create Menu'}
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure menu routing, hierarchy, tabler icon, and assigned permissions.
|
||||
Configure menu routing, hierarchy, icon, and assigned permissions.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -198,20 +202,24 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
||||
|
||||
<Form.Item
|
||||
name="path_url"
|
||||
label="Path URL"
|
||||
rules={[{ required: true, message: 'Path URL is required!' }]}
|
||||
label="Menu Path"
|
||||
rules={[{ required: true, message: 'Menu path is required!' }]}
|
||||
>
|
||||
<Input className="input font-mono" placeholder="e.g. /administration/user" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="menu_parent_id" label="Parent Menu" tooltip="Select parent menu or leave as Root menu (null)">
|
||||
<Select placeholder="Root Menu (No Parent)" allowClear
|
||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
<Form.Item
|
||||
name="menu_parent_id"
|
||||
label="Parent Menu"
|
||||
tooltip="Select parent menu or leave as Root menu (None)"
|
||||
>
|
||||
<Select placeholder="Root Menu (None)" allowClear
|
||||
showSearch={{ filterOption: (input, option) => (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)
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Select placeholder="Select Tabler Icon" allowClear
|
||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
<Select placeholder="Select Tabler Icon" allowClear showSearch
|
||||
getPopupContainer={(triggerNode: any) => 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)
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<div className="p-3 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-zinc-50/50 dark:bg-zinc-900/40 flex items-center justify-between">
|
||||
{/* Admin Menu Switch with HIS Primary Color */}
|
||||
<div className="p-3.5 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-zinc-50/50 dark:bg-zinc-900/40 flex items-center justify-between">
|
||||
<div>
|
||||
<span className="text-sm font-medium text-zinc-900 dark:text-zinc-100 block">
|
||||
Admin Panel Menu
|
||||
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 block">
|
||||
Admin Menu
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground block mt-0.5">
|
||||
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.
|
||||
</span>
|
||||
</div>
|
||||
<Form.Item name="is_admin_menu" valuePropName="checked" className="mb-0">
|
||||
<Switch />
|
||||
<Form.Item name="is_menu_admin" valuePropName="checked" className="mb-0">
|
||||
<Switch
|
||||
checked={isAdminMenu}
|
||||
onChange={(checked) => {
|
||||
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!"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
{/* Action / Permissions Multi-select Container */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Form.Item name="action" label="Action / Permissions" tooltip="Select which action permissions are available on this menu" className="w-full">
|
||||
<Form.Item name="action" label="Action Permissions"
|
||||
tooltip="Select action permissions available on this menu"
|
||||
className="w-full"
|
||||
rules={[{ required: true, message: 'Please add aleast one action!' }]}
|
||||
>
|
||||
<Select mode="multiple" allowClear loading={permissionLoading} options={availablePermissions.map(p => ({ label: p, value: p }))}
|
||||
placeholder={permissionLoading ? "Loading permissions..." : "Select permissions..."}
|
||||
showSearch={{ filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()) }}
|
||||
placeholder={permissionLoading ? "Loading permissions..." : "Assign permissions to this menu..."}
|
||||
className="h-max"
|
||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
className="w-full min-h-[42px] [&_.ant-select-selector]:min-h-[42px]! [&_.ant-select-selector]:h-auto! [&_.ant-select-selector]:max-h-40! [&_.ant-select-selector]:overflow-y-auto! [&_.ant-select-selector]:p-1.5!"
|
||||
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||
tagRender={(props) => {
|
||||
const { value, closable, onClose } = props;
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 mr-1.5 my-0.5">
|
||||
<span className="inline-flex items-center gap-1 mr-1.5 my-1">
|
||||
<RbacBadge permission={String(value)} size="sm" />
|
||||
{closable && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="text-xs text-muted-foreground hover:text-rose-500 ml-0.5"
|
||||
aria-label={`Remove permission ${value}`}
|
||||
className="text-xs text-muted-foreground hover:text-rose-500 rounded p-0.5 hover:bg-rose-50 dark:hover:bg-rose-950/40 transition-colors"
|
||||
>
|
||||
<X size={10} />
|
||||
<X size={11} />
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
@@ -287,11 +312,18 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
||||
}}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Button variant='outline' className="mt-6" title="Add Permission" type="button" onClick={() => setShowPermissionForm(true)}><Plus /></Button>
|
||||
<div className="pt-6">
|
||||
<Button variant='outline' size='icon' type="button" onClick={() => setShowPermissionForm(true)}><Plus /></Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Form.Item name="description" label="Description">
|
||||
<Input.TextArea className="input" id="description" rows={3} placeholder="Describe the purpose of this menu" />
|
||||
<Form.Item name="description" label="Description" className="mb-0">
|
||||
<Input.TextArea
|
||||
className="input"
|
||||
id="description"
|
||||
rows={3}
|
||||
placeholder="Describe the purpose and scope of this menu..."
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
@@ -299,23 +331,25 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
||||
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={isLoading}>
|
||||
<Button type="submit" disabled={isLoading} className="bg-his hover:bg-his/90 text-white font-medium">
|
||||
{isLoading && (
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
<Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />
|
||||
)}
|
||||
Save Menu
|
||||
{isUpdate ? 'Save Changes' : 'Save'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
|
||||
{showPermissionForm ?
|
||||
{showPermissionForm && (
|
||||
<PermissionForm
|
||||
isUpdate={false}
|
||||
onCancel={() => { setShowPermissionForm(false); mutate() }}
|
||||
onCancel={() => {
|
||||
setShowPermissionForm(false);
|
||||
mutate();
|
||||
}}
|
||||
/>
|
||||
: null
|
||||
}
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Path URL',
|
||||
title: 'Menu Path',
|
||||
dataIndex: 'path_url',
|
||||
key: 'path_url',
|
||||
render: (path: string) => (
|
||||
@@ -156,29 +156,30 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
},
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'is_admin_menu',
|
||||
key: 'is_admin_menu',
|
||||
width: 120,
|
||||
dataIndex: 'is_menu_admin',
|
||||
key: 'is_menu_admin',
|
||||
width: 140,
|
||||
align: 'center',
|
||||
render: (isAdmin?: boolean) => (
|
||||
isAdmin ? (
|
||||
render: (_val: any, record: IMenu) => {
|
||||
const isAdmin = Boolean(record.is_admin_menu);
|
||||
return isAdmin ? (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-sm text-[11px] font-semibold bg-indigo-500/10 text-indigo-600 border border-indigo-500/20 dark:bg-indigo-500/20 dark:text-indigo-300 dark:border-indigo-500/30">
|
||||
Admin Panel
|
||||
Admin Menu
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-sm text-[11px] font-semibold bg-zinc-500/10 text-zinc-600 border border-zinc-500/20 dark:bg-zinc-500/20 dark:text-zinc-400 dark:border-zinc-500/30">
|
||||
General
|
||||
Non-Admin Menu
|
||||
</span>
|
||||
)
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Actions / Permissions',
|
||||
title: 'Permissions',
|
||||
dataIndex: 'action',
|
||||
key: 'action',
|
||||
render: (actions?: string[]) => {
|
||||
if (!actions || actions.length === 0) {
|
||||
return <span className="text-xs text-muted-foreground italic">No action assigned</span>;
|
||||
return <span className="text-xs text-muted-foreground italic">No permissions assigned</span>;
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap gap-1 max-w-md">
|
||||
@@ -200,7 +201,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'Action',
|
||||
title: 'Actions',
|
||||
key: 'row_action',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
@@ -230,7 +231,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
title="Delete Menu?"
|
||||
title="Delete Menu"
|
||||
description={`Are you sure you want to delete menu "${record.name}"? If this menu has child menus or permissions assigned, access may be affected.`}
|
||||
onConfirm={() => handleDelete(record.id!)}
|
||||
onOkSuccess={() => router.refresh()}
|
||||
@@ -276,7 +277,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
}}
|
||||
>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New Menu
|
||||
Create Menu
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -289,9 +290,9 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
||||
emptyText: (
|
||||
<div className="py-8 text-center text-muted-foreground">
|
||||
<i className="ti ti-category text-3xl mb-2 text-zinc-400 block" />
|
||||
<p className="text-sm font-medium">No menus registered</p>
|
||||
<p className="text-sm font-medium">No menus found</p>
|
||||
<p className="text-xs text-zinc-400 mt-1">
|
||||
{searchText ? 'No menu matching your search.' : 'Click "Create New Menu" to register your first navigation menu.'}
|
||||
{searchText ? 'No menu matching your search.' : 'Click "Create Menu" to register your first navigation menu.'}
|
||||
</p>
|
||||
</div>
|
||||
),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 || []);
|
||||
|
||||
@@ -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>
|
||||
|
||||
+15
-5
@@ -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;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from '@/components/ui/rbac-badge';
|
||||
export { default } from '@/components/ui/rbac-badge';
|
||||
@@ -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<IRolePermissionRowProps> = ({
|
||||
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 (
|
||||
<div
|
||||
className={cn(
|
||||
'flex flex-col py-3 px-3 sm:px-4 border-b border-zinc-200/80 dark:border-zinc-800/80 transition-colors',
|
||||
node.level === 0
|
||||
? 'bg-zinc-50/70 dark:bg-zinc-900/50'
|
||||
: 'bg-white dark:bg-zinc-950/40 hover:bg-zinc-50/40 dark:hover:bg-zinc-900/20'
|
||||
)}
|
||||
>
|
||||
{/* Top row: Hierarchy, Menu Identifier & Row Actions */}
|
||||
<div className="flex items-center justify-between gap-3 min-w-0">
|
||||
<div
|
||||
className="flex items-center gap-2.5 min-w-0 flex-1"
|
||||
style={{ paddingLeft: `${indentPx}px` }}
|
||||
>
|
||||
{/* Expand / Collapse Control */}
|
||||
{node.hasChildren ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleCollapse}
|
||||
aria-label={node.isCollapsed ? 'Expand menu' : 'Collapse menu'}
|
||||
className="w-5 h-5 flex items-center justify-center text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 rounded transition-colors shrink-0"
|
||||
>
|
||||
{node.isCollapsed ? <ChevronRight size={15} /> : <ChevronDown size={15} />}
|
||||
</button>
|
||||
) : (
|
||||
<span className="w-5 shrink-0" />
|
||||
)}
|
||||
|
||||
{/* Submenu Level Marker */}
|
||||
{node.level > 0 && (
|
||||
<span className="text-zinc-400 dark:text-zinc-600 font-mono text-xs select-none shrink-0">
|
||||
↳
|
||||
</span>
|
||||
)}
|
||||
|
||||
{/* Checkbox (interactive) or Row Index (readonly) */}
|
||||
{isInteractive ? (
|
||||
assignedActions.length > 0 && (
|
||||
<Checkbox
|
||||
checked={isAllSelected}
|
||||
indeterminate={isIndeterminate}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
onSelectAll?.();
|
||||
} else {
|
||||
onClearAll?.();
|
||||
}
|
||||
}}
|
||||
className="shrink-0"
|
||||
/>
|
||||
)
|
||||
) : (
|
||||
index !== undefined && (
|
||||
<span className="text-xs font-mono font-medium text-muted-foreground w-6 text-center shrink-0">
|
||||
{index + 1}
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
|
||||
{/* Icon, Title, Path & Admin Badge */}
|
||||
<div className="flex items-center gap-2 min-w-0 flex-wrap">
|
||||
{node.icon ? (
|
||||
<span className="inline-flex items-center justify-center w-6 h-6 rounded bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-300 text-xs shrink-0">
|
||||
<i className={node.icon} />
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center justify-center w-6 h-6 rounded bg-zinc-50 dark:bg-zinc-900 text-zinc-400 text-xs font-mono shrink-0">
|
||||
#
|
||||
</span>
|
||||
)}
|
||||
|
||||
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 truncate">
|
||||
{node.name}
|
||||
</span>
|
||||
|
||||
{node.path_url && (
|
||||
<span className="text-xs font-mono text-muted-foreground truncate">
|
||||
{node.path_url}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{node.is_menu_admin && (
|
||||
<span className="text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded bg-indigo-500/10 text-indigo-600 border border-indigo-500/20 dark:bg-indigo-500/20 dark:text-indigo-300 dark:border-indigo-500/30 shrink-0">
|
||||
Admin
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: Summary Count & Row Select/Clear Action */}
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{isInteractive ? (
|
||||
assignedActions.length > 0 && (
|
||||
<>
|
||||
<span className="hidden sm:inline-block text-xs font-mono text-muted-foreground">
|
||||
{currentSelected.length} / {assignedActions.length} selected
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-7 text-xs px-2.5 font-medium"
|
||||
onClick={() => {
|
||||
if (isAllSelected) {
|
||||
onClearAll?.();
|
||||
} else {
|
||||
onSelectAll?.();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isAllSelected ? 'Clear All' : 'Select All'}
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
) : (
|
||||
<span className="text-xs font-mono px-2 py-0.5 rounded bg-zinc-100 dark:bg-zinc-800 text-zinc-600 dark:text-zinc-300">
|
||||
{currentSelected.length} permissions
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom: Dedicated indented permission badges container */}
|
||||
<div
|
||||
className="mt-2.5"
|
||||
style={{ paddingLeft: `${actionsIndentPx}px` }}
|
||||
>
|
||||
{assignedActions.length > 0 ? (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{assignedActions.map(action => {
|
||||
const isChecked = currentSelected.includes(action);
|
||||
|
||||
if (isInteractive) {
|
||||
return (
|
||||
<label
|
||||
key={action}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1.5 px-2.5 py-1 rounded border text-xs cursor-pointer select-none transition-all',
|
||||
isChecked
|
||||
? 'bg-zinc-100/90 dark:bg-zinc-800/90 border-zinc-300 dark:border-zinc-700 shadow-xs'
|
||||
: 'bg-transparent border-zinc-200/60 dark:border-zinc-800/80 hover:border-zinc-300 dark:hover:border-zinc-700 opacity-80 hover:opacity-100'
|
||||
)}
|
||||
>
|
||||
<Checkbox
|
||||
checked={isChecked}
|
||||
onChange={(e) => onPermissionToggle?.(action, e.target.checked)}
|
||||
/>
|
||||
<RbacBadge permission={action} size="sm" />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
// Readonly view
|
||||
return (
|
||||
<RbacBadge key={action} permission={action} size="sm" />
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground italic block">
|
||||
No permissions assigned
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RolePermissionRow;
|
||||
@@ -36,7 +36,7 @@ const SIDEBAR_MENU = [
|
||||
submenuItems: [
|
||||
{
|
||||
title: "Access Permissions",
|
||||
path: '/rbac/action-pemission'
|
||||
path: '/rbac/action-permissions'
|
||||
},
|
||||
{
|
||||
title: "Menu Management",
|
||||
|
||||
@@ -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' },
|
||||
];
|
||||
|
||||
+1
-1
@@ -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?: {
|
||||
|
||||
Reference in New Issue
Block a user