diff --git a/frontend/package.json b/frontend/package.json index e237d59..490e23e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,6 +21,8 @@ "devDependencies": { "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", + "@types/react-router-dom": "^5.3.3", + "@types/axios": "^0.14.0", "typescript": "^4.9.5", "react-scripts": "5.0.1" }, diff --git a/frontend/src/components/EventDetails.tsx b/frontend/src/components/EventDetails.tsx new file mode 100644 index 0000000..88585fd --- /dev/null +++ b/frontend/src/components/EventDetails.tsx @@ -0,0 +1,101 @@ +import React, { useState, useEffect } from 'react'; +import { useParams, useNavigate } from 'react-router-dom'; +import axios from 'axios'; +import { Event, Rsvp } from '../types'; +import { Button, Container, Typography, Box, Paper, List, ListItem, ListItemText, CircularProgress, Alert } from '@mui/material'; + +const EventDetails: React.FC = () => { + const { slug } = useParams<{ slug: string }>(); + const navigate = useNavigate(); + const [event, setEvent] = useState(null); + const [rsvps, setRsvps] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchEventDetails = async () => { + try { + const [eventResponse, rsvpsResponse] = await Promise.all([ + axios.get(`/api/events/${slug}`), + axios.get(`/api/events/${slug}/rsvps`) + ]); + setEvent(eventResponse.data); + setRsvps(rsvpsResponse.data); + setLoading(false); + } catch (error) { + setError('Failed to load event details'); + setLoading(false); + } + }; + + fetchEventDetails(); + }, [slug]); + + if (loading) { + return ( + + + + + + ); + } + + if (error) { + return ( + + {error} + + ); + } + + if (!event) { + return ( + + Event not found + + ); + } + + return ( + + + + {event.title} + + + {event.date} at {event.location} + + + {event.description} + + + + RSVPs + + + {rsvps.map((rsvp) => ( + + + + ))} + + + + + + + + ); +}; + +export default EventDetails; \ No newline at end of file diff --git a/frontend/src/types.ts b/frontend/src/types.ts new file mode 100644 index 0000000..ebfb118 --- /dev/null +++ b/frontend/src/types.ts @@ -0,0 +1,20 @@ +export interface Event { + id: number; + title: string; + description: string; + date: string; + location: string; + slug: string; + created_at: string; + updated_at: string; +} + +export interface Rsvp { + id: number; + event_id: number; + name: string; + email: string; + status: 'attending' | 'not_attending' | 'maybe'; + created_at: string; + updated_at: string; +} \ No newline at end of file