import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import LoadingSpinner from '../components/LoadingSpinner'; import ElectionDetailsModal from '../components/ElectionDetailsModal'; import './UpcomingVotesPage.css'; export default function UpcomingVotesPage({ voter }) { const [upcomingElections, setUpcomingElections] = useState([]); const [loading, setLoading] = useState(true); const [selectedElectionId, setSelectedElectionId] = useState(null); const navigate = useNavigate(); useEffect(() => { fetchData(); }, []); const fetchData = async () => { try { const token = localStorage.getItem('token'); // Fetch upcoming elections const electionsResponse = await fetch('http://localhost:8000/api/elections/upcoming', { headers: { 'Authorization': `Bearer ${token}` }, }); if (!electionsResponse.ok) throw new Error('Erreur de chargement'); const electionsData = await electionsResponse.json(); setUpcomingElections(electionsData || []); } catch (err) { console.error('Erreur:', err); } finally { setLoading(false); } }; if (loading) return ; return (

⏳ Votes à Venir

Élections qui arriveront prochainement

{upcomingElections.length === 0 ? (
📭

Aucun vote à venir

Aucune élection prévue pour le moment.

) : ( <>
Élections à venir {upcomingElections.length}
{upcomingElections.map(election => (

{election.name}

⏳ À venir

Description : {election.description || 'N/A'}

Début : {new Date(election.start_date).toLocaleDateString('fr-FR')}

))}
)} setSelectedElectionId(null)} voter={voter} type="futur" />
); }