mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 23:16: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 { usePathname } from 'next/navigation';
|
||||||
import Link from 'next/link';
|
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() {
|
export default function AdminBreadcrumb() {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
@@ -12,6 +27,9 @@ export default function AdminBreadcrumb() {
|
|||||||
.slice(1); // skip 'admin'
|
.slice(1); // skip 'admin'
|
||||||
|
|
||||||
const formatSegment = (seg: string) => {
|
const formatSegment = (seg: string) => {
|
||||||
|
if (SEGMENT_LABELS[seg.toLowerCase()]) {
|
||||||
|
return SEGMENT_LABELS[seg.toLowerCase()];
|
||||||
|
}
|
||||||
return seg
|
return seg
|
||||||
.split('-')
|
.split('-')
|
||||||
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
@@ -55,4 +73,3 @@ export default function AdminBreadcrumb() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
{isLoading && (
|
{isLoading && (
|
||||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
)}
|
)}
|
||||||
{okText || 'Continue'}
|
{okText || 'Delete'}
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
import { MoreHorizontalIcon } from 'lucide-react';
|
import { MoreHorizontalIcon } from 'lucide-react';
|
||||||
import { Table } from 'antd';
|
import { Table } from 'antd';
|
||||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||||
@@ -27,6 +28,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
|
|
||||||
const axios = useAxiosAuth();
|
const axios = useAxiosAuth();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data && Array.isArray(data)) {
|
if (data && Array.isArray(data)) {
|
||||||
@@ -63,7 +65,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
|
|
||||||
const columns: ColumnsType<IPermission> = [
|
const columns: ColumnsType<IPermission> = [
|
||||||
{
|
{
|
||||||
title: 'Num',
|
title: 'No',
|
||||||
dataIndex: 'key',
|
dataIndex: 'key',
|
||||||
width: 70,
|
width: 70,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@@ -91,7 +93,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Action',
|
title: 'Actions',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 80,
|
width: 80,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@@ -101,7 +103,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||||
<MoreHorizontalIcon className="h-4 w-4" />
|
<MoreHorizontalIcon className="h-4 w-4" />
|
||||||
<span className="sr-only">Action</span>
|
<span className="sr-only">Actions</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
@@ -111,20 +113,20 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
setShowFormDialog(true);
|
setShowFormDialog(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Edit
|
Edit Permission
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<AlertDialogTrigger asChild>
|
<AlertDialogTrigger asChild>
|
||||||
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
<DropdownMenuItem className="text-rose-600 dark:text-rose-400">
|
||||||
Delete
|
Delete Permission
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</AlertDialogTrigger>
|
</AlertDialogTrigger>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<ConfirmAsync
|
<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.`}
|
description={`Are you sure you want to delete permission "${record.name}"? This may affect menus and roles using this permission.`}
|
||||||
onConfirm={() => handleDelete(record.id)}
|
onConfirm={() => handleDelete(record.id)}
|
||||||
onOkSuccess={() => { }}
|
onOkSuccess={() => router.refresh()}
|
||||||
/>
|
/>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
),
|
),
|
||||||
@@ -168,7 +170,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
Create New Permission
|
Create Permission
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -183,7 +185,7 @@ const ComponentPermissionPage: FC<Props> = ({ data }) => {
|
|||||||
<i className="ti ti-shield-lock text-3xl mb-2 text-zinc-400 block" />
|
<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-sm font-medium">No permissions found</p>
|
||||||
<p className="text-xs text-zinc-400 mt-1">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
{isLoading && (
|
{isLoading && (
|
||||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
)}
|
)}
|
||||||
{okText || 'Continue'}
|
{okText || 'Delete'}
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { Icons } from "@/components/Icons";
|
|||||||
import { type IMenu } from "./type";
|
import { type IMenu } from "./type";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { TABLER_ICON_OPTIONS } from "@/lib/tabler-icons";
|
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 { Plus, X } from "lucide-react";
|
||||||
import PermissionForm from "../../action-permissions/component/Form";
|
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) {
|
export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props) {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [selectedIcon, setSelectedIcon] = useState<string>('');
|
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 [form] = Form.useForm();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const axios = useAxiosAuth();
|
const axios = useAxiosAuth();
|
||||||
@@ -89,24 +90,27 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
return {
|
return {
|
||||||
label,
|
label,
|
||||||
value: item.id!,
|
value: item.id!,
|
||||||
isAdmin: item.is_admin_menu,
|
isAdmin: Boolean(item.is_admin_menu),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}, [menuList, isUpdate, data]);
|
}, [menuList, isUpdate, data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
const adminStatus = Boolean(data.is_admin_menu);
|
||||||
|
setIsAdminMenu(adminStatus);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
...data,
|
...data,
|
||||||
menu_parent_id: data.menu_parent_id ?? null,
|
menu_parent_id: data.menu_parent_id ?? null,
|
||||||
is_admin_menu: data.is_admin_menu ?? false,
|
is_menu_admin: adminStatus,
|
||||||
action: data.action ?? [],
|
action: data.action ?? [],
|
||||||
});
|
});
|
||||||
setSelectedIcon(data.icon || '');
|
setSelectedIcon(data.icon || '');
|
||||||
} else {
|
} else {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
|
setIsAdminMenu(false);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
is_admin_menu: false,
|
is_menu_admin: false,
|
||||||
menu_parent_id: null,
|
menu_parent_id: null,
|
||||||
action: [],
|
action: [],
|
||||||
});
|
});
|
||||||
@@ -120,7 +124,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
path_url: values.path_url?.trim(),
|
path_url: values.path_url?.trim(),
|
||||||
description: values.description?.trim() || '',
|
description: values.description?.trim() || '',
|
||||||
icon: values.icon?.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,
|
menu_parent_id: values.menu_parent_id ? Number(values.menu_parent_id) : null,
|
||||||
action: Array.isArray(values.action) ? values.action : [],
|
action: Array.isArray(values.action) ? values.action : [],
|
||||||
};
|
};
|
||||||
@@ -141,7 +145,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success('Menu successfully created.');
|
toast.success('Menu created successfully.');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
if (onCancel) onCancel();
|
if (onCancel) onCancel();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -164,7 +168,7 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success('Menu successfully updated.');
|
toast.success('Menu updated successfully.');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
if (onCancel) onCancel();
|
if (onCancel) onCancel();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -180,10 +184,10 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
<Form form={form} onFinish={handleSubmit} layout="vertical">
|
<Form form={form} onFinish={handleSubmit} layout="vertical">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle className="dark:text-white">
|
<DialogTitle className="dark:text-white">
|
||||||
{isUpdate ? 'Edit Menu' : 'Create New Menu'}
|
{isUpdate ? 'Edit Menu' : 'Create Menu'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Configure menu routing, hierarchy, tabler icon, and assigned permissions.
|
Configure menu routing, hierarchy, icon, and assigned permissions.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
@@ -198,20 +202,24 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="path_url"
|
name="path_url"
|
||||||
label="Path URL"
|
label="Menu Path"
|
||||||
rules={[{ required: true, message: 'Path URL is required!' }]}
|
rules={[{ required: true, message: 'Menu path is required!' }]}
|
||||||
>
|
>
|
||||||
<Input className="input font-mono" placeholder="e.g. /administration/user" />
|
<Input className="input font-mono" placeholder="e.g. /administration/user" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item name="menu_parent_id" label="Parent Menu" tooltip="Select parent menu or leave as Root menu (null)">
|
<Form.Item
|
||||||
<Select placeholder="Root Menu (No Parent)" allowClear
|
name="menu_parent_id"
|
||||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
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()) }}
|
showSearch={{ filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()) }}
|
||||||
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
options={[
|
options={[
|
||||||
{ label: '— Root Menu (None) —', value: null as any },
|
{ label: '(None) - Root Menu', value: null as any },
|
||||||
...validParentOptions.map(p => ({
|
...validParentOptions.map(p => ({
|
||||||
label: `${p.label} ${p.isAdmin ? ' (Admin)' : ''}`,
|
label: `${p.label} ${p.isAdmin ? '(Admin)' : ''}`,
|
||||||
value: p.value,
|
value: p.value,
|
||||||
})),
|
})),
|
||||||
]}
|
]}
|
||||||
@@ -231,8 +239,8 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Select placeholder="Select Tabler Icon" allowClear
|
<Select placeholder="Select Tabler Icon" allowClear showSearch
|
||||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
onChange={(val) => setSelectedIcon(val || '')}
|
onChange={(val) => setSelectedIcon(val || '')}
|
||||||
options={TABLER_ICON_OPTIONS.map(opt => ({
|
options={TABLER_ICON_OPTIONS.map(opt => ({
|
||||||
label: (
|
label: (
|
||||||
@@ -247,39 +255,56 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
/>
|
/>
|
||||||
</Form.Item>
|
</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>
|
<div>
|
||||||
<span className="text-sm font-medium text-zinc-900 dark:text-zinc-100 block">
|
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 block">
|
||||||
Admin Panel Menu
|
Admin Menu
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-muted-foreground block mt-0.5">
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Form.Item name="is_admin_menu" valuePropName="checked" className="mb-0">
|
<Form.Item name="is_menu_admin" valuePropName="checked" className="mb-0">
|
||||||
<Switch />
|
<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>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Action / Permissions Multi-select Container */}
|
||||||
<div className="flex items-center gap-2">
|
<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 }))}
|
<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()) }}
|
showSearch={{ filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()) }}
|
||||||
placeholder={permissionLoading ? "Loading permissions..." : "Assign permissions to this menu..."}
|
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!"
|
||||||
className="h-max"
|
getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
||||||
optionFilterProp="children" getPopupContainer={(triggerNode: any) => triggerNode.parentNode}
|
|
||||||
tagRender={(props) => {
|
tagRender={(props) => {
|
||||||
const { value, closable, onClose } = props;
|
const { value, closable, onClose } = props;
|
||||||
return (
|
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" />
|
<RbacBadge permission={String(value)} size="sm" />
|
||||||
{closable && (
|
{closable && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
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>
|
</button>
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
@@ -287,11 +312,18 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</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>
|
</div>
|
||||||
|
|
||||||
<Form.Item name="description" label="Description">
|
<Form.Item name="description" label="Description" className="mb-0">
|
||||||
<Input.TextArea className="input" id="description" rows={3} placeholder="Describe the purpose of this menu" />
|
<Input.TextArea
|
||||||
|
className="input"
|
||||||
|
id="description"
|
||||||
|
rows={3}
|
||||||
|
placeholder="Describe the purpose and scope of this menu..."
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -299,23 +331,25 @@ export default function MenuForm({ data, menuList, isUpdate, onCancel }: Props)
|
|||||||
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading}>
|
<Button variant="outline" type="button" onClick={onCancel} disabled={isLoading}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" disabled={isLoading}>
|
<Button type="submit" disabled={isLoading} className="bg-his hover:bg-his/90 text-white font-medium">
|
||||||
{isLoading && (
|
{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>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</Form>
|
</Form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
{showPermissionForm ?
|
{showPermissionForm && (
|
||||||
<PermissionForm
|
<PermissionForm
|
||||||
isUpdate={false}
|
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',
|
dataIndex: 'path_url',
|
||||||
key: 'path_url',
|
key: 'path_url',
|
||||||
render: (path: string) => (
|
render: (path: string) => (
|
||||||
@@ -156,29 +156,30 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Type',
|
title: 'Type',
|
||||||
dataIndex: 'is_admin_menu',
|
dataIndex: 'is_menu_admin',
|
||||||
key: 'is_admin_menu',
|
key: 'is_menu_admin',
|
||||||
width: 120,
|
width: 140,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
render: (isAdmin?: boolean) => (
|
render: (_val: any, record: IMenu) => {
|
||||||
isAdmin ? (
|
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">
|
<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>
|
||||||
) : (
|
) : (
|
||||||
<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">
|
<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>
|
</span>
|
||||||
)
|
);
|
||||||
),
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Actions / Permissions',
|
title: 'Permissions',
|
||||||
dataIndex: 'action',
|
dataIndex: 'action',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
render: (actions?: string[]) => {
|
render: (actions?: string[]) => {
|
||||||
if (!actions || actions.length === 0) {
|
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 (
|
return (
|
||||||
<div className="flex flex-wrap gap-1 max-w-md">
|
<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',
|
key: 'row_action',
|
||||||
width: 80,
|
width: 80,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@@ -230,7 +231,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
|||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<ConfirmAsync
|
<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.`}
|
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!)}
|
onConfirm={() => handleDelete(record.id!)}
|
||||||
onOkSuccess={() => router.refresh()}
|
onOkSuccess={() => router.refresh()}
|
||||||
@@ -276,7 +277,7 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
Create New Menu
|
Create Menu
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -289,9 +290,9 @@ const ComponentMenuPage: FC<Props> = ({ data }) => {
|
|||||||
emptyText: (
|
emptyText: (
|
||||||
<div className="py-8 text-center text-muted-foreground">
|
<div className="py-8 text-center text-muted-foreground">
|
||||||
<i className="ti ti-category text-3xl mb-2 text-zinc-400 block" />
|
<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">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -5,23 +5,41 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
|
|||||||
import fetchData from '@/lib/fetchData';
|
import fetchData from '@/lib/fetchData';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { type IRole, type IRoleDetail } from '../component/type';
|
import { type IRole, type IRoleDetail } from '../component/type';
|
||||||
import RbacBadge from '@/components/ui/rbac-badge';
|
import RolePermissionRow from '@/components/rbac/role-permission-row';
|
||||||
import { PencilLine } from 'lucide-react';
|
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Detail Hak Akses & Kewenangan | Admin",
|
title: "Role Permission Details | Admin",
|
||||||
description: "Detail of user role and authorized menu actions",
|
description: "Detailed overview of role permissions and authorized menu actions",
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ id: string }>;
|
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 UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||||
const { id } = await 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 isAdminAllowed = Boolean(data?.allow_admin_panel ?? data?.allow_admin);
|
||||||
const roleDetails: IRoleDetail[] = Array.isArray(data?.role_detail)
|
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_id: p.menu_id || p.id,
|
||||||
menu_name: p.menu_name || p.name,
|
menu_name: p.menu_name || p.name,
|
||||||
menu_path: p.menu_path || p.path || '#',
|
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 : [],
|
action: Array.isArray(p.action) ? p.action : [],
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
@@ -48,45 +66,45 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<div>
|
<div>
|
||||||
<CardTitle className="text-xl">Access and Permissions</CardTitle>
|
<CardTitle className="text-xl">Role Permission Details</CardTitle>
|
||||||
<CardDescription className="mt-1">
|
<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>
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
<Link href={`/admin/rbac/user-role/edit/${id}`}>
|
||||||
<Button className="bg-his hover:bg-his/90 text-white font-medium">
|
<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>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<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">
|
<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">
|
||||||
Kode Peran
|
Role Code
|
||||||
</span>
|
</span>
|
||||||
<span className="font-mono font-bold text-sm text-zinc-900 dark:text-zinc-100">
|
<span className="font-mono font-bold text-sm text-zinc-900 dark:text-zinc-100">
|
||||||
{data?.code || `ROLE-${id}`}
|
{data?.code || `ROLE-${id}`}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col space-y-1">
|
<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">
|
||||||
Nama Hak Akses
|
Role Name
|
||||||
</span>
|
</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 || '-'}
|
{data?.name || '-'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col space-y-1">
|
<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">
|
||||||
Akses Admin Panel
|
Admin Panel Access
|
||||||
</span>
|
</span>
|
||||||
<div>
|
<div>
|
||||||
{isAdminAllowed ? (
|
{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="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" />
|
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500" />
|
||||||
Admin Panel
|
Web CMS & Admin Panel
|
||||||
</span>
|
</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">
|
<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>
|
</div>
|
||||||
<div className="flex flex-col space-y-1">
|
<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
|
Status
|
||||||
</span>
|
</span>
|
||||||
<div>
|
<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="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" />
|
<span className="w-1.5 h-1.5 rounded-full bg-green-500" />
|
||||||
{data?.status?.name || 'Aktif'}
|
{data?.status?.name || 'Active'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col space-y-1 md:col-span-2">
|
<div className="flex flex-col space-y-1 md:col-span-2">
|
||||||
<span className="text-xs text-muted-foreground tracking-wider font-semibold">
|
<span className="text-xs text-muted-foreground uppercase tracking-wider font-semibold">
|
||||||
Deskripsi
|
Description
|
||||||
</span>
|
</span>
|
||||||
<span className="text-sm text-zinc-700 dark:text-zinc-300">
|
<span className="text-sm text-zinc-700 dark:text-zinc-300">
|
||||||
{data?.description || 'Tidak ada deskripsi.'}
|
{data?.description || 'No description provided.'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -126,70 +144,38 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
|||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<i className="ti ti-checklist text-lg text-his" />
|
<i className="ti ti-checklist text-lg text-his" />
|
||||||
<CardTitle className="text-base font-semibold">
|
<CardTitle className="text-base font-semibold">
|
||||||
Daftar Izin Menu & Aksi ({roleDetails.length} Menu Diizinkan)
|
Authorized Menu Permissions ({roleDetails.length} Menus Allowed)
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="p-0">
|
<CardContent className="p-0">
|
||||||
{roleDetails.length > 0 ? (
|
{roleDetails.length > 0 ? (
|
||||||
<div className="overflow-x-auto">
|
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
|
||||||
<table className="w-full text-sm">
|
{roleDetails.map((detail, idx) => (
|
||||||
<thead>
|
<RolePermissionRow
|
||||||
<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">
|
key={detail.menu_id || idx}
|
||||||
<th className="py-3 px-4 w-14 text-center">No</th>
|
node={{
|
||||||
<th className="py-3 px-4">Menu Aplikasi (Hierarki)</th>
|
id: detail.menu_id,
|
||||||
<th className="py-3 px-4">Aksi yang Diizinkan</th>
|
name: detail.menu_name,
|
||||||
</tr>
|
path_url: detail.menu_path,
|
||||||
</thead>
|
is_menu_admin: detail.is_admin_menu,
|
||||||
<tbody className="divide-y divide-zinc-200 dark:divide-zinc-800">
|
level: 0,
|
||||||
{roleDetails.map((detail, idx) => (
|
action: detail.action,
|
||||||
<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">
|
mode="readonly"
|
||||||
{idx + 1}
|
index={idx}
|
||||||
</td>
|
selectedActions={detail.action || []}
|
||||||
<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>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="py-12 text-center text-muted-foreground">
|
<div className="py-12 text-center text-muted-foreground">
|
||||||
<i className="ti ti-lock-open text-3xl mb-2 text-zinc-400 block" />
|
<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">
|
<Link href={`/admin/rbac/user-role/edit/${id}`} className="mt-3 inline-block">
|
||||||
<Button size="sm" variant="outline">
|
<Button size="sm" variant="outline">
|
||||||
Konfigurasi Hak Akses Sekarang
|
Configure Permissions Now
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
|
|
||||||
const showSuccess = () => {
|
const showSuccess = () => {
|
||||||
router.refresh();
|
router.refresh();
|
||||||
toast.success(contentSuccess || 'Role successfully removed.');
|
toast.success(contentSuccess || 'Role deleted successfully.');
|
||||||
if (onOkSuccess) onOkSuccess();
|
if (onOkSuccess) onOkSuccess();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
<AlertDialogTitle>{title || 'Are you absolutely sure?'}</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<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>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
@@ -64,7 +64,7 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
{isLoading && (
|
{isLoading && (
|
||||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||||
)}
|
)}
|
||||||
{okText || 'Continue'}
|
{okText || 'Delete'}
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
@@ -72,4 +72,3 @@ const ConfirmAsync: FC<Props> = ({ title, description, onConfirm, okText, cancel
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default ConfirmAsync;
|
export default ConfirmAsync;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { FC, useState, useMemo } from 'react';
|
import React, { FC, useState, useMemo } from 'react';
|
||||||
import { Checkbox, Input } from 'antd';
|
import { Input } from 'antd';
|
||||||
import { ChevronDown, ChevronRight, Search, Shield, ShieldCheck } from 'lucide-react';
|
import { Search, Shield, ShieldCheck } from 'lucide-react';
|
||||||
import { type IMenu } from './type';
|
import { type IMenu } from './type';
|
||||||
import RbacBadge from '@/components/ui/rbac-badge';
|
import RolePermissionRow from '@/components/rbac/role-permission-row';
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
|
|
||||||
export interface IMenuPermissionTreeProps {
|
export interface IMenuPermissionTreeProps {
|
||||||
menus: IMenu[];
|
menus: IMenu[];
|
||||||
@@ -71,7 +70,7 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
|
|
||||||
// Separate Non-Admin and Admin menus
|
// Separate Non-Admin and Admin menus
|
||||||
const { nonAdminTree, adminTree } = useMemo(() => {
|
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));
|
const adminList = menus.filter(m => Boolean(m.is_admin_menu));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -106,7 +105,7 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
return matches;
|
return matches;
|
||||||
}, [menus, searchQuery]);
|
}, [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) => {
|
const renderNode = (node: TreeNode) => {
|
||||||
if (node.id === undefined) return null;
|
if (node.id === undefined) return null;
|
||||||
if (searchMatchIds && !searchMatchIds.has(node.id)) {
|
if (searchMatchIds && !searchMatchIds.has(node.id)) {
|
||||||
@@ -114,127 +113,33 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isCollapsed = collapsedIds.has(node.id);
|
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 assignedActions = node.action || [];
|
||||||
const currentSelectedActions = selectedPermissions[node.id] || [];
|
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 (
|
return (
|
||||||
<React.Fragment key={node.id}>
|
<React.Fragment key={node.id}>
|
||||||
<div
|
<RolePermissionRow
|
||||||
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
|
node={{
|
||||||
? 'bg-zinc-50/70 dark:bg-zinc-900/60 font-semibold'
|
id: node.id,
|
||||||
: 'bg-white dark:bg-zinc-950/40 hover:bg-zinc-50/50 dark:hover:bg-zinc-900/30'
|
name: node.name,
|
||||||
}`}
|
path_url: node.path_url,
|
||||||
>
|
icon: node.icon,
|
||||||
{/* Left: Menu Name, Hierarchy Indent & Parent indicator */}
|
is_menu_admin: Boolean(node.is_admin_menu),
|
||||||
<div
|
level: node.level,
|
||||||
className="flex items-center gap-2 sm:gap-3 flex-1 min-w-0 mb-2 sm:mb-0"
|
hasChildren,
|
||||||
style={{ paddingLeft: `${node.level * 24}px` }}
|
isCollapsed,
|
||||||
>
|
action: assignedActions,
|
||||||
{hasChildren ? (
|
}}
|
||||||
<button
|
mode="interactive"
|
||||||
type="button"
|
selectedActions={currentSelectedActions}
|
||||||
onClick={() => toggleCollapse(node.id!)}
|
onToggleCollapse={() => 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"
|
onPermissionToggle={(actionName, checked) =>
|
||||||
>
|
onPermissionToggle(node.id!, actionName, checked)
|
||||||
{isCollapsed ? <ChevronRight size={15} /> : <ChevronDown size={15} />}
|
}
|
||||||
</button>
|
onSelectAll={() => onMenuSelectAll(node.id!, assignedActions)}
|
||||||
) : (
|
onClearAll={() => onMenuClearAll(node.id!)}
|
||||||
<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>
|
|
||||||
|
|
||||||
{/* Render children recursively if not collapsed */}
|
{/* Render children recursively if not collapsed */}
|
||||||
{hasChildren && !isCollapsed && node.children!.map(child => renderNode(child))}
|
{hasChildren && !isCollapsed && node.children!.map(child => renderNode(child))}
|
||||||
@@ -244,22 +149,24 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col space-y-6">
|
<div className="flex flex-col space-y-6">
|
||||||
{/* Search Bar */}
|
{/* Search Bar & Instruction */}
|
||||||
<div className="flex items-center justify-between gap-4">
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
|
||||||
<div className="w-full sm:w-72">
|
<div className="w-full sm:w-64 md:w-72">
|
||||||
<Input
|
<Input
|
||||||
prefix={<Search size={14} className="text-muted-foreground mr-1" />}
|
prefix={<Search size={14} className="text-muted-foreground mr-1" />}
|
||||||
placeholder="Cari menu atau permission..."
|
placeholder="Search menu or permission..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
allowClear
|
allowClear
|
||||||
className="h-9"
|
className="h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="hidden sm:flex items-center gap-2 text-xs text-muted-foreground">
|
<div className="text-xs text-muted-foreground flex items-center gap-1.5">
|
||||||
<span>Gunakan tombol</span>
|
<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-medium">Semua</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">
|
||||||
<span>atau centang permission per menu</span>
|
Select All
|
||||||
|
</span>
|
||||||
|
<span>to quickly grant all permissions for that menu</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -272,19 +179,19 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
Non-Admin Menus (General Application)
|
Non-Admin Menus (General Application)
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xs text-muted-foreground font-medium">
|
<span className="text-xs text-muted-foreground font-mono font-medium">
|
||||||
{menus.filter(m => !m.is_admin_menu).length} menu
|
{menus.filter(m => !(m.is_admin_menu)).length} menus
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="divide-y divide-zinc-200 dark:divide-zinc-800">
|
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
|
||||||
{nonAdminTree.length > 0 ? (
|
{nonAdminTree.length > 0 ?
|
||||||
nonAdminTree.map(node => renderNode(node))
|
nonAdminTree.map(node => renderNode(node))
|
||||||
) : (
|
:
|
||||||
<div className="py-8 text-center text-xs text-muted-foreground">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -298,19 +205,19 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
Admin Menus (Admin Panel)
|
Admin Menus (Admin Panel)
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xs text-muted-foreground font-medium">
|
<span className="text-xs text-muted-foreground font-mono font-medium">
|
||||||
{menus.filter(m => Boolean(m.is_admin_menu)).length} menu
|
{menus.filter(m => Boolean(m.is_admin_menu)).length} menus
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="divide-y divide-zinc-200 dark:divide-zinc-800">
|
<div className="divide-y divide-zinc-200/80 dark:divide-zinc-800/80">
|
||||||
{adminTree.length > 0 ? (
|
{adminTree.length > 0 ?
|
||||||
adminTree.map(node => renderNode(node))
|
adminTree.map(node => renderNode(node))
|
||||||
) : (
|
:
|
||||||
<div className="py-8 text-center text-xs text-muted-foreground">
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -319,4 +226,3 @@ export const MenuPermissionTree: FC<IMenuPermissionTreeProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default MenuPermissionTree;
|
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) {
|
} else if (Array.isArray(initialData.privilege) && initialData.privilege.length > 0) {
|
||||||
// Support legacy privilege format
|
|
||||||
initialData.privilege.forEach((item: any) => {
|
initialData.privilege.forEach((item: any) => {
|
||||||
const mId = item.menu_id || item.id;
|
const mId = item.menu_id || item.id;
|
||||||
if (mId && Array.isArray(item.action)) {
|
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) => {
|
setSelectedPermissions((prev) => {
|
||||||
const next = { ...prev };
|
const next = { ...prev };
|
||||||
menus.forEach((m) => {
|
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];
|
delete next[m.id];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -182,7 +184,8 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
if (!menu || !actions || actions.length === 0) return;
|
if (!menu || !actions || actions.length === 0) return;
|
||||||
|
|
||||||
// Rule: If allow_admin_panel is false, exclude Admin menus
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,19 +200,18 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
menu_id: menu.id!,
|
menu_id: menu.id!,
|
||||||
menu_name: menu.name,
|
menu_name: menu.name,
|
||||||
menu_path: menu.path_url || '#',
|
menu_path: menu.path_url || '#',
|
||||||
is_admin_menu: Boolean(menu.is_admin_menu),
|
is_admin_menu: isAdmin,
|
||||||
action: safeActions,
|
action: safeActions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const payload: Record<string, any> = {
|
const payload: Record<string, any> = {
|
||||||
|
code: values.name?.trim().replace(/\s/g, '_').toUpperCase(),
|
||||||
name: values.name?.trim(),
|
name: values.name?.trim(),
|
||||||
description: values.description?.trim() || '',
|
description: values.description?.trim() || '',
|
||||||
allow_admin_panel: Boolean(allowAdminPanel),
|
allow_admin_panel: Boolean(allowAdminPanel),
|
||||||
allow_admin: Boolean(allowAdminPanel), // For backward compatibility with legacy endpoints
|
|
||||||
role_detail: roleDetail,
|
role_detail: roleDetail,
|
||||||
privilege: roleDetail, // For backward compatibility with legacy endpoints
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isUpdate) {
|
if (!isUpdate) {
|
||||||
@@ -223,7 +225,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success('Role successfully created.');
|
toast.success('Role created successfully.');
|
||||||
router.push('/admin/rbac/user-role');
|
router.push('/admin/rbac/user-role');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} else {
|
} else {
|
||||||
@@ -237,7 +239,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
toast.success('Role successfully updated.');
|
toast.success('Role updated successfully.');
|
||||||
router.push('/admin/rbac/user-role');
|
router.push('/admin/rbac/user-role');
|
||||||
router.refresh();
|
router.refresh();
|
||||||
}
|
}
|
||||||
@@ -262,11 +264,11 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
</Link>
|
</Link>
|
||||||
<div>
|
<div>
|
||||||
<CardTitle className="text-xl">
|
<CardTitle className="text-xl">
|
||||||
{isUpdate ? 'Edit User Role' : 'Create New User Role'}
|
{isUpdate ? 'Edit Role' : 'Create Role'}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1">
|
<CardDescription className="mt-1">
|
||||||
{isUpdate
|
{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'}
|
: 'Define role details and assign hierarchical menu access'}
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</div>
|
</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">
|
<div className="flex items-center gap-2 self-end sm:self-auto">
|
||||||
<Link href="/admin/rbac/user-role">
|
<Link href="/admin/rbac/user-role">
|
||||||
<Button variant="outline" size="sm" disabled={isLoading}>
|
<Button variant="outline" size="sm" disabled={isLoading}>
|
||||||
Batal
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Button
|
<Button
|
||||||
@@ -285,57 +287,62 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
disabled={isLoading || menuLoading}
|
disabled={isLoading || menuLoading}
|
||||||
>
|
>
|
||||||
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
|
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
|
||||||
Simpan Perubahan
|
Save Changes
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Form Body */}
|
{/* Form Body */}
|
||||||
<Form form={form} layout="vertical" scrollToFirstError>
|
<Form form={form} layout="vertical" scrollToFirstError size='small'>
|
||||||
{/* Section A: General Information */}
|
{/* Section A: General Information */}
|
||||||
<Card className="mb-6">
|
<Card className="mb-6">
|
||||||
<CardHeader className="pb-4">
|
<CardHeader className="pb-4">
|
||||||
<CardTitle className="text-base font-semibold">
|
<CardTitle className="text-base font-semibold">
|
||||||
Informasi Umum (General Information)
|
General Information
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
Masukkan nama peran, deskripsi, dan hak akses admin panel
|
Enter role name, description, and admin panel privileges
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<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
|
<Form.Item
|
||||||
name="name"
|
name="name"
|
||||||
label="Role Name"
|
label="Role Name"
|
||||||
rules={[{ required: true, message: 'Role name is required!' }]}
|
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>
|
</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 className="p-3.5 rounded-lg -mt-5!">
|
||||||
<div>
|
<div className='mb-2'>
|
||||||
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 block">
|
<span className="text-sm font-semibold text-zinc-900 dark:text-zinc-100 block">
|
||||||
Allow Admin Panel
|
Allow Admin Panel
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-muted-foreground block mt-0.5">
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<Form.Item name="allow_admin_panel" valuePropName="checked" className="mb-0">
|
<Form.Item name="allow_admin_panel" valuePropName="checked">
|
||||||
<Switch
|
<Switch
|
||||||
|
size='medium'
|
||||||
checked={allowAdminPanel}
|
checked={allowAdminPanel}
|
||||||
onChange={handleAdminToggle}
|
onChange={handleAdminToggle}
|
||||||
|
style={{
|
||||||
|
backgroundColor: allowAdminPanel ? '#EA512C' : undefined,
|
||||||
|
}}
|
||||||
|
className="[&.ant-switch-checked]:bg-his! [&.ant-switch-checked:hover]:bg-his/90!"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Form.Item name="description" label="Description" className="mt-2 mb-0">
|
<Form.Item name="description" label="Description" className="mt-2 mb-0">
|
||||||
<Input.TextArea
|
<Input.TextArea size='large'
|
||||||
className="input"
|
className="input"
|
||||||
rows={2}
|
rows={2}
|
||||||
placeholder="Deskripsi tugas dan tanggung jawab role ini..."
|
placeholder="Describe role responsibilities and permission scope..."
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</CardContent>
|
</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 className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
||||||
<div>
|
<div>
|
||||||
<CardTitle className="text-base font-semibold">
|
<CardTitle className="text-base font-semibold">
|
||||||
Detil Hak Akses & Access Permissions
|
Menu Permissions & Access Rights
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription className="mt-1">
|
<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>
|
</CardDescription>
|
||||||
</div>
|
</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">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
@@ -362,7 +369,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
{menuLoading ? (
|
{menuLoading ? (
|
||||||
<div className="py-12 flex flex-col items-center justify-center text-muted-foreground">
|
<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" />
|
<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>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<MenuPermissionTree
|
<MenuPermissionTree
|
||||||
@@ -380,8 +387,8 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
{/* Bottom Action Bar */}
|
{/* Bottom Action Bar */}
|
||||||
<div className="mt-6 flex justify-end items-center gap-3">
|
<div className="mt-6 flex justify-end items-center gap-3">
|
||||||
<Link href="/admin/rbac/user-role">
|
<Link href="/admin/rbac/user-role">
|
||||||
<Button variant="outline" type="button" disabled={isLoading}>
|
<Button variant="outline" type="button" disabled={isLoading} className='text-zinc-800! dark:text-white'>
|
||||||
Batal
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Button
|
<Button
|
||||||
@@ -391,7 +398,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
disabled={isLoading || menuLoading}
|
disabled={isLoading || menuLoading}
|
||||||
>
|
>
|
||||||
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
|
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
|
||||||
Simpan Perubahan
|
Save Changes
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
@@ -402,14 +409,14 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
<AlertDialog open={true}>
|
<AlertDialog open={true}>
|
||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle>Konfirmasi Simpan Role?</AlertDialogTitle>
|
<AlertDialogTitle>Save Role Configuration?</AlertDialogTitle>
|
||||||
<AlertDialogDescription>
|
<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>
|
</AlertDialogDescription>
|
||||||
</AlertDialogHeader>
|
</AlertDialogHeader>
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>
|
<AlertDialogCancel disabled={isLoading} onClick={() => setShowConfirm(false)}>
|
||||||
Batal
|
Cancel
|
||||||
</AlertDialogCancel>
|
</AlertDialogCancel>
|
||||||
<AlertDialogAction
|
<AlertDialogAction
|
||||||
disabled={isLoading}
|
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" />}
|
{isLoading && <Icons.spinner className="mr-1.5 h-4 w-4 animate-spin" />}
|
||||||
Lanjutkan
|
Save Changes
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
@@ -431,4 +438,3 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default RoleForm;
|
export default RoleForm;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
|
|
||||||
const axios = useAxiosAuth();
|
const axios = useAxiosAuth();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data && Array.isArray(data)) {
|
if (data && Array.isArray(data)) {
|
||||||
@@ -56,7 +57,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
|
|
||||||
const columns: ColumnsType<IRole> = [
|
const columns: ColumnsType<IRole> = [
|
||||||
{
|
{
|
||||||
title: 'Num',
|
title: 'No',
|
||||||
dataIndex: 'key',
|
dataIndex: 'key',
|
||||||
width: 70,
|
width: 70,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@@ -118,8 +119,8 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
const count = Array.isArray(details)
|
const count = Array.isArray(details)
|
||||||
? details.length
|
? details.length
|
||||||
: Array.isArray(record.privilege)
|
: Array.isArray(record.privilege)
|
||||||
? record.privilege.length
|
? record.privilege.length
|
||||||
: 0;
|
: 0;
|
||||||
return (
|
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">
|
<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
|
{count} menus
|
||||||
@@ -137,7 +138,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Action',
|
title: 'Actions',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 80,
|
width: 80,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
@@ -147,13 +148,13 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||||
<MoreHorizontalIcon className="h-4 w-4" />
|
<MoreHorizontalIcon className="h-4 w-4" />
|
||||||
<span className="sr-only">Role Action</span>
|
<span className="sr-only">Role Actions</span>
|
||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem asChild>
|
<DropdownMenuItem asChild>
|
||||||
<Link href={`/admin/rbac/user-role/${record.id}`}>
|
<Link href={`/admin/rbac/user-role/${record.id}`}>
|
||||||
View Detail
|
View Details
|
||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem asChild>
|
<DropdownMenuItem asChild>
|
||||||
@@ -170,7 +171,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<ConfirmAsync
|
<ConfirmAsync
|
||||||
title="Delete Role?"
|
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!)}
|
onConfirm={() => handleDelete(record.id!)}
|
||||||
onOkSuccess={() => { }}
|
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">
|
<div className="flex flex-1 items-center space-x-2 w-full sm:w-auto">
|
||||||
<Input
|
<Input
|
||||||
placeholder="Search role name, code, description..."
|
placeholder="Search role name, code, description..."
|
||||||
className="h-8 w-full sm:w-64"
|
className="h-8 w-full sm:w-[280px]"
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChange={handleSearch}
|
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"
|
className="h-8 text-his hover:text-his hover:bg-his/10 font-semibold"
|
||||||
>
|
>
|
||||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||||
Create New Role
|
Create Role
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -228,7 +229,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
<ShieldCheck className="h-8 w-8 mx-auto mb-2 text-zinc-400" />
|
<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-sm font-medium">No roles found</p>
|
||||||
<p className="text-xs text-zinc-400 mt-1">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
@@ -239,4 +240,3 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default ComponentRolePage;
|
export default ComponentRolePage;
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import { type Metadata } from 'next';
|
|||||||
import RoleForm from '../component/RoleForm';
|
import RoleForm from '../component/RoleForm';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Create User Role | Admin",
|
title: "Create Role | Admin",
|
||||||
description: "Create a new user role with custom menu permissions",
|
description: "Create a new user role with custom menu permissions",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function CreateRolePage() {
|
export default function CreateRolePage() {
|
||||||
return <RoleForm isUpdate={false} />;
|
return <RoleForm isUpdate={false} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { type IRole } from '../../component/type';
|
|||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Edit User Role | Admin",
|
title: "Edit Role | Admin",
|
||||||
description: "Update role permissions and configuration",
|
description: "Update role permissions and configuration",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +22,6 @@ async function getRoleData(id: string): Promise<IRole | undefined> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Fallback: search in role list
|
|
||||||
try {
|
try {
|
||||||
const list = await fetchData('/role', 'no-cache');
|
const list = await fetchData('/role', 'no-cache');
|
||||||
const roles = Array.isArray(list) ? list : (list?.role || list?.roles || []);
|
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 dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "User Role Management | Admin",
|
title: "Role Management | Admin",
|
||||||
description: "Manage system user roles, admin panel access, and menu permissions",
|
description: "Manage system user roles, admin panel access, and menu permissions",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,9 +34,9 @@ export default async function UserRolePage() {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
<CardHeader className="flex flex-row items-center justify-between space-y-0">
|
||||||
<div>
|
<div>
|
||||||
<CardTitle>User Role</CardTitle>
|
<CardTitle>Role Management</CardTitle>
|
||||||
<CardDescription className="mt-1">
|
<CardDescription className="mt-1">
|
||||||
List of registered user roles and permission sets
|
List of registered user roles and permission configurations
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
+15
-5
@@ -183,16 +183,26 @@
|
|||||||
/* END SCROLLBAR */
|
/* END SCROLLBAR */
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-select {
|
.ant-select:not(.ant-select-multiple) {
|
||||||
/* display: flex; */
|
|
||||||
/* justify-content: center; */
|
|
||||||
/* align-items: center; */
|
|
||||||
/* padding: 19.35px 12px !important; */
|
|
||||||
font-size: 0.875rem !important/* 14px */;
|
font-size: 0.875rem !important/* 14px */;
|
||||||
line-height: 1.25rem !important/* 20px */;
|
line-height: 1.25rem !important/* 20px */;
|
||||||
height: 40px !important;
|
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{
|
/* .ant-select-selection-search{
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
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: [
|
submenuItems: [
|
||||||
{
|
{
|
||||||
title: "Access Permissions",
|
title: "Access Permissions",
|
||||||
path: '/rbac/action-pemission'
|
path: '/rbac/action-permissions'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Menu Management",
|
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 Text', value: 'ti ti-file-text', category: 'Reports' },
|
||||||
{ label: 'File Spreadsheet', value: 'ti ti-file-spreadsheet', category: 'Reports' },
|
{ label: 'File Spreadsheet', value: 'ti ti-file-spreadsheet', category: 'Reports' },
|
||||||
{ label: 'File Description', value: 'ti ti-file-description', category: 'Reports' },
|
{ label: 'File Description', value: 'ti ti-file-description', category: 'Reports' },
|
||||||
|
{ label: 'Notes', value: 'ti ti-notes', category: 'Reports' },
|
||||||
|
|
||||||
// Communication & Badges
|
// Communication & Badges
|
||||||
{ label: 'Id Badge', value: 'ti ti-id-badge', category: 'Security' },
|
{ label: 'Id Badge', value: 'ti ti-id-badge', category: 'Security' },
|
||||||
{ label: 'Credit Card', value: 'ti ti-credit-card', category: 'Security' },
|
{ label: 'Credit Card', value: 'ti ti-credit-card', category: 'Security' },
|
||||||
{ label: 'Scan', value: 'ti ti-scan', 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: 'Fingerprint', value: 'ti ti-fingerprint', category: 'Security' },
|
||||||
{ label: 'Bell', value: 'ti ti-bell', category: 'General' },
|
{ label: 'Bell', value: 'ti ti-bell', category: 'General' },
|
||||||
];
|
];
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ export interface IMenu {
|
|||||||
path_url: string;
|
path_url: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
is_admin_menu?: boolean;
|
is_admin_menu: boolean;
|
||||||
menu_parent_id?: number | null;
|
menu_parent_id?: number | null;
|
||||||
action?: string[];
|
action?: string[];
|
||||||
status?: {
|
status?: {
|
||||||
|
|||||||
Reference in New Issue
Block a user