feat: add download functionality for upcoming projects report in Excel format

This commit is contained in:
2025-10-22 11:38:19 +02:00
parent af28be8112
commit 42668862fd
2 changed files with 237 additions and 0 deletions

View File

@@ -60,6 +60,7 @@ export default function ProjectCalendarPage() {
const [loading, setLoading] = useState(true);
const [currentDate, setCurrentDate] = useState(new Date());
const [viewMode, setViewMode] = useState('month'); // 'month' or 'upcoming'
const [downloading, setDownloading] = useState(false);
useEffect(() => {
fetch("/api/projects")
@@ -131,6 +132,37 @@ export default function ProjectCalendarPage() {
});
};
const handleDownloadReport = async () => {
setDownloading(true);
try {
const response = await fetch('/api/reports/upcoming-projects');
if (!response.ok) {
throw new Error('Failed to download report');
}
// Get the blob from the response
const blob = await response.blob();
// Create a download link
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `nadchodzace_projekty_${new Date().toISOString().split('T')[0]}.xlsx`;
document.body.appendChild(link);
link.click();
// Clean up
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('Error downloading report:', error);
alert('Błąd podczas pobierania raportu');
} finally {
setDownloading(false);
}
};
const renderCalendarGrid = () => {
const monthStart = startOfMonth(currentDate);
const monthEnd = endOfMonth(currentDate);
@@ -383,6 +415,19 @@ export default function ProjectCalendarPage() {
</div>
</PageHeader>
<div className="mb-4 flex justify-end">
<button
onClick={handleDownloadReport}
disabled={downloading}
className="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 disabled:opacity-50 disabled:cursor-not-allowed rounded transition-colors"
title={downloading ? 'Pobieranie...' : 'Eksportuj raport nadchodzących projektów do Excel'}
>
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth="2">
<path strokeLinecap="round" strokeLinejoin="round" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
</button>
</div>
{viewMode === 'month' ? renderCalendarGrid() : renderUpcomingView()}
</PageContainer>
);