import { useState } from 'react'; import { useNavigate } from 'react-router'; import { ChevronLeft, ChevronRight, Pencil } from 'lucide-react'; import { clsx } from 'clsx'; import type { inferRouterOutputs } from '@trpc/server'; import type { AppRouter } from '@cockpit/api/router'; import { trpc } from '../lib/trpc'; import { Card } from '../components/ui/Card'; import { Button } from '../components/ui/Button'; import { SkeletonCard } from '../components/ui/SkeletonCard'; import { ErrorState } from '../components/ui/ErrorState'; import { useCurrentUser } from '../hooks/useCurrentUser'; type HistoryPerson = inferRouterOutputs['dayEntry']['historyForDate']['entries'][number]; const AMPEL_META: Record = { green: { label: 'Im Plan', badge: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]', }, amber: { label: 'Gefährdet', badge: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]', }, red: { label: 'Blockiert', badge: 'bg-[var(--color-ampel-red-bg)] text-[var(--color-ampel-red-fg)]', }, }; const TREND_LABEL: Record = { besser: '↗ Besser', gleich: '→ Gleich', schlechter: '↘ Schlechter', }; function formatDateLong(iso: string): string { return new Intl.DateTimeFormat('de-DE', { timeZone: 'Europe/Berlin', weekday: 'short', day: 'numeric', month: 'long', year: 'numeric', }).format(new Date(`${iso}T12:00:00Z`)); } const todayStr = new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Berlin' }).format(new Date()); // Editierbar bis 3 Kalendertage nach dem Tag (Spiegel der Backend-Nachfrist). function isWithinGraceFE(dateIso: string): boolean { const cur = new Date(`${dateIso}T12:00:00Z`).getTime(); const today = new Date(`${todayStr}T12:00:00Z`).getTime(); const diffDays = Math.round((today - cur) / 86_400_000); return diffDays >= 0 && diffDays <= 3; } export function HistorieRoute() { const [date, setDate] = useState(undefined); const me = useCurrentUser(); const navigate = useNavigate(); const q = trpc.dayEntry.historyForDate.useQuery({ date }); if (q.isPending) return ; if (q.isError || !q.data) return ( void q.refetch()} /> ); const { date: current, prevDate, nextDate, entries, ohneEintrag } = q.data; const editableDay = isWithinGraceFE(current); return (

Historie

Was hat das Team an einem Tag gemacht — Reflexion & ToDos.

{formatDateLong(current)} setDate(e.target.value || undefined)} className="ml-2 rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1.5 text-sm" />
{entries.length === 0 ? (

Keine Einträge an diesem Tag.

) : (
{entries.map((p) => ( navigate(`/reflexion?date=${current}`)} /> ))}
)} {ohneEintrag.length > 0 && (

Ohne Eintrag an diesem Tag: {ohneEintrag.join(', ')}

)}
); } function PersonCard({ person: p, canEdit, onEdit, }: { person: HistoryPerson; canEdit: boolean; onEdit: () => void; }) { const ampel = p.ampel ? AMPEL_META[p.ampel] : null; return (

{p.name}

{ampel && ( {ampel.label} )} {p.trend && ( {TREND_LABEL[p.trend] ?? p.trend} )} {p.status === 'begun' && ( nicht reflektiert )} {canEdit && ( )}
{p.todos.length > 0 && (
    {p.todos.map((t) => (
  • {t.title} {t.unplanned && ( ungeplant )} {t.dropReason && ( {t.dropReason} )}
  • ))}
)} {p.reflectionText && (

{p.reflectionText}

)} {p.url && ( {p.url} )} {p.todos.length === 0 && !p.reflectionText && !p.url && (

Keine Details.

)}
); }