import { useState } from 'react'; import { useParams, Link, useNavigate } from 'react-router'; import { ArrowLeft, Pencil, Plus, Trash2, AlertTriangle, Check } from 'lucide-react'; 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 { Modal } from '../components/ui/Modal'; import { useConfirm } from '../components/ui/ConfirmProvider'; import { useCurrentUser } from '../hooks/useCurrentUser'; import { voice } from '../lib/voice'; import { formatDurationCompact } from '../lib/format-duration'; import { toast } from 'sonner'; import { clsx } from 'clsx'; import { LEAD_STATUS_META, type LeadStatus } from '../lib/lead-meta'; import { ProjectLogo, LogoUpload } from '../components/project/ProjectLogo'; import { MODUS_META, MODI, LEVEL_META, LEVELS, RISK_STATUS_LABEL, RISK_STATUSES, RISK_STRATEGIE_LABEL, RISK_STRATEGIEN, HALTUNG_META, HALTUNGEN, PHASE_META, PHASES, ZIELDREIECK_LABEL, ZIELDREIECK_FLEX, CHANGE_ENTSCHEIDUNG_META, CHANGE_ENTSCHEIDUNGEN, stakeholderStrategie, dateWarnings, type ProjectModus, type Level, type RiskStatus, type RiskStrategie, type Haltung, type ProjectPhase, type ZieldreieckFlex, type ChangeEntscheidung, } from '../lib/project-meta'; type Risk = inferRouterOutputs['risk']['forProject'][number]; type Stakeholder = inferRouterOutputs['stakeholder']['forProject'][number]; type Milestone = inferRouterOutputs['project']['byId']['milestones'][number]; type ChangeItem = inferRouterOutputs['change']['forProject'][number]; type ProjectDetail = inferRouterOutputs['project']['byId']['project']; const inputCls = 'w-full rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-3 py-2 text-sm'; // Datum in Berlin-Zeit als YYYY-MM-DD (nicht UTC — sonst Off-by-one abends). function formatDay(d: string | Date): string { return new Intl.DateTimeFormat('en-CA', { timeZone: 'Europe/Berlin' }).format(new Date(d)); } function countSentences(text: string): number { return text .split(/[.!?]+/) .map((s) => s.trim()) .filter(Boolean).length; } export function ProjektRoute() { const { id = '' } = useParams<{ id: string }>(); const me = useCurrentUser(); const navigate = useNavigate(); const q = trpc.project.byId.useQuery({ id }); const [abschlussOpen, setAbschlussOpen] = useState(false); if (q.isPending) return ; if (q.isError || !q.data) return ( void q.refetch()} /> ); const { project: p, area: a, milestones } = q.data; const isP1 = me?.id === p.verantwortlicheUserId; const pflichtKeys: Array<{ key: string; label: string }> = [ { key: 'steckbrief_freigegeben', label: 'Steckbrief in Outline freigegeben' }, { key: 'verantwortlicher', label: 'Projektverantwortliche/r gesetzt' }, { key: 'plane_board', label: 'Plane-Board verlinkt' }, { key: 'meilensteine', label: 'Meilensteine vorhanden (≥ 2)' }, { key: 'status_aktuell', label: 'Status-Ampel aktuell (≤ 7 Werktage)' }, { key: 'retrospektive', label: 'Abschluss-Retrospektive (bei beendeten Projekten)' }, ]; function goBack() { if (window.history.length > 1) navigate(-1); else navigate(`/bereich/${a.slug}`); } return (

Dashboard {' › '} {a.name}

{p.name}

{isP1 && !p.archiviert && ( )} {p.archiviert && ( archiviert )}
{p.kind === 'kundenprojekt' ? 'Kundenprojekt' : 'Internes Projekt'} ·
{abschlussOpen && ( setAbschlussOpen(false)} /> )}

Pflicht-Minimum

    {pflichtKeys.map(({ key, label }) => { const ok = p.pflichtMinimumState[key] === true; return (
  • {label}
  • ); })}
{p.dodText && (

Definition of Done

{p.dodText}

)} {p.abschlussvermerk && (

Abschlussvermerk

{p.abschlussvermerk}

)}
); } // --- Modus (Leitfaden: jederzeit ans Team kommuniziert) --------------------- function ModusControl({ projectId, modus }: { projectId: string; modus: ProjectModus }) { const utils = trpc.useUtils(); const set = trpc.project.setModus.useMutation({ onSuccess: async () => { toast(voice.toast.saved); await utils.project.byId.invalidate({ id: projectId }); await utils.dashboard.overview.invalidate(); }, }); const meta = MODUS_META[modus]; return ( ); } // --- Ziel & Maxime + SMART-Ziel, Nicht-Ziele, Liefergegenstände, Zieldreieck - function DeadlineControl({ projectId, deadline }: { projectId: string; deadline: string | null }) { const utils = trpc.useUtils(); const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(deadline ?? ''); const update = trpc.project.update.useMutation({ onSuccess: async () => { toast(voice.toast.saved); await utils.project.byId.invalidate({ id: projectId }); setEditing(false); }, }); if (editing) { const warnings = dateWarnings(draft || undefined); return ( setDraft(e.target.value)} className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm text-[var(--color-ink)]" /> {warnings.length > 0 && ( {warnings[0]} )} ); } return ( ); } function HeaderLogo({ projectId, logoUrl, name, }: { projectId: string; logoUrl: string | null; name: string; }) { const utils = trpc.useUtils(); const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(logoUrl); const update = trpc.project.update.useMutation({ onSuccess: async () => { toast(voice.toast.saved); await utils.project.byId.invalidate({ id: projectId }); setEditing(false); }, }); if (editing) { return (
); } return ( ); } function ZielSection({ projectId, project: p }: { projectId: string; project: ProjectDetail }) { const utils = trpc.useUtils(); const [editing, setEditing] = useState(false); const [maxime, setMaxime] = useState(p.maxime ?? ''); const [ziel, setZiel] = useState(p.ziel ?? ''); const [desc, setDesc] = useState(p.description ?? ''); const [nichtZiele, setNichtZiele] = useState(p.nichtZiele ?? ''); const [liefer, setLiefer] = useState(p.liefergegenstaende ?? ''); const [flex, setFlex] = useState( (p.zieldreieckFlex as ZieldreieckFlex) ?? '', ); const update = trpc.project.update.useMutation({ onSuccess: async () => { toast(voice.toast.saved); await utils.project.byId.invalidate({ id: projectId }); setEditing(false); }, }); const sentences = countSentences(ziel || desc); const zielHint = (ziel || desc).trim() === '' ? 'Noch kein Ziel. Leitfaden: SMART formulieren — spezifisch, messbar, akzeptiert, realistisch, terminiert.' : sentences > 4 ? `${sentences} Sätze — kürzer ist schärfer (3-4 Sätze reichen).` : null; function startEdit() { setMaxime(p.maxime ?? ''); setZiel(p.ziel ?? ''); setDesc(p.description ?? ''); setNichtZiele(p.nichtZiele ?? ''); setLiefer(p.liefergegenstaende ?? ''); setFlex((p.zieldreieckFlex as ZieldreieckFlex) ?? ''); setEditing(true); } function save() { update.mutate({ projectId, maxime: maxime.trim() || null, ziel: ziel.trim() || null, description: desc.trim() || null, nichtZiele: nichtZiele.trim() || null, liefergegenstaende: liefer.trim() || null, zieldreieckFlex: flex === '' ? null : flex, }); } return (

Ziel & Definition

{!editing && ( )}
{editing ? (