2025-11-13 21:18:15 +01:00
|
|
|
import { useState, useEffect } from 'react';
|
2025-11-12 17:50:44 +01:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
|
|
import Layout from '../components/layout/Layout';
|
2025-11-13 21:18:15 +01:00
|
|
|
import { eventsAPI } from '../services/api';
|
|
|
|
|
import { Calendar, MapPin, Users, Loader2, CheckCircle } from 'lucide-react';
|
2025-11-12 17:50:44 +01:00
|
|
|
|
|
|
|
|
const EventsPage = () => {
|
|
|
|
|
const navigate = useNavigate();
|
2025-11-13 21:18:15 +01:00
|
|
|
const [events, setEvents] = useState([]);
|
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [error, setError] = useState('');
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const fetchEvents = async () => {
|
|
|
|
|
try {
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const data = await eventsAPI.getAll();
|
|
|
|
|
setEvents(data);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
setError('Failed to load events');
|
|
|
|
|
console.error('Error loading events:', err);
|
|
|
|
|
} finally {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fetchEvents();
|
|
|
|
|
}, []);
|
2025-11-12 17:50:44 +01:00
|
|
|
|
2025-11-13 21:43:58 +01:00
|
|
|
const handleJoinEvent = (slug) => {
|
|
|
|
|
navigate(`/events/${slug}/chat`);
|
2025-11-12 17:50:44 +01:00
|
|
|
};
|
|
|
|
|
|
2025-11-13 21:18:15 +01:00
|
|
|
if (loading) {
|
|
|
|
|
return (
|
|
|
|
|
<Layout>
|
|
|
|
|
<div className="max-w-4xl mx-auto flex items-center justify-center min-h-[400px]">
|
|
|
|
|
<div className="flex flex-col items-center gap-3">
|
|
|
|
|
<Loader2 className="w-12 h-12 animate-spin text-primary-600" />
|
|
|
|
|
<p className="text-gray-600">Loading events...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<Layout>
|
|
|
|
|
<div className="max-w-4xl mx-auto">
|
|
|
|
|
<div className="bg-red-50 border border-red-200 rounded-md p-4 text-red-700">
|
|
|
|
|
{error}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 17:50:44 +01:00
|
|
|
return (
|
|
|
|
|
<Layout>
|
|
|
|
|
<div className="max-w-4xl mx-auto">
|
|
|
|
|
<h1 className="text-3xl font-bold text-gray-900 mb-2">Choose an event</h1>
|
|
|
|
|
<p className="text-gray-600 mb-8">Join an event and start connecting with other dancers</p>
|
|
|
|
|
|
|
|
|
|
<div className="grid gap-6 md:grid-cols-2">
|
2025-11-13 21:18:15 +01:00
|
|
|
{events.map((event) => (
|
2025-11-12 17:50:44 +01:00
|
|
|
<div
|
|
|
|
|
key={event.id}
|
2025-11-13 21:18:15 +01:00
|
|
|
className={`bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow p-6 border-2 ${
|
|
|
|
|
event.isJoined ? 'border-primary-500' : 'border-gray-200'
|
|
|
|
|
}`}
|
2025-11-12 17:50:44 +01:00
|
|
|
>
|
2025-11-13 21:18:15 +01:00
|
|
|
<div className="flex items-start justify-between mb-3">
|
|
|
|
|
<h3 className="text-xl font-bold text-gray-900">{event.name}</h3>
|
|
|
|
|
{event.isJoined && (
|
|
|
|
|
<span className="flex items-center gap-1 px-2 py-1 bg-primary-100 text-primary-700 text-xs font-medium rounded-full">
|
|
|
|
|
<CheckCircle className="w-3 h-3" />
|
|
|
|
|
Joined
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-11-12 17:50:44 +01:00
|
|
|
|
|
|
|
|
<div className="space-y-2 mb-4">
|
|
|
|
|
<div className="flex items-center text-gray-600">
|
|
|
|
|
<MapPin className="w-4 h-4 mr-2" />
|
|
|
|
|
<span className="text-sm">{event.location}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center text-gray-600">
|
|
|
|
|
<Calendar className="w-4 h-4 mr-2" />
|
|
|
|
|
<span className="text-sm">
|
2025-11-13 21:18:15 +01:00
|
|
|
{new Date(event.startDate).toLocaleDateString('en-US')} - {new Date(event.endDate).toLocaleDateString('en-US')}
|
2025-11-12 17:50:44 +01:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center text-gray-600">
|
|
|
|
|
<Users className="w-4 h-4 mr-2" />
|
2025-11-13 21:18:15 +01:00
|
|
|
<span className="text-sm">{event.participantsCount} participants</span>
|
2025-11-12 17:50:44 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-11-13 21:18:15 +01:00
|
|
|
{event.description && (
|
|
|
|
|
<p className="text-gray-600 text-sm mb-4">{event.description}</p>
|
|
|
|
|
)}
|
2025-11-12 17:50:44 +01:00
|
|
|
|
|
|
|
|
<button
|
2025-11-13 21:43:58 +01:00
|
|
|
onClick={() => handleJoinEvent(event.slug)}
|
2025-11-12 17:50:44 +01:00
|
|
|
className="w-full px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 transition-colors"
|
|
|
|
|
>
|
2025-11-13 21:18:15 +01:00
|
|
|
{event.isJoined ? 'Open chat' : 'Join chat'}
|
2025-11-12 17:50:44 +01:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Layout>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default EventsPage;
|