mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
6ffe7746c8
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.
48 lines
1.2 KiB
TypeScript
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}
|
|
/>
|
|
);
|
|
}
|