import { useState, useEffect } from 'react'; import { useParams, useNavigate, useLocation, Link } from 'react-router-dom'; import { CheckCircle, XCircle, Calendar, MapPin, Loader } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; import { eventsAPI } from '../services/api'; export default function EventCheckinPage() { const { token } = useParams(); const navigate = useNavigate(); const location = useLocation(); const { user } = useAuth(); const [loading, setLoading] = useState(true); const [success, setSuccess] = useState(false); const [alreadyCheckedIn, setAlreadyCheckedIn] = useState(false); const [eventData, setEventData] = useState(null); const [error, setError] = useState(''); useEffect(() => { // Redirect to login if not authenticated if (!user) { navigate('/login', { state: { from: location.pathname }, replace: true, }); return; } // Perform check-in performCheckin(); }, [user]); const performCheckin = async () => { try { setLoading(true); const response = await eventsAPI.checkin(token); if (response.success) { setSuccess(true); setAlreadyCheckedIn(response.alreadyCheckedIn); setEventData(response.data.event); } } catch (err) { console.error('Check-in error:', err); setError(err.message || 'Failed to check in to event'); } finally { setLoading(false); } }; const formatDate = (dateString) => { return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric', }); }; if (loading) { return (

Checking you in...

Please wait while we process your check-in

); } if (error) { return (

Check-in Failed

{error}

Back to Events
); } if (success && eventData) { return (

{alreadyCheckedIn ? 'Already Checked In!' : 'Check-in Successful!'}

{alreadyCheckedIn ? 'You are already a participant of this event' : 'You have successfully joined this event'}

{/* Event Info */}

{eventData.name}

{eventData.location}
{formatDate(eventData.startDate)} - {formatDate(eventData.endDate)}
{/* Actions */}
Go to Event Chat Browse Other Events
); } return null; }