mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 12:46:29 +00:00
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:
@@ -5,10 +5,8 @@ import { MoreHorizontalIcon } from 'lucide-react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { PlusCircledIcon } from '@radix-ui/react-icons';
|
||||
import useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
@@ -21,9 +19,10 @@ import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInpu
|
||||
|
||||
type Props = {
|
||||
data: IClient[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IClient[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IClient>()
|
||||
@@ -133,7 +132,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()}>
|
||||
@@ -143,10 +142,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem><Link href={`/task/client-detail/${record.id}`} className='w-full'>View Details</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -175,10 +178,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 Client
|
||||
</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 Client
|
||||
</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: "Client - Project Assignment | Admin",
|
||||
}
|
||||
export default async function ClientPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/client')
|
||||
const data = await fetchData('/client')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function ClientPage() {
|
||||
<CardTitle>Client Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of clients 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>
|
||||
|
||||
@@ -18,9 +18,10 @@ import FormEndUser from '@/app/(dashboard)/task/component/FormEndUser';
|
||||
|
||||
type Props = {
|
||||
data: IEndUser[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IEndUser[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IEndUser>()
|
||||
@@ -115,7 +116,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()}>
|
||||
@@ -124,10 +125,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" onClick={e => e?.stopPropagation()}>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit End User</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete End User
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
@@ -156,10 +161,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 End User
|
||||
</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 End User
|
||||
</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: "End User - Project Assignment | Admin",
|
||||
}
|
||||
export default async function EndUserPage() {
|
||||
const actions = await getAccessPagePermission('/project-assignment/end-user')
|
||||
const data = await fetchData('/end-user')
|
||||
|
||||
return (
|
||||
@@ -22,13 +24,15 @@ export default async function EndUserPage() {
|
||||
<CardTitle>End User Management</CardTitle>
|
||||
<CardDescription className='mt-1'>Here's a list of end users 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>
|
||||
|
||||
@@ -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'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>
|
||||
|
||||
Reference in New Issue
Block a user