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:
Ichsan Kurniawan
2026-05-06 18:34:38 +07:00
parent bbc2c7e3e2
commit 3eabe762bf
14 changed files with 1157 additions and 14 deletions
@@ -0,0 +1,62 @@
'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: 'Status', key: 'status', value: 'status.name', width: 15 }
]
const resBlob: any = await exportTable(session?.user.detail as IUser, data, columns, 'List of End Users')
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 = `End User 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,183 @@
'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;
@@ -0,0 +1,38 @@
import { type Metadata } from 'next';
import { Suspense, lazy } from 'react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import LazyLoading from '@/components/loader/LazyLoading';
import fetchData from '@/lib/fetchData';
const ComponentPage = lazy(() => import('./component'));
const ExportComponent = lazy(() => import('./component/Export'));
export const metadata: Metadata = {
title: "End User - Project Assignment | Admin",
}
export default async function EndUserPage() {
const data = await fetchData('/end-user')
return (
<>
<div className="flex flex-col">
<Card>
<CardHeader className='flex flex-col md:flex-row items-center justify-between space-y-5 sm:space-y-0'>
<div>
<CardTitle>End User Management</CardTitle>
<CardDescription className='mt-1'>Here&apos;s a list of end users that have been registered for project assignment!</CardDescription>
</div>
<Suspense fallback={<LazyLoading />}>
<ExportComponent data={data} />
</Suspense>
</CardHeader>
<CardContent>
<Suspense fallback={<LazyLoading />}>
<ComponentPage data={data} />
</Suspense>
</CardContent>
</Card>
</div>
</>
);
}