import { useState, useEffect, useMemo } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { formatDate } from '../utils/dateFormatter'; import { useTrip } from '../hooks/useTrip'; import PlannablesList from './plannables/PlannablesList'; import './TripDetail.css'; const TripDetail = () => { const { id } = useParams(); const navigate = useNavigate(); const [trip, setTrip] = useState(null); const { fetchTrip, loading, error } = useTrip(); useEffect(() => { const loadTrip = async () => { try { const tripData = await fetchTrip(id); setTrip(tripData); } catch (err) { console.error('Error loading trip:', err); } }; loadTrip(); }, [id, fetchTrip]); // Memoize trip dates display to prevent unnecessary re-renders const tripDatesDisplay = useMemo(() => { if (!trip) return null; return (
Start: {formatDate(trip.start_date)} End: {formatDate(trip.end_date)}
); }, [trip]); if (loading) { return (

Loading trip details...

); } if (error) { return (

Error

{error}

Back to Dashboard
); } if (!trip) { return null; } return (
← Back to Dashboard

{trip.name}

{trip.description && (

{trip.description}

)} {tripDatesDisplay}

Calendar View

Calendar view will be implemented here in the future

); }; export default TripDetail;