"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; interface Webinar { id: string; title: string; description: string; speaker: string; startAt: string; duration: number; bannerUrl?: string; category: string; capacity: number; priceCents: number; } interface Registration { id: string; userId: string; webinarId: string; registeredAt: string; webinar: Webinar; } function formatDate(dateString: string) { const date = new Date(dateString); return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", hour: "2-digit", minute: "2-digit", }); } export default function AccountWebinarsPage() { const router = useRouter(); const [registrations, setRegistrations] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { async function fetchRegistrations() { try { const res = await fetch("/api/account/webinars"); if (!res.ok) { if (res.status === 401) { router.push("/"); return; } throw new Error("Failed to fetch registrations"); } const data = await res.json(); setRegistrations(data.registrations || []); } catch (err) { console.error("Error fetching registrations:", err); setError("Failed to load your webinars"); } finally { setLoading(false); } } fetchRegistrations(); }, [router]); if (loading) { return (

📚 My Webinars

View your registered webinars

Loading your webinars...

); } return (

📚 My Webinars

View your registered webinars

{error && (
{error}
)} {registrations.length === 0 ? (

You haven't registered for any webinars yet.

🎓 Browse Webinars
) : (
{registrations.map((registration) => { const webinar = registration.webinar; const startDate = new Date(webinar.startAt); const now = new Date(); const isPast = startDate < now; return (
{webinar.bannerUrl && (
{webinar.title} {isPast && (
Completed
)}
)}

{webinar.title}

{webinar.category}

{webinar.description}

🎤 {webinar.speaker}
📅 {formatDate(webinar.startAt)}
⏱️ {webinar.duration} minutes
Registered {formatDate(registration.registeredAt).split(",")[0]}
📖 View Details {!isPast && ( )}
); })}
)}
); }