Files
hats-app/app/admin/rbac/user-role/edit/[id]/page.tsx
T
Ichsan Kurniawan 6ffe7746c8 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.
2026-11-05 20:37:39 +07:00

48 lines
1.2 KiB
TypeScript

import { type Metadata } from 'next';
import fetchData from '@/lib/fetchData';
import RoleForm from '../../component/RoleForm';
import { type IRole } from '../../component/type';
export const dynamic = 'force-dynamic';
export const metadata: Metadata = {
title: "Edit Role | Admin",
description: "Update role permissions and configuration",
};
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;
}
export default async function EditRolePage({ params }: Props) {
const { id } = await params;
const roleData = await getRoleData(id);
return (
<RoleForm
isUpdate={true}
roleId={id}
initialData={roleData}
/>
);
}