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.
This commit is contained in:
58
src/hooks/useJiraExport.ts
Normal file
58
src/hooks/useJiraExport.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
'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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user