mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 11:06:29 +00:00
3eabe762bf
Add new admin Project Assignment area with Client, End User, and Project Management pages and components (tables, Export buttons, lazy-loaded pages). Introduce FormProject for creating/editing projects and export utilities to download Excel for each module. Update task types: IEndUser now includes code and a status object. Clean up FormClient by removing unused imports and inline end-user modal usage. Make BadgeStatus robust to missing status values. Add "Project Assignment" entry to the sidebar and import FolderGit2.
183 lines
7.1 KiB
TypeScript
183 lines
7.1 KiB
TypeScript
'use client'
|
|
|
|
import { ChangeEvent, FC, useEffect, useState } from 'react';
|
|
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 { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { useRouter } from 'next/navigation';
|
|
import Image from 'next/image';
|
|
import { IEndUser } from '@/app/(dashboard)/task/types';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
|
import FormEndUser from '@/app/(dashboard)/task/component/FormEndUser';
|
|
|
|
type Props = {
|
|
data: IEndUser[]
|
|
};
|
|
|
|
const ComponentPage: FC<Props> = ({ data }) => {
|
|
const [filterData, setFilterData] = useState<IEndUser[]>([])
|
|
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
|
const [selectedData, setSelectedData] = useState<IEndUser>()
|
|
|
|
const router = useRouter()
|
|
|
|
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.code?.toLowerCase()?.includes(text.toLowerCase()) ||
|
|
item.description?.toLowerCase().includes(text.toLowerCase()) ||
|
|
item?.status.name.toLowerCase()?.includes(text.toLowerCase())
|
|
))
|
|
setFilterData(newData)
|
|
} else {
|
|
setFilterData(data)
|
|
}
|
|
}
|
|
|
|
const handleClose = () => {
|
|
setAction(undefined)
|
|
setSelectedData(undefined)
|
|
}
|
|
|
|
const Columns: ColumnsType<IEndUser> = [
|
|
{
|
|
title: 'No',
|
|
dataIndex: 'key',
|
|
render: (text, record, index) => index + 1
|
|
},
|
|
{
|
|
title: 'Code',
|
|
dataIndex: 'code',
|
|
sorter: (a, b) => a.code!.localeCompare(b.code!)
|
|
},
|
|
{
|
|
title: 'End User Name',
|
|
dataIndex: 'name',
|
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
|
render: (text, record) => (
|
|
<div className='flex items-center space-x-2.5'>
|
|
{record.photo ?
|
|
<LazyImage className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' alt='logo' src={record.photo} />
|
|
:
|
|
<Image alt='avatar' height={0} width={0} quality={50} src='/assets/ilustration.png' className='w-8 h-8 rounded-md border dark:border-zinc-800 object-cover' />
|
|
}
|
|
<p>{text}</p>
|
|
</div>
|
|
)
|
|
},
|
|
{
|
|
title: 'Description',
|
|
dataIndex: 'description',
|
|
sorter: (a, b) => a.description.localeCompare(b.description)
|
|
},
|
|
{
|
|
title: 'Status',
|
|
dataIndex: 'status_name',
|
|
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'>
|
|
<BadgeStatus status={record.status.name} />
|
|
</div>
|
|
)
|
|
},
|
|
{
|
|
title: 'Action',
|
|
key: 'action',
|
|
fixed: 'right',
|
|
render: (_, record) => (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant='ghost' size="icon" onClick={e => e?.stopPropagation()}>
|
|
<MoreHorizontalIcon />
|
|
<span className="sr-only">Action Button</span>
|
|
</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>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
),
|
|
},
|
|
];
|
|
|
|
const tableProps: TableProps<IEndUser> = {
|
|
bordered: false,
|
|
size: 'large',
|
|
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 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 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>
|
|
</div>
|
|
<Table
|
|
{...tableProps}
|
|
rowKey='id'
|
|
columns={Columns}
|
|
dataSource={filterData || []}
|
|
style={{ cursor: "pointer" }}
|
|
/>
|
|
</div>
|
|
|
|
{(action === 'CREATE' || action === 'EDIT') && <FormEndUser data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
|
|
|
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/end-user/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }}
|
|
title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove End User ${selectedData?.name} from our servers.`}
|
|
titleButton={`I understand the consequences, delete this End User`}
|
|
/> : null}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default ComponentPage; |