import { redirect } from 'next/navigation'; import { getCurrentUser, toPublicUser } from '@/lib/auth/getCurrentUser'; import { createScheduleService, createProjectService, } from '@/lib/api/services'; import { Header } from '@/components/layout/Header'; import { ProjectNav } from '@/components/layout/ProjectNav'; import { CalendarEventForm } from '@/components/calendar/CalendarEventForm'; import { ForbiddenError, NotFoundError } from '@/lib/errors'; export const dynamic = 'force-dynamic'; const SOURCE_COLORS: Record = { event: 'bg-blue-100 text-blue-700', milestone: 'bg-purple-100 text-purple-700', todo: 'bg-yellow-100 text-yellow-700', }; export default async function CalendarPage({ params, searchParams, }: { params: Promise<{ projectId: string }>; searchParams: Promise<{ from?: string; to?: string }>; }) { const user = await getCurrentUser(); if (!user) redirect('/login'); const { projectId } = await params; const { from, to } = await searchParams; const projectService = createProjectService(); let project: Awaited>; try { project = projectService.getProject(user.id, Number(projectId)); } catch (error) { if (error instanceof ForbiddenError || error instanceof NotFoundError) { redirect('/dashboard'); } throw error; } // デフォルトは当月 const now = new Date(); const defaultFrom = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-01`; const rangeFrom = from ?? defaultFrom; const rangeTo = to ?? defaultFrom.replace(/-01$/, '-28'); const scheduleService = createScheduleService(); const events = scheduleService.getCalendarEvents(user.id, project.id, { from: rangeFrom, to: rangeTo, }); return (

カレンダー

期間: {rangeFrom} 〜 {rangeTo}

{events.length === 0 ? (

期間内のイベントはありません。

) : ( events.map((e) => (

{e.title}

{e.startAt}

{e.source}
)) )}
); }