mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 21:26:29 +00:00
initial commit for new hats app
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
'use client'
|
||||
|
||||
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
||||
import { Table } from 'antd';
|
||||
import { TableProps, type ColumnsType } from 'antd/es/table';
|
||||
import { MixerHorizontalIcon } from '@radix-ui/react-icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { type IPosition } from './type';
|
||||
|
||||
type Props = {
|
||||
data: IPosition[]
|
||||
};
|
||||
|
||||
const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IPosition[]>([])
|
||||
|
||||
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<IPosition> = [
|
||||
{
|
||||
title: 'Num',
|
||||
dataIndex: 'key',
|
||||
render: (text, record, index) => index + 1
|
||||
},
|
||||
{
|
||||
title: 'Code',
|
||||
dataIndex: 'code',
|
||||
},
|
||||
{
|
||||
title: 'Position name',
|
||||
dataIndex: 'name',
|
||||
sorter: (a, b) => a.name.localeCompare(b.name)
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
dataIndex: 'status',
|
||||
filters: [
|
||||
{
|
||||
text: 'ACTIVE',
|
||||
value: 'A',
|
||||
},
|
||||
{
|
||||
text: 'INACTIVE',
|
||||
value: 'N',
|
||||
},
|
||||
{
|
||||
text: 'DELETED',
|
||||
value: 'X',
|
||||
},
|
||||
],
|
||||
onFilter: (value, record) => record.status!.code.indexOf(value as string) === 0,
|
||||
align: 'center',
|
||||
render: (text, record) => (
|
||||
<div className='flex justify-center text-white font-semibold text-xs'>
|
||||
{record.status.code === 'A' ?
|
||||
<div className="px-2 py-1.5 rounded-full bg-green-500 w-24">{record.status.name}</div>
|
||||
:
|
||||
<div className="px-2 py-1.5 rounded-full bg-rose-500 w-24">{record.status.name}</div>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'description',
|
||||
}
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IPosition> = {
|
||||
bordered: false,
|
||||
showHeader: true,
|
||||
pagination: {
|
||||
pageSizeOptions: [5, 10, 20, 50],
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
size: 'default'
|
||||
},
|
||||
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 position..." className="h-8 w-[150px] lg:w-[250px]" onChange={handleSearch} />
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComponentRolePage;
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface IPosition {
|
||||
id: number,
|
||||
name: string,
|
||||
status: {
|
||||
id: number,
|
||||
code: "A" | 'N' | 'X',
|
||||
name: "ACTIVE" | 'INACTIVE' | 'DELETED'
|
||||
},
|
||||
description: string
|
||||
}
|
||||
Reference in New Issue
Block a user