import { useState, useEffect } from 'react' import { useParams, useNavigate, Link } from 'react-router-dom' import { useAuth } from '../context/AuthContext' export default function GuestDetail() { const { id } = useParams() const navigate = useNavigate() const { authFetch, user } = useAuth() const [guest, setGuest] = useState(null) useEffect(() => { authFetch(`/api/guests/${id}`).then((r) => (r.ok ? r.json() : null)).then(setGuest) }, [id]) const handleCandidature = async (action) => { const confirmMsg = action === 'start' ? 'Proposer la candidature de cet invité ?' : action === 'accept' ? 'Accepter → créer un compte membre et supprimer cet invité ?' : 'Refuser cette candidature ?' if (!confirm(confirmMsg)) return const r = await authFetch(`/api/guests/${id}/candidature`, { method: 'POST', body: JSON.stringify({ action }), }) if (r.ok) { if (action === 'accept') { alert('Membre créé ! Mot de passe par défaut : Bienvenue2026') navigate('/members') } else { const data = await r.json() alert(data.message) setGuest((g) => ({ ...g, statut_candidature: data.statut_candidature })) } } else { const err = await r.json() alert(err.error || 'Erreur') } } if (!guest) return
Chargement...
const isOwner = guest.invite_par_id === user?.id || user?.role === 'admin' const statutBadge = (s) => { if (s === 'acceptee') return ✓ Acceptée if (s === 'refusee') return ✗ Refusée return En attente } const candidatureBadge = (s) => { if (s === 'candidature') return Candidature en cours if (s === 'refuse') return Candidature refusée return null } return ({guest.societe}
} {guest.activite &&{guest.activite}
} {guest.visit_number === 2 && 2} {guest.visit_number >= 3 && {guest.visit_number}}Candidature refusée
)}Note : {guest.commentaires}
} {guest.date_club && ({new Date(guest.date_club) > new Date() ? 'Vient le' : 'Venue le'} {new Date(guest.date_club).toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}
)} {guest.invite_par_prenom && guest.invite_par_nom && (Invité par {guest.invite_par_prenom} {guest.invite_par_nom}
)} {guest.mail_envoye && guest.invitation_sent_at && (Email envoyé le {new Date(guest.invitation_sent_at).toLocaleDateString('fr-FR')}
)}