Apply RBAC permissions across admin and tasks

Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
This commit is contained in:
Ichsan Kurniawan
2026-11-09 17:32:31 +07:00
parent 1b37ff65f5
commit 279b642a7a
69 changed files with 1070 additions and 1167 deletions
@@ -17,9 +17,10 @@ import FormProject from './FormProject';
type Props = {
data: IProjectAssignment[]
actions?: string[]
};
const ComponentPage: FC<Props> = ({ data }) => {
const ComponentPage: FC<Props> = ({ data, actions }) => {
const [filterData, setFilterData] = useState<IProjectAssignment[]>([])
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
const [selectedData, setSelectedData] = useState<IProjectAssignment>()
@@ -135,7 +136,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
title: 'Action',
key: 'action',
fixed: 'right',
render: (_, record) => (
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
@@ -144,10 +145,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
Delete Project
</DropdownMenuItem>
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Project</DropdownMenuItem>
)}
{(actions.includes('DELETE')) && (
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
Delete Project
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
),
@@ -176,10 +181,12 @@ const ComponentPage: FC<Props> = ({ data }) => {
<div className="flex flex-1 items-center space-x-2">
<Input placeholder="Search data..." className="h-8 w-full sm:w-62.5" onChange={handleSearch} />
</div>
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
<PlusCircledIcon className="mr-2 h-4 w-4" />
Create New Project
</Button>
{(actions?.includes('CREATE')) && (
<Button size="sm" className="ml-auto h-8 w-full sm:w-max text-his" variant='ghost' onClick={() => { setAction('CREATE'); setSelectedData(undefined) }}>
<PlusCircledIcon className="mr-2 h-4 w-4" />
Create New Project
</Button>
)}
</div>
<Table
{...tableProps}
@@ -3,6 +3,7 @@ import { Suspense, lazy } from 'react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import LazyLoading from '@/components/loader/LazyLoading';
import fetchData from '@/lib/fetchData';
import { getAccessPagePermission } from '@/lib/get-access-data';
const ComponentPage = lazy(() => import('./component'));
const ExportComponent = lazy(() => import('./component/Export'));
@@ -11,6 +12,7 @@ export const metadata: Metadata = {
title: "Project - Project Assignment | Admin",
}
export default async function ProjectManagementPage() {
const actions = await getAccessPagePermission('/project-assignment/project-management')
const data = await fetchData('/project')
return (
@@ -22,13 +24,15 @@ export default async function ProjectManagementPage() {
<CardTitle>Project Management</CardTitle>
<CardDescription className='mt-1'>Here&apos;s a list of projects that have been registered for project assignment!</CardDescription>
</div>
<Suspense fallback={<LazyLoading />}>
<ExportComponent data={data} />
</Suspense>
{actions.includes('EXPORT') &&
<Suspense fallback={<LazyLoading />}>
<ExportComponent data={data} />
</Suspense>
}
</CardHeader>
<CardContent>
<Suspense fallback={<LazyLoading />}>
<ComponentPage data={data} />
<ComponentPage data={data} actions={actions} />
</Suspense>
</CardContent>
</Card>