"use client"; import { useEffect, useMemo, useState } from "react"; import FullCalendar from "@fullcalendar/react"; import dayGridPlugin from "@fullcalendar/daygrid"; import timeGridPlugin from "@fullcalendar/timegrid"; import listPlugin from "@fullcalendar/list"; import interactionPlugin from "@fullcalendar/interaction"; import { useSession } from "next-auth/react"; type EventItem = { id: string; title: string; description?: string | null; location?: string | null; startAt: string; endAt: string; status: string; }; export default function CalendarBoard() { const { data } = useSession(); const [events, setEvents] = useState([]); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const fetchEvents = async () => { setLoading(true); setError(null); try { const response = await fetch("/api/events"); if (!response.ok) { throw new Error("Events konnten nicht geladen werden."); } const payload = await response.json(); setEvents(payload); } catch (err) { setError((err as Error).message); } finally { setLoading(false); } }; useEffect(() => { if (data?.user) { fetchEvents(); } }, [data?.user]); const calendarEvents = useMemo( () => events.map((event) => ({ id: event.id, title: event.title, start: event.startAt, end: event.endAt, extendedProps: { status: event.status, location: event.location, description: event.description } })), [events] ); if (!data?.user) { return (

Bitte anmelden, um die Vereinskalender zu sehen.

); } return (

Kalender

{error &&

{error}

} {loading &&

Lade Termine...

}
{ const status = arg.event.extendedProps.status; return (
{arg.event.title}
{status !== "APPROVED" && (
{status}
)}
); }} height="auto" />
); }