mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 10:26:28 +00:00
Add project-assignment admin pages and UI updates
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.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
'use client'
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
import { Icons } from '@/components/Icons';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { exportTable } from '@/lib/exportExcel';
|
||||
import dayjs from 'dayjs';
|
||||
import { IExcelJSColumnType } from '@/types/types';
|
||||
import { IUser } from '@/app/admin/administration/user/component/type';
|
||||
|
||||
type Props = {
|
||||
data: IUser[]
|
||||
}
|
||||
|
||||
const ExportComponent: FC<Props> = ({ data }) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
const { data: session } = useSession()
|
||||
|
||||
const handleExport = async () => {
|
||||
setIsLoading(true)
|
||||
|
||||
const columns: IExcelJSColumnType[] = [
|
||||
{ header: 'No', key: 'number', width: 5, style: { numFmt: '0;[Red]0' } },
|
||||
{ header: 'Code', key: 'code', width: 15 },
|
||||
{ header: 'Name', key: 'name', width: 25 },
|
||||
{ header: 'Description', key: 'description', width: 25 },
|
||||
{ header: 'Total Project', key: 'total_project', width: 10 },
|
||||
{ header: 'Total WO', key: 'total_work_order', width: 10 },
|
||||
{ header: 'Total User Assigned', key: 'total_user_assigned', width: 10 },
|
||||
{ header: 'Status', key: 'status_name', width: 15 },
|
||||
]
|
||||
|
||||
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of Clients')
|
||||
if (resBlob) {
|
||||
const url = URL.createObjectURL(resBlob);
|
||||
|
||||
// Create a link and trigger a click event to start the download
|
||||
const a = document.createElement("a");
|
||||
a.style.display = "none";
|
||||
a.href = url;
|
||||
a.download = `Client List - Export by ${session?.user.detail.nik} - ${dayjs().format('YYYYMMDD HH:mm:ss')}`; // Set the downloaded filename
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
|
||||
// Clean up by removing the temporary link and URL
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button className='w-full sm:w-max' disabled={isLoading} onClick={handleExport}>
|
||||
{isLoading &&
|
||||
<Icons.spinner className="mr-1 h-4 w-4 animate-spin" />
|
||||
}
|
||||
Download
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ExportComponent;
|
||||
@@ -0,0 +1,202 @@
|
||||
'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 useAxiosAuth from '@/lib/axios/useAxiosAuth';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
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/FormClient';
|
||||
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
||||
|
||||
type Props = {
|
||||
data: IClient[]
|
||||
};
|
||||
|
||||
const ComponentPage: FC<Props> = ({ data }) => {
|
||||
const [filterData, setFilterData] = useState<IClient[]>([])
|
||||
const [action, setAction] = useState<'CREATE' | 'EDIT' | 'DELETE' | undefined>(undefined)
|
||||
const [selectedData, setSelectedData] = useState<IClient>()
|
||||
|
||||
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<IClient> = [
|
||||
{
|
||||
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) => (
|
||||
<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: '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) => (
|
||||
<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><Link href={`/task/client-detail/${record.id}`} className='w-full'>View Details</Link></DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setAction('EDIT'); setSelectedData(record) }}>Edit Client</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => { setSelectedData(record); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
||||
Delete Client
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const tableProps: TableProps<IClient> = {
|
||||
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 Client
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey='id'
|
||||
columns={Columns}
|
||||
dataSource={filterData || []}
|
||||
style={{ cursor: "pointer" }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{(action === 'CREATE' || action === 'EDIT') && <FormClient data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
||||
|
||||
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/client/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { 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;
|
||||
Reference in New Issue
Block a user