'use client' import Layout from "@/components/layout/Layout"; import Link from "next/link"; import moment from "moment"; import { useState, useEffect } from "react"; import axios from "axios"; const formatEventDate = (dateStr) => { if (!dateStr) return "Details will be announced"; return dateStr.replace(/\d{4}-\d{2}-\d{2}/g, (date) => { const m = moment(date, "YYYY-MM-DD", true); return m.isValid() ? m.format("MMM D, YYYY") : date; }); }; import { useSearchParams } from "next/navigation"; export default function UpcomingEventSinglePage({ slug: propSlug }) { const searchParams = useSearchParams(); const [event, setEvent] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { let activeSlug = propSlug; if (!activeSlug && searchParams) { activeSlug = searchParams.get('slug') || searchParams.get('id'); } if (!activeSlug && typeof window !== 'undefined') { const parts = window.location.pathname.split('/').filter(Boolean); if (parts.length > 0) { activeSlug = parts[parts.length - 1]; } } const fetchEvent = async () => { try { const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3006/api'; const response = await axios.get(`${API_BASE_URL}/upcoming-events/slug/${activeSlug}`); if (response.data && response.data.success) { const e = response.data.data; setEvent({ ...e, title: e.title || e.eventtitle, date: e.date || e.eventdate, image: e.image || e.eventimageurl, desc: e.description || e.eventdescription, btnText: e.btn_text || e.btnText, link: e.link || `/upcoming-event/${e.slug}`, location: e.location || e.venue, }); } } catch (error) { console.error("Error fetching event details:", error); } finally { setLoading(false); } }; if (activeSlug) { fetchEvent(); } else { setLoading(false); } }, [propSlug, searchParams]); if (loading) { return ( Loading... ); } if (!event) { return ( Event not found Back to Events ); } const eventDate = formatEventDate(event.date); const eventLocation = event.location || "Venue will be confirmed"; return ( {event.title} Home {" "} {event.title} {event.title} {event.desc || "More details will be updated soon."} { e.target.onerror = null; e.target.src = '/assets/img/all-images/memory/memory-img4.png'; }} /> Event Details Date: {eventDate} Venue: {eventLocation} Time: {event.time || "Details will be announced"} {event.admission && ( <> Admission: {event.admission} > )} Additional Information Program details will be updated as they are confirmed. Registration or ticket information will be added here when available. Please check back closer to the event date for final details. ); }
{event.desc || "More details will be updated soon."}