feat: implement project export to Excel with API endpoint and UI button
This commit is contained in:
@@ -123,6 +123,28 @@ export default function ProjectListPage() {
|
||||
setSearchTerm('');
|
||||
};
|
||||
|
||||
const handleExportExcel = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/projects/export');
|
||||
if (response.ok) {
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `projects_export_${new Date().toISOString().split('T')[0]}.xlsx`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a);
|
||||
} else {
|
||||
alert('Failed to export projects. Please try again.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Export error:', error);
|
||||
alert('An error occurred during export. Please try again.');
|
||||
}
|
||||
};
|
||||
|
||||
const toggleFilters = () => {
|
||||
setFiltersExpanded(!filtersExpanded);
|
||||
};
|
||||
@@ -203,6 +225,27 @@ export default function ProjectListPage() {
|
||||
{t('projects.mine') || 'Moje'}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="lg"
|
||||
className="w-full sm:w-auto"
|
||||
onClick={handleExportExcel}
|
||||
>
|
||||
<svg
|
||||
className="w-5 h-5 mr-2"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
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>
|
||||
{t('projects.exportExcel') || 'Export to Excel'}
|
||||
</Button>
|
||||
<Link href="/projects/new" className="w-full sm:w-auto">
|
||||
<Button variant="primary" size="lg" className="w-full">
|
||||
<svg
|
||||
|
||||
Reference in New Issue
Block a user