mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 21:16: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.
67 lines
2.7 KiB
TypeScript
67 lines
2.7 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', value: 'project.code', width: 15 },
|
|
{ header: 'Name', key: 'name', value: 'project.name', width: 25 },
|
|
{ header: 'Client Name', key: 'client', value: 'client.name', width: 25 },
|
|
{ header: 'End User Name', key: 'end_user', value: 'end_user.name', width: 25 },
|
|
{ header: 'Year', key: 'year', value: 'project.year', width: 25 },
|
|
{ header: 'Start Date', key: 'start_date', value: 'project.start_date', style: { numFmt: 'dd/mm/yyyy' }, width: 25 },
|
|
{ header: 'End Date', key: 'end_date', value: 'project.end_date', style: { numFmt: 'dd/mm/yyyy' }, width: 25 },
|
|
{ header: 'Description', key: 'description', value: 'project.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 Projects')
|
|
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 = `Project 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; |