mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
279b642a7a
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.
89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
'use client'
|
|
|
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
|
import { Table } from 'antd';
|
|
import { TableProps, type ColumnsType } from 'antd/es/table';
|
|
import { Input } from '@/components/ui/input';
|
|
import { type IMasterStatus } from './type';
|
|
|
|
type Props = {
|
|
data: IMasterStatus[]
|
|
};
|
|
|
|
const ComponentRolePage: FC<Props> = ({ data }) => {
|
|
const [filterData, setFilterData] = useState<IMasterStatus[]>([])
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
setFilterData(data)
|
|
}
|
|
}, [data])
|
|
|
|
const handleSearch = (e: ChangeEvent<HTMLInputElement>) => {
|
|
const text = e.target.value
|
|
if (text) {
|
|
const newData = [...data!].filter(item => (
|
|
item.name?.toLowerCase().includes(text.toLowerCase()) ||
|
|
item.description?.toLowerCase().includes(text.toLowerCase())
|
|
))
|
|
setFilterData(newData)
|
|
} else {
|
|
setFilterData(data)
|
|
}
|
|
}
|
|
|
|
const Columns: ColumnsType<IMasterStatus> = [
|
|
{
|
|
title: 'Num',
|
|
dataIndex: 'key',
|
|
render: (text, record, index) => index + 1
|
|
},
|
|
{
|
|
title: 'Code',
|
|
dataIndex: 'code',
|
|
},
|
|
{
|
|
title: 'Name',
|
|
dataIndex: 'name',
|
|
sorter: (a, b) => a.name.localeCompare(b.name)
|
|
},
|
|
{
|
|
title: 'Description',
|
|
dataIndex: 'description',
|
|
}
|
|
];
|
|
|
|
const tableProps: TableProps<IMasterStatus> = {
|
|
bordered: false,
|
|
showHeader: true,
|
|
pagination: {
|
|
pageSizeOptions: [5, 10, 20, 50],
|
|
defaultPageSize: 10,
|
|
showSizeChanger: true,
|
|
showQuickJumper: true,
|
|
size: 'middle' as any
|
|
},
|
|
scroll: { x: 'max-content' },
|
|
tableLayout: 'auto',
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className='flex flex-col space-y-4'>
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex flex-1 items-center space-x-2">
|
|
<Input placeholder="Search master status..." className="h-8 w-[150px] lg:w-[250px]" onChange={handleSearch} />
|
|
</div>
|
|
</div>
|
|
<Table
|
|
{...tableProps}
|
|
rowKey='id'
|
|
columns={Columns}
|
|
dataSource={filterData || []}
|
|
/>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default ComponentRolePage; |