'use client' import { FC, useState } from 'react'; import dayjs from 'dayjs'; import { useSession } from 'next-auth/react'; import { Icons } from '@/components/Icons'; import { Button } from '@/components/ui/button'; import DateRangePicker from './DateRangePicker'; import { exportAllEmployeeHistory } from '@/lib/exportExcel'; import { type IHistory } from '@/app/(dashboard)/history/components/type'; import { type IUser } from '@/app/admin/administration/user/component/type'; type Props = { data: IHistory[] }; const ExportComponent: FC = ({ data }) => { const [isLoading, setIsLoading] = useState(false) const { data: session } = useSession() const handleExport = async () => { setIsLoading(true) const resBlob: any = await exportAllEmployeeHistory(session?.user.detail as IUser, data) 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 = `Employee Attendance History - ${dayjs().format('YYYYMMDD HHmmssa')}`; // 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 ( <>
); } export default ExportComponent;