import { useState, useMemo } from 'react' import { Link } from 'react-router-dom' import { addDays, startOfWeek, isSameDay } from 'date-fns' import { PageHeader, Button } from '../components/ui' import { useWorkorders } from '../hooks/useWorkorders' import { useEmployees } from '../hooks/useEmployees' import { groupAppointmentsByDay, countInRange, dayKey } from '../lib/planboard' import { ticketPath, ticketRef } from '../lib/ticketRoutes' import { planboardSubtitle, dayLabels, appointmentClass, appointmentTimeLabel, appointmentOwnerLabel, appointmentTitle, } from '../lib/planboardView' /* Termine haengen an den Tickets (startDate/startTime/endTime/assignedTo); die Aufbereitung steckt in src/lib/planboard.js, die Texte in src/lib/planboardView.js. */ export default function PlanboardPage() { const [currentWeek, setCurrentWeek] = useState(startOfWeek(new Date(), { weekStartsOn: 1 })) const { workorders, loading } = useWorkorders({ limit: 500 }) const { employees } = useEmployees() const weekDays = Array.from({ length: 7 }, (_, i) => addDays(currentWeek, i)) const navigateWeek = (dir) => setCurrentWeek((prev) => addDays(prev, dir * 7)) const goToday = () => setCurrentWeek(startOfWeek(new Date(), { weekStartsOn: 1 })) const byDay = useMemo(() => groupAppointmentsByDay(workorders || [], employees || []), [workorders, employees]) const weekCount = countInRange(byDay, weekDays) return (
} />
{weekDays.map((day, index) => { const entries = byDay[dayKey(day)] || [] const today = isSameDay(day, new Date()) const labels = dayLabels(day) return (
= 5 ? ' weekend' : ''}`} role="group" aria-label={labels.full} aria-current={today ? 'date' : undefined} >
{labels.weekday} {labels.number}
{entries.length === 0 &&
Keine Termine
} {entries.map((entry) => (
{appointmentTimeLabel(entry)}
{entry.customerName || entry.topic}
{entry.customerName &&
{entry.topic}
}
{appointmentOwnerLabel(entry)}
))}
) })}
) }