'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 Link from 'next/link'; import Image from 'next/image'; import { IClient } from '@/app/(dashboard)/task/types'; import { LazyImage } from '@/components/ui/lazy-image'; import BadgeStatus from '@/components/ui/badge-status'; import FormClient from '@/app/(dashboard)/task/component/client/FormClient'; import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput'; type Props = { data: IClient[] actions?: string[] }; const ComponentPage: FC = ({ data, actions }) => { const [filterData, setFilterData] = useState([]) const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined) const [selectedData, setSelectedData] = useState() const router = useRouter() useEffect(() => { if (data) { setFilterData(data) } }, [data]) const handleSearch = (e: ChangeEvent) => { 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 = [ { title: 'No', dataIndex: 'key', render: (text, record, index) => index + 1 }, { title: 'Code', dataIndex: 'code', sorter: (a, b) => a.code.localeCompare(b.code) }, { title: 'Client Name', dataIndex: 'name', sorter: (a, b) => a.name.localeCompare(b.name), render: (text, record) => (
{record.photo ? : avatar }

{text}

) }, { title: 'Description', dataIndex: 'description', sorter: (a, b) => a.description.localeCompare(b.description) }, { title: 'Total Project', dataIndex: 'total_project', align: 'right' }, { title: 'Total WO', dataIndex: 'total_work_order', align: 'right' }, { title: 'Total User Assigned', dataIndex: 'total_user_assigned', align: 'right' }, { title: 'Status', dataIndex: 'status_name', filters: [ { text: 'ACTIVE', value: 'A', }, { text: 'INACTIVE', value: 'N', }, { text: 'DELETED', value: 'X', }, ], onFilter: (value, record) => record.status_name.indexOf(value as string) === 0, align: 'center', render: (text, record) => (
) }, { title: 'Action', key: 'action', fixed: 'right', render: (_, record) => (actions?.includes('UPDATE') || actions?.includes('EDIT') || actions?.includes('DELETE')) && ( e?.stopPropagation()}> View Details {(actions.includes('UPDATE') || actions.includes('EDIT')) && ( { setAction('EDIT'); setSelectedData(record) }}>Edit Client )} {(actions.includes('DELETE')) && ( { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}> Delete Client )} ), }, ]; const tableProps: TableProps = { 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 ( <>
{(actions?.includes('CREATE')) && ( )}
{(action === 'CREATE' || action === 'EDIT') && { router.refresh(); handleClose() }} />} {action === 'DELETE' ? { router.refresh(); handleClose() }} title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove client ${selectedData?.name} from our servers.`} titleButton={`I understand the consequences, delete this client`} /> : null} ); } export default ComponentPage;