Files
towercontrol/src/hooks/useJiraExport.ts
Julien Froidefond 4152b0bdfc chore: refactor project structure and clean up unused components
- Updated `TODO.md` to reflect new testing tasks and final structure expectations.
- Simplified TypeScript path mappings in `tsconfig.json` for better clarity.
- Revised business logic separation rules in `.cursor/rules` to align with new directory structure.
- Deleted unused client components and services to streamline the codebase.
- Adjusted import paths in scripts to match the new structure.
2025-09-21 10:26:35 +02:00

59 lines
1.8 KiB
TypeScript

'use client';
import { useState, useTransition } from 'react';
import { exportJiraAnalytics, ExportFormat } from '@/actions/jira-export';
export function useJiraExport() {
const [isExporting, startTransition] = useTransition();
const [error, setError] = useState<string | null>(null);
const exportAnalytics = (format: ExportFormat = 'csv') => {
startTransition(async () => {
try {
setError(null);
const result = await exportJiraAnalytics(format);
if (result.success && result.data && result.filename) {
// Créer un blob et déclencher le téléchargement
const mimeType = format === 'json' ? 'application/json' : 'text/csv';
const blob = new Blob([result.data], { type: mimeType });
// Créer un lien temporaire pour le téléchargement
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = result.filename;
// Déclencher le téléchargement
document.body.appendChild(link);
link.click();
// Nettoyer
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
console.log(`✅ Export ${format.toUpperCase()} réussi: ${result.filename}`);
} else {
setError(result.error || 'Erreur lors de l\'export');
}
} catch (err) {
const errorMessage = err instanceof Error ? err.message : 'Erreur lors de l\'export';
setError(errorMessage);
console.error('Erreur export analytics:', err);
}
});
};
const exportCSV = () => exportAnalytics('csv');
const exportJSON = () => exportAnalytics('json');
return {
isExporting,
error,
exportCSV,
exportJSON,
exportAnalytics
};
}