'use client'; import { useState, useEffect } from 'react'; import FullCalendar from '@fullcalendar/react'; import dayGridPlugin from '@fullcalendar/daygrid'; import timeGridPlugin from '@fullcalendar/timegrid'; import interactionPlugin from '@fullcalendar/interaction'; import { useTranslation } from '@/lib/i18n'; import { useAuth } from '@/lib/auth'; import { useRouter } from 'next/navigation'; interface CalTask { id: string; title: string; scheduled_at: string | null; due_at: string | null; status: string; group_name: string; group_color: string; } const LOCALE_MAP: Record = { cs: 'cs', he: 'he', ru: 'ru', ua: 'uk', }; export default function CalendarPage() { const [tasks, setTasks] = useState([]); const [error, setError] = useState(null); const { t, locale } = useTranslation(); const { token } = useAuth(); const router = useRouter(); useEffect(() => { if (!token) { router.replace('/login'); return; } fetch('/api/v1/tasks?limit=100', { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, }) .then(r => { if (!r.ok) throw new Error(`HTTP ${r.status}`); return r.json(); }) .then(d => setTasks(d.data || [])) .catch(err => setError(err.message)); }, [token, router]); const events = tasks .filter((tk) => tk.scheduled_at !== null || tk.due_at !== null) .map(tk => ({ id: tk.id, title: tk.title, start: (tk.scheduled_at || tk.due_at) as string, end: (tk.due_at || tk.scheduled_at) as string, backgroundColor: tk.group_color || '#3B82F6', borderColor: tk.group_color || '#3B82F6', extendedProps: { status: tk.status, group: tk.group_name }, })); // Build background events from unique groups const groupColors = new Map(); tasks.forEach(tk => { if (tk.group_name && tk.group_color) { groupColors.set(tk.group_name, tk.group_color); } }); if (!token) return null; return (

{t('calendar.title')}

{error && (
{error}
)}
); }