import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import api from '../utils/api'; import { Card } from '../components/ui/card'; import { Button } from '../components/ui/button'; import { Badge } from '../components/ui/badge'; import { toast } from 'sonner'; import Navbar from '../components/Navbar'; import { Calendar, MapPin, Users, ArrowLeft, Check, X, HelpCircle } from 'lucide-react'; const EventDetails = () => { const { id } = useParams(); const navigate = useNavigate(); const [event, setEvent] = useState(null); const [loading, setLoading] = useState(true); const [rsvpLoading, setRsvpLoading] = useState(false); useEffect(() => { fetchEvent(); }, [id]); const fetchEvent = async () => { try { const response = await api.get(`/events/${id}`); setEvent(response.data); } catch (error) { toast.error('Failed to load event'); navigate('/events'); } finally { setLoading(false); } }; const handleRSVP = async (status) => { setRsvpLoading(true); try { await api.post(`/events/${id}/rsvp`, { rsvp_status: status }); toast.success(`RSVP updated to: ${status}`); fetchEvent(); } catch (error) { toast.error('Failed to update RSVP'); } finally { setRsvpLoading(false); } }; if (loading) { return (

Loading event...

); } if (!event) { return null; } return (
{event.user_rsvp_status && ( {event.user_rsvp_status === 'yes' && 'Going'} {event.user_rsvp_status === 'no' && 'Not Going'} {event.user_rsvp_status === 'maybe' && 'Maybe'} )}

{event.title}

{new Date(event.start_at).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}
{new Date(event.start_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} -{' '} {new Date(event.end_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
{event.location}
{event.rsvp_count || 0} {event.rsvp_count === 1 ? 'person' : 'people'} attending {event.capacity && ` (Capacity: ${event.capacity})`}
{event.description && (

About This Event

{event.description}

)}

RSVP to This Event

); }; export default EventDetails;