'use client'; import { useState, useEffect } from 'react'; import { Card, CardHeader, CardContent } from '@/components/ui/Card'; import { Badge } from '@/components/ui/Badge'; import { Button } from '@/components/ui/Button'; import { formatDistanceToNow } from 'date-fns'; import { fr } from 'date-fns/locale'; interface SyncLog { id: string; source: string; status: string; message: string | null; tasksSync: number; createdAt: string; } interface JiraLogsProps { className?: string; } export function JiraLogs({ className = "" }: JiraLogsProps) { const [logs, setLogs] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const fetchLogs = async () => { try { setIsLoading(true); setError(null); const response = await fetch('/api/jira/logs?limit=10'); if (!response.ok) { throw new Error('Erreur lors de la récupération des logs'); } const { data } = await response.json(); setLogs(data); } catch (err) { setError(err instanceof Error ? err.message : 'Erreur inconnue'); } finally { setIsLoading(false); } }; useEffect(() => { fetchLogs(); }, []); const getStatusBadge = (status: string) => { switch (status) { case 'success': return ✓ Succès; case 'error': return ✗ Erreur; default: return {status}; } }; return (

LOGS JIRA

{error && (
{error}
)} {isLoading ? (
{[...Array(3)].map((_, i) => (
))}
) : logs.length === 0 ? (
📋
Aucun log de synchronisation
) : (
{logs.map((log) => (
{getStatusBadge(log.status)} {formatDistanceToNow(new Date(log.createdAt), { addSuffix: true, locale: fr })}
{log.tasksSync > 0 ? ( `${log.tasksSync} tâche${log.tasksSync > 1 ? 's' : ''} synchronisée${log.tasksSync > 1 ? 's' : ''}` ) : ( 'Aucune tâche synchronisée' )}
{log.message && (
{log.message}
)}
))}
)} {/* Info */}
Les logs sont conservés pour traçabilité des synchronisations
); }