Files
Ichsan Kurniawan 3eabe762bf 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.
2026-05-06 18:34:38 +07:00

65 lines
2.3 KiB
TypeScript

'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;