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:
@@ -17,9 +17,10 @@ import { type IGlobalParameter } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IGlobalParameter[]
|
||||
actions?: string[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const ComponentPage: FC<Props> = ({ data, actions }) => {
|
||||
const [filterData, setFilterData] = useState<IGlobalParameter[]>([])
|
||||
const [selectedData, setSelectedData] = useState<IGlobalParameter | undefined>(undefined)
|
||||
const [showFormDialog, setShowFormDialog] = useState(false)
|
||||
@@ -32,7 +33,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
}
|
||||
}, [data])
|
||||
|
||||
const handleDelete = (id: string | number) => {
|
||||
const handleDelete = async (id: string | number) => {
|
||||
return axios.delete(`/global-parameter/${id}`).then(res => res.data)
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
{
|
||||
title: 'Action',
|
||||
key: 'action',
|
||||
render: (_, record) => (
|
||||
render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && (
|
||||
<AlertDialog>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -127,10 +128,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
{(actions.includes('UPDATE') || actions.includes('EDIT')) && (
|
||||
<DropdownMenuItem onClick={() => { setShowFormDialog(true); setSelectedData(record) }} >Edit</DropdownMenuItem>
|
||||
)}
|
||||
{(actions.includes('DELETE')) && (
|
||||
<AlertDialogTrigger asChild>
|
||||
<DropdownMenuItem>Delete</DropdownMenuItem>
|
||||
</AlertDialogTrigger>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ConfirmAsync
|
||||
@@ -171,12 +176,14 @@ const ComponentPage: FC<Props> = ({ data }) => {
|
||||
<div className='flex flex-col space-y-4'>
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between space-y-2 sm:space-y-0">
|
||||
<div className="flex flex-1 items-center space-x-2">
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-[250px]" onChange={handleSearch} />
|
||||
<Input placeholder="Search parameters..." className="h-8 w-full sm:w-62.5 lg:w-72" onChange={handleSearch} />
|
||||
</div>
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
{(actions?.includes('CREATE')) && (
|
||||
<Button size="sm" variant='ghost' className="ml-auto h-8 w-full sm:w-max text-his" onClick={() => setShowFormDialog(true)}>
|
||||
<PlusCircledIcon className="mr-2 h-4 w-4" />
|
||||
Create New
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
|
||||
Reference in New Issue
Block a user