Files
everythingbutwork/apps/web/src/routes/projekt.tsx
T
Raffael SheikhandClaude Opus 4.8 7dd1f2fb20 Feature: Zeit-pro-Projekt-Auswertung im Projekt-Detail
time_entry erfasst bezugKind='project'+bezugId, aber niemand sah je, wie viel
Zeit ein Projekt frisst. Neue Query time.byProject (Gesamtsumme + pro Person);
neue "Getrackte Zeit"-Sektion im Projekt-Detail (blendet sich aus, wenn nichts
getrackt wurde).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 12:15:05 +02:00

2501 lines
86 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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<AppRouter>['risk']['forProject'][number];
type Stakeholder = inferRouterOutputs<AppRouter>['stakeholder']['forProject'][number];
type Milestone = inferRouterOutputs<AppRouter>['project']['byId']['milestones'][number];
type ChangeItem = inferRouterOutputs<AppRouter>['change']['forProject'][number];
type ProjectDetail = inferRouterOutputs<AppRouter>['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 <SkeletonCard lines={6} />;
if (q.isError || !q.data)
return (
<ErrorState message="Projekt konnte nicht geladen werden." onRetry={() => 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 (
<div className="space-y-6">
<header>
<div className="flex items-center gap-3">
<button
type="button"
onClick={goBack}
aria-label="Zurück"
className="inline-flex h-8 w-8 items-center justify-center rounded-[var(--radius-md)] border border-[var(--color-border)] text-[var(--color-ink-muted)] hover:border-[var(--color-ink)] hover:text-[var(--color-ink)]"
>
<ArrowLeft size={16} />
</button>
<p className="text-sm text-[var(--color-ink-muted)]">
<Link to="/dashboard" className="hover:underline">
Dashboard
</Link>
{' › '}
<Link to={`/bereich/${a.slug}`} className="hover:underline">
{a.name}
</Link>
</p>
</div>
<div className="mt-2 flex items-start justify-between gap-4">
<div className="flex items-center gap-3">
<HeaderLogo projectId={p.id} logoUrl={p.logoUrl} name={p.name} />
<h1 className="text-3xl font-bold">{p.name}</h1>
</div>
{isP1 && !p.archiviert && (
<Button variant="secondary" onClick={() => setAbschlussOpen(true)}>
Projekt abschließen
</Button>
)}
{p.archiviert && (
<span className="rounded-full bg-black/5 px-2.5 py-1 text-xs">archiviert</span>
)}
</div>
<div className="flex flex-wrap items-center gap-2 text-[var(--color-ink-muted)]">
<span>{p.kind === 'kundenprojekt' ? 'Kundenprojekt' : 'Internes Projekt'}</span>
<span>·</span>
<DeadlineControl projectId={p.id} deadline={p.deadline} />
</div>
<div className="mt-3">
<ModusControl projectId={p.id} modus={p.modus as ProjectModus} />
</div>
</header>
{abschlussOpen && (
<AbschlussDialog
projectId={p.id}
abschlussvermerk={p.abschlussvermerk}
onClose={() => setAbschlussOpen(false)}
/>
)}
<PhaseSection projectId={p.id} phase={p.phase as ProjectPhase} />
<StatusSection projectId={p.id} ampel={p.statusCache} trend={p.trendCache} />
<ZielSection projectId={p.id} project={p} />
<section className="grid grid-cols-1 gap-4 md:grid-cols-2">
<VerlinkungenSection projectId={p.id} project={p} />
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Pflicht-Minimum</h2>
</Card.Header>
<Card.Body>
<ul className="space-y-2 text-sm">
{pflichtKeys.map(({ key, label }) => {
const ok = p.pflichtMinimumState[key] === true;
return (
<li key={key} className="flex items-center gap-2">
<span
className={clsx(
'inline-block h-2.5 w-2.5 rounded-full',
ok ? 'bg-[var(--color-ampel-green-fg)]' : 'bg-[var(--color-border-strong)]',
)}
/>
<span className={ok ? '' : 'text-[var(--color-ink-muted)]'}>{label}</span>
</li>
);
})}
</ul>
</Card.Body>
</Card.Root>
</section>
<StakeholdersSection projectId={p.id} />
<LeadsSection projectId={p.id} />
<RisksSection projectId={p.id} />
<ChangeLogSection projectId={p.id} />
<MilestonesSection projectId={p.id} milestones={milestones} deadline={p.deadline} />
<ZeitSection projectId={p.id} />
{p.dodText && (
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Definition of Done</h2>
</Card.Header>
<Card.Body>
<p className="whitespace-pre-wrap text-sm">{p.dodText}</p>
</Card.Body>
</Card.Root>
)}
{p.abschlussvermerk && (
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Abschlussvermerk</h2>
</Card.Header>
<Card.Body>
<p className="whitespace-pre-wrap text-sm">{p.abschlussvermerk}</p>
</Card.Body>
</Card.Root>
)}
</div>
);
}
// --- 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 (
<label className="flex flex-wrap items-center gap-2 text-sm">
<span className="text-[var(--color-ink-muted)]">Modus</span>
<span className={clsx('rounded-full px-2.5 py-0.5 text-xs font-medium', meta.badge)}>
{meta.label}
</span>
<select
value={modus}
onChange={(e) => set.mutate({ projectId, modus: e.target.value as ProjectModus })}
className="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-white px-2 py-1 text-sm"
>
{MODI.map((m) => (
<option key={m} value={m}>
{MODUS_META[m].label}
</option>
))}
</select>
<span className="text-xs text-[var(--color-ink-faint)]">{meta.hint}</span>
</label>
);
}
// --- 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 (
<span className="inline-flex flex-wrap items-center gap-2">
<input
type="date"
value={draft}
onChange={(e) => 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)]"
/>
<Button
type="button"
size="sm"
disabled={update.isPending}
onClick={() => update.mutate({ projectId, deadline: draft || null })}
>
Speichern
</Button>
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
{warnings.length > 0 && (
<span className="flex items-center gap-1 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={12} /> {warnings[0]}
</span>
)}
</span>
);
}
return (
<button
type="button"
onClick={() => {
setDraft(deadline ?? '');
setEditing(true);
}}
className="inline-flex items-center gap-1 hover:text-[var(--color-ink)] hover:underline"
title="Deadline bearbeiten"
>
{deadline ? `Deadline ${deadline}` : 'kein Deadline'}
<Pencil size={12} />
</button>
);
}
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<string | null>(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 (
<div className="rounded-[var(--radius-md)] border border-[var(--color-border)] p-3">
<LogoUpload value={draft} name={name} onChange={setDraft} />
<div className="mt-2 flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button
type="button"
size="sm"
disabled={update.isPending}
onClick={() => update.mutate({ projectId, logoUrl: draft })}
>
Speichern
</Button>
</div>
</div>
);
}
return (
<button
type="button"
onClick={() => {
setDraft(logoUrl);
setEditing(true);
}}
className="group relative shrink-0"
title="Logo ändern"
>
<ProjectLogo url={logoUrl} name={name} size={56} />
<span className="absolute inset-0 flex items-center justify-center rounded-[var(--radius-md)] bg-black/40 text-white opacity-0 transition-opacity group-hover:opacity-100">
<Pencil size={16} />
</span>
</button>
);
}
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<ZieldreieckFlex | ''>(
(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 (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Ziel & Definition</h2>
{!editing && (
<button
type="button"
onClick={startEdit}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Pencil size={13} /> Bearbeiten
</button>
)}
</Card.Header>
<Card.Body className="space-y-3">
{editing ? (
<div className="space-y-3">
<label className="block">
<span className="text-sm font-medium">Maxime (roter Faden, ein Satz)</span>
<input
value={maxime}
onChange={(e) => setMaxime(e.target.value)}
maxLength={280}
placeholder="z. B. „So schnell wie möglich, mit bestehenden Ressourcen.“"
className={clsx(inputCls, 'mt-1')}
/>
</label>
<label className="block">
<span className="text-sm font-medium">Ziel (SMART)</span>
<textarea
value={ziel}
onChange={(e) => setZiel(e.target.value)}
rows={2}
maxLength={1000}
placeholder="z. B. „Ladezeit der Startseite bis 31.07. unter 1 Sekunde, abgenommen vom Kunden.“"
className={clsx(inputCls, 'mt-1')}
/>
</label>
{zielHint && (
<p className="flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={13} className="mt-0.5 shrink-0" />
{zielHint}
</p>
)}
<label className="block">
<span className="text-sm font-medium">Nicht-Ziele (Scope-Schutz)</span>
<textarea
value={nichtZiele}
onChange={(e) => setNichtZiele(e.target.value)}
rows={2}
maxLength={2000}
placeholder="Was gehört ausdrücklich NICHT dazu?"
className={clsx(inputCls, 'mt-1')}
/>
</label>
<label className="block">
<span className="text-sm font-medium">Liefergegenstände</span>
<textarea
value={liefer}
onChange={(e) => setLiefer(e.target.value)}
rows={2}
maxLength={2000}
placeholder="Was liegt am Ende konkret vor?"
className={clsx(inputCls, 'mt-1')}
/>
</label>
<label className="block">
<span className="text-sm font-medium">Hintergrund / Beschreibung</span>
<textarea
value={desc}
onChange={(e) => setDesc(e.target.value)}
rows={3}
maxLength={2000}
className={clsx(inputCls, 'mt-1')}
/>
</label>
<label className="block">
<span className="text-sm font-medium">
Zieldreieck: Wenn es eng wird, gibt zuerst nach…
</span>
<select
value={flex}
onChange={(e) => setFlex(e.target.value as ZieldreieckFlex | '')}
className={clsx(inputCls, 'mt-1')}
>
<option value="">— nicht festgelegt —</option>
{ZIELDREIECK_FLEX.map((z) => (
<option key={z} value={z}>
{ZIELDREIECK_LABEL[z]}
</option>
))}
</select>
</label>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button type="button" size="sm" onClick={save} disabled={update.isPending}>
Speichern
</Button>
</div>
</div>
) : (
<div className="space-y-3 text-sm">
<ZielRow label="Maxime" value={p.maxime} italic />
<ZielRow label="Ziel (SMART)" value={p.ziel} />
<ZielRow label="Nicht-Ziele" value={p.nichtZiele} />
<ZielRow label="Liefergegenstände" value={p.liefergegenstaende} />
<ZielRow label="Hintergrund" value={p.description} />
<Zieldreieck flex={p.zieldreieckFlex as ZieldreieckFlex | null} />
</div>
)}
</Card.Body>
</Card.Root>
);
}
function ZielRow({
label,
value,
italic,
}: {
label: string;
value: string | null;
italic?: boolean;
}) {
return (
<div>
<p className="text-xs font-medium text-[var(--color-ink-muted)]">{label}</p>
{value ? (
<p className={clsx('mt-0.5 whitespace-pre-wrap', italic && 'italic')}>
{italic ? `„${value}“` : value}
</p>
) : (
<p className="mt-0.5 text-[var(--color-ink-faint)]">—</p>
)}
</div>
);
}
function Zieldreieck({ flex }: { flex: ZieldreieckFlex | null }) {
const corners: ZieldreieckFlex[] = ['leistung', 'zeit', 'aufwand'];
return (
<div>
<p className="text-xs font-medium text-[var(--color-ink-muted)]">Zieldreieck</p>
<div className="mt-1 flex flex-wrap gap-2">
{corners.map((c) => {
const gibtNach = flex === c;
return (
<span
key={c}
className={clsx(
'rounded-full px-2.5 py-0.5 text-xs',
gibtNach
? 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]'
: 'bg-black/5 text-[var(--color-ink-muted)]',
)}
>
{ZIELDREIECK_LABEL[c]}
{gibtNach && ' · gibt nach'}
</span>
);
})}
{!flex && (
<span className="text-xs text-[var(--color-ink-faint)]">Priorität nicht festgelegt</span>
)}
</div>
</div>
);
}
// --- Getrackte Zeit ---------------------------------------------------------
function ZeitSection({ projectId }: { projectId: string }) {
const q = trpc.time.byProject.useQuery({ projectId });
if (!q.data || q.data.totalSeconds === 0) return null;
return (
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Getrackte Zeit</h2>
</Card.Header>
<Card.Body className="space-y-2">
<p className="text-sm">
Gesamt:{' '}
<span className="font-mono font-semibold">
{formatDurationCompact(q.data.totalSeconds)}
</span>
</p>
<ul className="space-y-1 text-sm">
{q.data.perUser.map((u) => (
<li key={u.userId} className="flex justify-between gap-2">
<span className="truncate">{u.name}</span>
<span className="shrink-0 font-mono text-[var(--color-ink-muted)]">
{formatDurationCompact(u.seconds)}
</span>
</li>
))}
</ul>
</Card.Body>
</Card.Root>
);
}
// --- Phasen-Stepper + Gate-Review -------------------------------------------
function PhaseSection({ projectId, phase }: { projectId: string; phase: ProjectPhase }) {
const utils = trpc.useUtils();
const gatesQ = trpc.project.phaseGates.useQuery({ projectId });
const [gateOpen, setGateOpen] = useState(false);
const setPhase = trpc.project.setPhase.useMutation({
onSuccess: async () => {
await utils.project.byId.invalidate({ id: projectId });
await utils.dashboard.overview.invalidate();
},
});
const currentIdx = PHASES.indexOf(phase);
const gates = gatesQ.data ?? [];
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Phase</h2>
{phase !== 'abschluss' && (
<button
type="button"
onClick={() => setGateOpen(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Check size={13} /> Gate-Review & weiter
</button>
)}
</Card.Header>
<Card.Body className="space-y-3">
<ol className="flex flex-wrap gap-1">
{PHASES.map((ph, i) => {
const done = i < currentIdx;
const current = i === currentIdx;
return (
<li key={ph}>
<button
type="button"
onClick={() => setPhase.mutate({ projectId, phase: ph })}
title={PHASE_META[ph].gateZiel}
className={clsx(
'inline-flex items-center gap-1 rounded-[var(--radius-md)] border px-3 py-1.5 text-sm',
current
? 'border-[var(--color-ink)] bg-[var(--color-ink)] text-[var(--color-brand-fg)]'
: done
? 'border-[var(--color-ampel-green-fg)] text-[var(--color-ampel-green-fg)]'
: 'border-[var(--color-border)] text-[var(--color-ink-muted)] hover:border-[var(--color-border-strong)]',
)}
>
{done && <Check size={12} />}
{i + 1}. {PHASE_META[ph].label}
</button>
</li>
);
})}
</ol>
<p className="text-xs text-[var(--color-ink-muted)]">
Gate-Ziel: {PHASE_META[phase].gateZiel}
</p>
{gates.length > 0 && (
<details>
<summary className="cursor-pointer text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]">
{gates.length} Gate-Review{gates.length === 1 ? '' : 's'}
</summary>
<ul className="mt-2 space-y-1.5 text-sm">
{gates.map((g) => (
<li key={g.id} className="flex items-start gap-2">
<span
className={clsx(
'mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-[10px] text-white',
g.ergebnisErreicht
? 'bg-[var(--color-ampel-green-fg)]'
: 'bg-[var(--color-ampel-red-fg)]',
)}
>
{g.ergebnisErreicht ? '✓' : '✗'}
</span>
<span>
<span className="font-medium">{PHASE_META[g.phase as ProjectPhase].label}</span>{' '}
<span className="text-xs text-[var(--color-ink-faint)]">
{formatDay(g.reviewedAt)}
</span>
{g.notiz && (
<span className="block text-xs text-[var(--color-ink-muted)]">{g.notiz}</span>
)}
</span>
</li>
))}
</ul>
</details>
)}
</Card.Body>
{gateOpen && (
<GateDialog projectId={projectId} phase={phase} onClose={() => setGateOpen(false)} />
)}
</Card.Root>
);
}
function GateDialog({
projectId,
phase,
onClose,
}: {
projectId: string;
phase: ProjectPhase;
onClose: () => void;
}) {
const utils = trpc.useUtils();
const [erreicht, setErreicht] = useState(true);
const [notiz, setNotiz] = useState('');
const [advance, setAdvance] = useState(true);
const add = trpc.project.addPhaseGate.useMutation({
onSuccess: async () => {
toast(voice.toast.saved);
await utils.project.byId.invalidate({ id: projectId });
await utils.project.phaseGates.invalidate({ projectId });
await utils.dashboard.overview.invalidate();
onClose();
},
});
return (
<Modal open onClose={onClose} title={`Gate-Review: ${PHASE_META[phase].label}`}>
<p className="mt-1 text-sm text-[var(--color-ink-muted)]">
Ziel: {PHASE_META[phase].gateZiel}
</p>
<form
className="mt-4 space-y-3"
onSubmit={(e) => {
e.preventDefault();
add.mutate({
projectId,
phase,
ergebnisErreicht: erreicht,
notiz: notiz.trim() || undefined,
advance,
});
}}
>
<label className="flex items-center gap-2 text-sm">
<input
type="checkbox"
checked={erreicht}
onChange={(e) => setErreicht(e.target.checked)}
/>
Ergebnis erreicht
</label>
<textarea
value={notiz}
onChange={(e) => setNotiz(e.target.value)}
rows={3}
placeholder="Rückblick / Maßnahmen (bei Gelb/Rot)"
className={inputCls}
/>
<label className="flex items-center gap-2 text-sm">
<input type="checkbox" checked={advance} onChange={(e) => setAdvance(e.target.checked)} />
Folgephase jetzt freigeben
</label>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" onClick={onClose}>
Abbrechen
</Button>
<Button type="submit" disabled={add.isPending}>
Speichern
</Button>
</div>
</form>
</Modal>
);
}
// --- Projekt-Statusbericht (Ampel + Trend + 2-3 Sätze) ----------------------
function StatusSection({
projectId,
ampel,
trend,
}: {
projectId: string;
ampel: 'green' | 'amber' | 'red' | null;
trend: 'besser' | 'gleich' | 'schlechter' | null;
}) {
const utils = trpc.useUtils();
const histQ = trpc.project.statusHistory.useQuery({ projectId });
const [open, setOpen] = useState(false);
const [neuAmpel, setNeuAmpel] = useState<'green' | 'amber' | 'red'>(ampel ?? 'green');
const [neuTrend, setNeuTrend] = useState<'besser' | 'gleich' | 'schlechter' | ''>(trend ?? '');
const [text, setText] = useState('');
const [extern, setExtern] = useState(false);
const add = trpc.project.addStatus.useMutation({
onSuccess: async () => {
toast(voice.toast.saved);
await utils.project.byId.invalidate({ id: projectId });
await utils.project.statusHistory.invalidate({ projectId });
await utils.dashboard.overview.invalidate();
setText('');
setOpen(false);
},
});
const history = histQ.data ?? [];
const latest = history[0];
const ampelLabel = { green: 'Im Plan', amber: 'Gefährdet', red: 'Blockiert' };
const ampelCls = {
green: 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]',
amber: 'bg-[var(--color-ampel-amber-bg)] text-[var(--color-ampel-amber-fg)]',
red: 'bg-[var(--color-ampel-red-bg)] text-[var(--color-ampel-red-fg)]',
};
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Status</h2>
{!open && (
<button
type="button"
onClick={() => setOpen(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Status setzen
</button>
)}
</Card.Header>
<Card.Body className="space-y-3">
{open && (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
add.mutate({
projectId,
ampel: neuAmpel,
trend: neuTrend === '' ? undefined : neuTrend,
text: text.trim() || undefined,
externSichtbar: extern,
});
}}
>
<div className="grid grid-cols-2 gap-2">
<label className="text-xs text-[var(--color-ink-muted)]">
Ampel
<select
value={neuAmpel}
onChange={(e) => setNeuAmpel(e.target.value as 'green' | 'amber' | 'red')}
className={inputCls}
>
<option value="green">Im Plan</option>
<option value="amber">Gefährdet</option>
<option value="red">Blockiert</option>
</select>
</label>
<label className="text-xs text-[var(--color-ink-muted)]">
Trend
<select
value={neuTrend}
onChange={(e) =>
setNeuTrend(e.target.value as 'besser' | 'gleich' | 'schlechter' | '')
}
className={inputCls}
>
<option value="">—</option>
<option value="besser">Besser</option>
<option value="gleich">Gleich</option>
<option value="schlechter">Schlechter</option>
</select>
</label>
</div>
<textarea
value={text}
onChange={(e) => setText(e.target.value)}
rows={2}
maxLength={1000}
placeholder="2-3 Sätze Erläuterung"
className={inputCls}
/>
<label className="flex items-center gap-2 text-sm">
<input
type="checkbox"
checked={extern}
onChange={(e) => setExtern(e.target.checked)}
/>
Nach außen kommunizierbar (Kundenprojekt)
</label>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setOpen(false)}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={add.isPending}>
Speichern
</Button>
</div>
</form>
)}
{latest ? (
<div className="text-sm">
<div className="flex items-center gap-2">
<span
className={clsx(
'rounded-full px-2 py-0.5 text-xs font-medium',
ampelCls[latest.ampel],
)}
>
{ampelLabel[latest.ampel]}
</span>
{latest.trend && (
<span className="text-xs text-[var(--color-ink-muted)]">Trend: {latest.trend}</span>
)}
{latest.externSichtbar && (
<span className="rounded-full bg-black/5 px-2 py-0.5 text-[10px] text-[var(--color-ink-muted)]">
extern
</span>
)}
<span className="ml-auto text-xs text-[var(--color-ink-faint)]">
{formatDay(latest.createdAt)}
{latest.authorName ? ` · ${latest.authorName}` : ''}
</span>
</div>
{latest.text && <p className="mt-1.5 whitespace-pre-wrap">{latest.text}</p>}
</div>
) : ampel ? (
// Verlauf-Query noch nicht da / fehlgeschlagen → zumindest den aktuellen
// Status aus dem statusCache zeigen, statt fälschlich „kein Status".
<div className="flex items-center gap-2 text-sm">
<span className={clsx('rounded-full px-2 py-0.5 text-xs font-medium', ampelCls[ampel])}>
{ampelLabel[ampel]}
</span>
{trend && <span className="text-xs text-[var(--color-ink-muted)]">Trend: {trend}</span>}
</div>
) : histQ.isPending ? (
<p className="text-sm text-[var(--color-ink-faint)]">Status wird geladen…</p>
) : histQ.isError ? (
<p className="text-sm text-[var(--color-ink-muted)]">
Status konnte nicht geladen werden.
</p>
) : (
<p className="text-sm text-[var(--color-ink-muted)]">Noch kein Status gesetzt.</p>
)}
{history.length > 1 && (
<details>
<summary className="cursor-pointer text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]">
Verlauf ({history.length - 1} ältere)
</summary>
<ul className="mt-2 space-y-2 text-sm">
{history.slice(1).map((s) => (
<li key={s.id} className="flex items-start gap-2">
<span
className={clsx(
'mt-0.5 inline-block h-2.5 w-2.5 shrink-0 rounded-full',
{
green: 'bg-[var(--color-ampel-green-fg)]',
amber: 'bg-[var(--color-ampel-amber-fg)]',
red: 'bg-[var(--color-ampel-red-fg)]',
}[s.ampel],
)}
/>
<span>
<span className="text-xs text-[var(--color-ink-faint)]">
{formatDay(s.createdAt)}
</span>
{s.text && <span className="block">{s.text}</span>}
</span>
</li>
))}
</ul>
</details>
)}
</Card.Body>
</Card.Root>
);
}
// --- Änderungs-Log (Scope-Creep) --------------------------------------------
function ChangeLogSection({ projectId }: { projectId: string }) {
const utils = trpc.useUtils();
const q = trpc.change.forProject.useQuery({ projectId });
const [adding, setAdding] = useState(false);
const [titel, setTitel] = useState('');
const [auswirkung, setAuswirkung] = useState('');
const add = trpc.change.create.useMutation({
onSuccess: async () => {
await utils.change.forProject.invalidate({ projectId });
setTitel('');
setAuswirkung('');
setAdding(false);
},
});
const list = q.data ?? [];
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Änderungs-Log</h2>
{!adding && (
<button
type="button"
onClick={() => setAdding(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Änderung
</button>
)}
</Card.Header>
<Card.Body className="space-y-2">
{adding && (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!titel.trim()) return;
add.mutate({
projectId,
titel: titel.trim(),
auswirkung: auswirkung.trim() || undefined,
});
}}
>
<input
value={titel}
onChange={(e) => setTitel(e.target.value)}
placeholder="Was ändert sich?"
className={inputCls}
/>
<input
value={auswirkung}
onChange={(e) => setAuswirkung(e.target.value)}
placeholder="Auswirkung aufs Zieldreieck (Leistung/Zeit/Aufwand)"
className={inputCls}
/>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setAdding(false)}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={add.isPending}>
Hinzufügen
</Button>
</div>
</form>
)}
{list.length === 0 && !adding ? (
<p className="text-sm text-[var(--color-ink-muted)]">
Keine Änderungen. Leitfaden: keine stille Erweiterung des Umfangs — jede Änderung
bewusst entscheiden.
</p>
) : (
<div className="space-y-2">
{list.map((c) => (
<ChangeRow key={c.id} projectId={projectId} change={c} />
))}
</div>
)}
</Card.Body>
</Card.Root>
);
}
function ChangeRow({ projectId, change: c }: { projectId: string; change: ChangeItem }) {
const utils = trpc.useUtils();
const invalidate = () => utils.change.forProject.invalidate({ projectId });
const update = trpc.change.update.useMutation({ onSuccess: invalidate });
const remove = trpc.change.remove.useMutation({ onSuccess: invalidate });
const confirm = useConfirm();
const meta = CHANGE_ENTSCHEIDUNG_META[c.entscheidung as ChangeEntscheidung];
return (
<div className="rounded-[var(--radius-md)] border border-[var(--color-border)] p-3 text-sm">
<div className="flex items-start justify-between gap-2">
<div className="flex-1">
<p className="font-medium">{c.titel}</p>
{c.auswirkung && (
<p className="mt-0.5 text-xs text-[var(--color-ink-muted)]">
Auswirkung: {c.auswirkung}
</p>
)}
<p className="mt-1 text-xs text-[var(--color-ink-faint)]">
{formatDay(c.createdAt)}
{c.authorName ? ` · ${c.authorName}` : ''}
</p>
{c.entscheidung === 'genehmigt' && (
<p className="mt-1 flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={12} className="mt-0.5 shrink-0" />
Genehmigt — Baseline/Steckbrief in Outline nachziehen.
</p>
)}
</div>
<div className="flex shrink-0 items-center gap-1">
<select
value={c.entscheidung}
onChange={(e) =>
update.mutate({ id: c.id, entscheidung: e.target.value as ChangeEntscheidung })
}
className={clsx('rounded-full border-0 px-2 py-0.5 text-xs font-medium', meta.badge)}
>
{CHANGE_ENTSCHEIDUNGEN.map((en) => (
<option key={en} value={en}>
{CHANGE_ENTSCHEIDUNG_META[en].label}
</option>
))}
</select>
<button
type="button"
onClick={async () => {
if (
await confirm({
title: 'Änderung löschen?',
destructive: true,
confirmLabel: 'Löschen',
})
)
remove.mutate({ id: c.id });
}}
aria-label="Entfernen"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
>
<Trash2 size={14} />
</button>
</div>
</div>
</div>
);
}
// --- Stakeholder-Analyse + Macht/Interesse-Matrix ---------------------------
function StakeholdersSection({ projectId }: { projectId: string }) {
const q = trpc.stakeholder.forProject.useQuery({ projectId });
const [adding, setAdding] = useState(false);
const list = q.data ?? [];
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Stakeholder</h2>
{!adding && (
<button
type="button"
onClick={() => setAdding(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Stakeholder
</button>
)}
</Card.Header>
<Card.Body className="space-y-4">
{list.length > 0 && <StakeholderMatrix list={list} />}
{list.length === 0 && !adding && (
<p className="text-sm text-[var(--color-ink-muted)]">
Noch keine Stakeholder erfasst. Alle, die auch nur entfernt mit dem Projekt zu tun
haben, haben Interessen, Macht und Einfluss.
</p>
)}
<div className="space-y-2">
{list.map((s) => (
<StakeholderRow key={s.id} projectId={projectId} stakeholder={s} />
))}
</div>
{adding && <AddStakeholderForm projectId={projectId} onDone={() => setAdding(false)} />}
</Card.Body>
</Card.Root>
);
}
function StakeholderMatrix({ list }: { list: Stakeholder[] }) {
// Zeilen = Einfluss (hoch oben), Spalten = Interesse (hoch rechts).
const rows: Level[] = ['hoch', 'mittel', 'niedrig'];
const cols: Level[] = ['niedrig', 'mittel', 'hoch'];
return (
<div className="overflow-x-auto">
<div className="min-w-[420px]">
<div className="grid grid-cols-[auto_repeat(3,1fr)] gap-1 text-xs">
<div />
{cols.map((c) => (
<div
key={c}
className="px-1 pb-1 text-center font-medium text-[var(--color-ink-muted)]"
>
Interesse {LEVEL_META[c].label.toLowerCase()}
</div>
))}
{rows.map((r) => (
<FragmentRow key={r} r={r} cols={cols} list={list} />
))}
</div>
<p className="mt-1 text-xs text-[var(--color-ink-faint)]">
Zeilen: Einfluss (oben = hoch) · Spalten: Interesse (rechts = hoch)
</p>
</div>
</div>
);
}
function FragmentRow({ r, cols, list }: { r: Level; cols: Level[]; list: Stakeholder[] }) {
return (
<>
<div className="flex items-center pr-1 text-right font-medium text-[var(--color-ink-muted)]">
Einfluss {LEVEL_META[r].label.toLowerCase()}
</div>
{cols.map((c) => {
const cell = list.filter((s) => s.einfluss === r && s.interesse === c);
return (
<div
key={c}
className="min-h-[3.5rem] rounded-[var(--radius-md)] border border-[var(--color-border)] p-1.5"
title={stakeholderStrategie(r, c)}
>
<p className="mb-1 text-[10px] uppercase tracking-wide text-[var(--color-ink-faint)]">
{stakeholderStrategie(r, c)}
</p>
<div className="flex flex-wrap gap-1">
{cell.map((s) => (
<span
key={s.id}
className="inline-flex items-center gap-1 rounded-full bg-black/5 px-1.5 py-0.5 text-[11px]"
>
<span
className={clsx(
'h-1.5 w-1.5 rounded-full',
HALTUNG_META[s.haltung as Haltung].dot,
)}
/>
{s.name}
</span>
))}
</div>
</div>
);
})}
</>
);
}
function StakeholderRow({
projectId,
stakeholder: s,
}: {
projectId: string;
stakeholder: Stakeholder;
}) {
const utils = trpc.useUtils();
const [editing, setEditing] = useState(false);
const invalidate = () => utils.stakeholder.forProject.invalidate({ projectId });
const update = trpc.stakeholder.update.useMutation({
onSuccess: async () => {
await invalidate();
setEditing(false);
},
});
const remove = trpc.stakeholder.remove.useMutation({ onSuccess: invalidate });
const confirm = useConfirm();
const [name, setName] = useState(s.name);
const [rolle, setRolle] = useState(s.rolle ?? '');
const [interesse, setInteresse] = useState<Level>(s.interesse as Level);
const [einfluss, setEinfluss] = useState<Level>(s.einfluss as Level);
const [haltung, setHaltung] = useState<Haltung>(s.haltung as Haltung);
const [beduerfnis, setBeduerfnis] = useState(s.beduerfnis ?? '');
const [notiz, setNotiz] = useState(s.notiz ?? '');
if (editing) {
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!name.trim()) return;
update.mutate({
id: s.id,
name: name.trim(),
rolle: rolle.trim() || null,
interesse,
einfluss,
haltung,
beduerfnis: beduerfnis.trim() || null,
notiz: notiz.trim() || null,
});
}}
>
<div className="grid grid-cols-2 gap-2">
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Name *"
className={inputCls}
/>
<input
value={rolle}
onChange={(e) => setRolle(e.target.value)}
placeholder="Rolle"
className={inputCls}
/>
<LevelSelect label="Interesse" value={interesse} onChange={setInteresse} />
<LevelSelect label="Einfluss" value={einfluss} onChange={setEinfluss} />
<label className="text-xs text-[var(--color-ink-muted)]">
Haltung
<select
value={haltung}
onChange={(e) => setHaltung(e.target.value as Haltung)}
className={inputCls}
>
{HALTUNGEN.map((h) => (
<option key={h} value={h}>
{HALTUNG_META[h].label}
</option>
))}
</select>
</label>
</div>
<input
value={beduerfnis}
onChange={(e) => setBeduerfnis(e.target.value)}
placeholder="Bedürfnis / was braucht die Person?"
className={inputCls}
/>
<input
value={notiz}
onChange={(e) => setNotiz(e.target.value)}
placeholder="Notiz"
className={inputCls}
/>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={update.isPending}>
Speichern
</Button>
</div>
</form>
);
}
return (
<div className="flex items-start justify-between gap-2 rounded-[var(--radius-md)] border border-[var(--color-border)] p-3 text-sm">
<div>
<p className="flex items-center gap-2 font-medium">
<span className={clsx('h-2 w-2 rounded-full', HALTUNG_META[s.haltung as Haltung].dot)} />
{s.name}
{s.rolle && (
<span className="font-normal text-[var(--color-ink-muted)]">· {s.rolle}</span>
)}
</p>
<div className="mt-1 flex flex-wrap gap-1 text-xs">
<span
className={clsx('rounded-full px-2 py-0.5', LEVEL_META[s.interesse as Level].badge)}
>
Interesse {LEVEL_META[s.interesse as Level].label}
</span>
<span className={clsx('rounded-full px-2 py-0.5', LEVEL_META[s.einfluss as Level].badge)}>
Einfluss {LEVEL_META[s.einfluss as Level].label}
</span>
</div>
{s.beduerfnis && (
<p className="mt-1 text-xs text-[var(--color-ink-muted)]">Braucht: {s.beduerfnis}</p>
)}
{s.notiz && <p className="mt-0.5 text-xs text-[var(--color-ink-faint)]">{s.notiz}</p>}
</div>
<div className="flex shrink-0 gap-1">
<button
type="button"
onClick={() => setEditing(true)}
aria-label="Bearbeiten"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ink)]"
>
<Pencil size={14} />
</button>
<button
type="button"
onClick={async () => {
if (
await confirm({
title: 'Stakeholder entfernen?',
destructive: true,
confirmLabel: 'Entfernen',
})
)
remove.mutate({ id: s.id });
}}
aria-label="Entfernen"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
>
<Trash2 size={14} />
</button>
</div>
</div>
);
}
function AddStakeholderForm({ projectId, onDone }: { projectId: string; onDone: () => void }) {
const utils = trpc.useUtils();
const [name, setName] = useState('');
const [rolle, setRolle] = useState('');
const [interesse, setInteresse] = useState<Level>('mittel');
const [einfluss, setEinfluss] = useState<Level>('mittel');
const [haltung, setHaltung] = useState<Haltung>('neutral');
const [beduerfnis, setBeduerfnis] = useState('');
const add = trpc.stakeholder.create.useMutation({
onSuccess: async () => {
await utils.stakeholder.forProject.invalidate({ projectId });
onDone();
},
});
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!name.trim()) return;
add.mutate({
projectId,
name: name.trim(),
rolle: rolle.trim() || undefined,
interesse,
einfluss,
haltung,
beduerfnis: beduerfnis.trim() || undefined,
});
}}
>
<div className="grid grid-cols-2 gap-2">
<input
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Name *"
className={inputCls}
/>
<input
value={rolle}
onChange={(e) => setRolle(e.target.value)}
placeholder="Rolle"
className={inputCls}
/>
<LevelSelect label="Interesse" value={interesse} onChange={setInteresse} />
<LevelSelect label="Einfluss" value={einfluss} onChange={setEinfluss} />
<label className="text-xs text-[var(--color-ink-muted)]">
Haltung
<select
value={haltung}
onChange={(e) => setHaltung(e.target.value as Haltung)}
className={inputCls}
>
{HALTUNGEN.map((h) => (
<option key={h} value={h}>
{HALTUNG_META[h].label}
</option>
))}
</select>
</label>
</div>
<input
value={beduerfnis}
onChange={(e) => setBeduerfnis(e.target.value)}
placeholder="Bedürfnis / was braucht die Person?"
className={inputCls}
/>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={onDone}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={add.isPending}>
Hinzufügen
</Button>
</div>
</form>
);
}
function LevelSelect({
label,
value,
onChange,
}: {
label: string;
value: Level;
onChange: (l: Level) => void;
}) {
return (
<label className="text-xs text-[var(--color-ink-muted)]">
{label}
<select
value={value}
onChange={(e) => onChange(e.target.value as Level)}
className={inputCls}
>
{LEVELS.map((l) => (
<option key={l} value={l}>
{LEVEL_META[l].label}
</option>
))}
</select>
</label>
);
}
// --- Leads (Vertriebs-Sicht des Projekts) -----------------------------------
function LeadsSection({ projectId }: { projectId: string }) {
const utils = trpc.useUtils();
const q = trpc.lead.forProject.useQuery({ projectId });
const [adding, setAdding] = useState(false);
const [firma, setFirma] = useState('');
const create = trpc.lead.create.useMutation({
onSuccess: async () => {
await utils.lead.forProject.invalidate({ projectId });
await utils.lead.list.invalidate();
setFirma('');
setAdding(false);
},
});
const list = q.data ?? [];
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">
Leads
{list.length > 0 && (
<span className="text-sm font-normal text-[var(--color-ink-muted)]">
{' '}
({list.length})
</span>
)}
</h2>
<div className="flex items-center gap-3">
<Link
to="/leads"
className="text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
>
Alle Leads →
</Link>
{!adding && (
<button
type="button"
onClick={() => setAdding(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Lead
</button>
)}
</div>
</Card.Header>
<Card.Body className="space-y-2">
{list.length === 0 && !adding && (
<p className="text-sm text-[var(--color-ink-muted)]">
Noch keine Leads mit diesem Projekt verknüpft.
</p>
)}
{list.map((l) => (
<Link
key={l.id}
to={`/lead/${l.id}`}
className="flex items-center justify-between gap-2 rounded-[var(--radius-md)] border border-[var(--color-border)] p-2.5 text-sm hover:border-[var(--color-ink)]"
>
<span className="flex items-center gap-2">
<span
className={clsx(
'h-2 w-2 rounded-full',
LEAD_STATUS_META[l.status as LeadStatus].dot,
)}
/>
<span className="font-medium">{l.firma}</span>
{l.branche && (
<span className="text-xs text-[var(--color-ink-muted)]">{l.branche}</span>
)}
</span>
<span className="flex items-center gap-2 text-xs text-[var(--color-ink-muted)]">
<span
className={clsx(
'rounded-full px-2 py-0.5',
LEAD_STATUS_META[l.status as LeadStatus].badge,
)}
>
{LEAD_STATUS_META[l.status as LeadStatus].label}
</span>
<span className="font-mono tabular-nums">{l.score}/10</span>
</span>
</Link>
))}
{adding && (
<form
className="flex gap-2"
onSubmit={(e) => {
e.preventDefault();
if (!firma.trim()) return;
create.mutate({ firma: firma.trim(), projectId, status: 'cold', score: 0 });
}}
>
<input
value={firma}
onChange={(e) => setFirma(e.target.value)}
placeholder="Firma / Lead-Name"
className={inputCls}
/>
<Button type="submit" size="sm" disabled={create.isPending}>
Anlegen
</Button>
<Button type="button" size="sm" variant="ghost" onClick={() => setAdding(false)}>
Abbrechen
</Button>
</form>
)}
</Card.Body>
</Card.Root>
);
}
// --- Risiken & Chancen ------------------------------------------------------
function RisksSection({ projectId }: { projectId: string }) {
const q = trpc.risk.forProject.useQuery({ projectId });
const usersQ = trpc.user.list.useQuery();
const users = usersQ.data ?? [];
const userMap = new Map(users.map((u) => [u.id, u.name]));
const [adding, setAdding] = useState<'risiko' | 'chance' | null>(null);
const list = q.data ?? [];
const risiken = list.filter((r) => r.kind === 'risiko');
const chancen = list.filter((r) => r.kind === 'chance');
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Risiken & Chancen</h2>
<div className="flex gap-2">
<button
type="button"
onClick={() => setAdding('risiko')}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Risiko
</button>
<button
type="button"
onClick={() => setAdding('chance')}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Chance
</button>
</div>
</Card.Header>
<Card.Body className="space-y-4">
{adding && (
<AddRiskForm
projectId={projectId}
kind={adding}
users={users}
onDone={() => setAdding(null)}
/>
)}
<div>
<p className="mb-1 text-sm font-medium text-[var(--color-ink-muted)]">Risiken</p>
{risiken.length === 0 ? (
<p className="text-sm text-[var(--color-ink-faint)]">Keine Risiken erfasst.</p>
) : (
<div className="space-y-2">
{risiken.map((r) => (
<RiskRow
key={r.id}
projectId={projectId}
risk={r}
users={users}
userMap={userMap}
/>
))}
</div>
)}
</div>
<div>
<p className="mb-1 text-sm font-medium text-[var(--color-ink-muted)]">Chancen</p>
{chancen.length === 0 ? (
<p className="text-sm text-[var(--color-ink-faint)]">Keine Chancen erfasst.</p>
) : (
<div className="space-y-2">
{chancen.map((r) => (
<RiskRow
key={r.id}
projectId={projectId}
risk={r}
users={users}
userMap={userMap}
/>
))}
</div>
)}
</div>
</Card.Body>
</Card.Root>
);
}
function RiskRow({
projectId,
risk: r,
users,
userMap,
}: {
projectId: string;
risk: Risk;
users: Array<{ id: string; name: string }>;
userMap: Map<string, string>;
}) {
const utils = trpc.useUtils();
const [editing, setEditing] = useState(false);
const invalidate = async () => {
await utils.risk.forProject.invalidate({ projectId });
await utils.dashboard.overview.invalidate();
};
const update = trpc.risk.update.useMutation({
onSuccess: async () => {
await invalidate();
setEditing(false);
},
});
const remove = trpc.risk.remove.useMutation({ onSuccess: invalidate });
const confirm = useConfirm();
const [title, setTitle] = useState(r.title);
const [wahr, setWahr] = useState<Level>(r.wahrscheinlichkeit as Level);
const [ausw, setAusw] = useState<Level>(r.auswirkung as Level);
const [herkunft, setHerkunft] = useState(r.herkunft ?? '');
const [showstopper, setShowstopper] = useState(r.showstopper);
const [massnahme, setMassnahme] = useState(r.massnahme ?? '');
const [strategie, setStrategie] = useState(r.strategie ?? '');
const [owner, setOwner] = useState(r.ownerUserId ?? '');
const [status, setStatus] = useState<RiskStatus>(r.status as RiskStatus);
const isChance = r.kind === 'chance';
if (editing) {
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!title.trim()) return;
update.mutate({
id: r.id,
title: title.trim(),
wahrscheinlichkeit: wahr,
auswirkung: ausw,
herkunft: herkunft === '' ? null : (herkunft as 'intern' | 'extern'),
showstopper,
massnahme: massnahme.trim() || null,
strategie: strategie === '' ? null : (strategie as RiskStrategie),
ownerUserId: owner === '' ? null : owner,
status,
});
}}
>
<textarea
value={title}
onChange={(e) => setTitle(e.target.value)}
rows={2}
placeholder="Ganzer Satz"
className={inputCls}
/>
<div className="grid grid-cols-2 gap-2">
<LevelSelect label="Wahrscheinlichkeit" value={wahr} onChange={setWahr} />
<LevelSelect label="Auswirkung" value={ausw} onChange={setAusw} />
<label className="text-xs text-[var(--color-ink-muted)]">
Herkunft
<select
value={herkunft}
onChange={(e) => setHerkunft(e.target.value)}
className={inputCls}
>
<option value="">—</option>
<option value="intern">Intern</option>
<option value="extern">Extern</option>
</select>
</label>
<label className="text-xs text-[var(--color-ink-muted)]">
Status
<select
value={status}
onChange={(e) => setStatus(e.target.value as RiskStatus)}
className={inputCls}
>
{RISK_STATUSES.map((st) => (
<option key={st} value={st}>
{RISK_STATUS_LABEL[st]}
</option>
))}
</select>
</label>
</div>
<div className="grid grid-cols-2 gap-2">
{!isChance && (
<label className="text-xs text-[var(--color-ink-muted)]">
Strategie
<select
value={strategie}
onChange={(e) => setStrategie(e.target.value)}
className={inputCls}
>
<option value="">—</option>
{RISK_STRATEGIEN.map((st) => (
<option key={st} value={st}>
{RISK_STRATEGIE_LABEL[st]}
</option>
))}
</select>
</label>
)}
<label className="text-xs text-[var(--color-ink-muted)]">
Owner
<select value={owner} onChange={(e) => setOwner(e.target.value)} className={inputCls}>
<option value="">—</option>
{users.map((u) => (
<option key={u.id} value={u.id}>
{u.name}
</option>
))}
</select>
</label>
</div>
<input
value={massnahme}
onChange={(e) => setMassnahme(e.target.value)}
placeholder={isChance ? 'Wie nutzen wir die Chance?' : 'Gegenmaßnahme'}
className={inputCls}
/>
{!isChance && (
<label className="flex items-center gap-2 text-sm">
<input
type="checkbox"
checked={showstopper}
onChange={(e) => setShowstopper(e.target.checked)}
/>
Showstopper (bringt das Projekt zum Stillstand)
</label>
)}
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={update.isPending}>
Speichern
</Button>
</div>
</form>
);
}
return (
<div
className={clsx(
'rounded-[var(--radius-md)] border p-3 text-sm',
r.showstopper ? 'border-[var(--color-ampel-red-fg)]' : 'border-[var(--color-border)]',
)}
>
<div className="flex items-start justify-between gap-2">
<p className="flex-1">
{r.showstopper && (
<span className="mr-2 inline-flex items-center gap-1 rounded-full bg-[var(--color-ampel-red-bg)] px-2 py-0.5 text-xs font-medium text-[var(--color-ampel-red-fg)]">
<AlertTriangle size={11} /> Showstopper
</span>
)}
{r.title}
</p>
<div className="flex shrink-0 gap-1">
<button
type="button"
onClick={() => setEditing(true)}
aria-label="Bearbeiten"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ink)]"
>
<Pencil size={14} />
</button>
<button
type="button"
onClick={async () => {
if (
await confirm({
title: 'Risiko löschen?',
destructive: true,
confirmLabel: 'Löschen',
})
)
remove.mutate({ id: r.id });
}}
aria-label="Entfernen"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
>
<Trash2 size={14} />
</button>
</div>
</div>
<div className="mt-1.5 flex flex-wrap gap-1 text-xs">
<span
className={clsx(
'rounded-full px-2 py-0.5',
LEVEL_META[r.wahrscheinlichkeit as Level].badge,
)}
>
W: {LEVEL_META[r.wahrscheinlichkeit as Level].label}
</span>
<span className={clsx('rounded-full px-2 py-0.5', LEVEL_META[r.auswirkung as Level].badge)}>
A: {LEVEL_META[r.auswirkung as Level].label}
</span>
{r.herkunft && (
<span className="rounded-full bg-black/5 px-2 py-0.5 text-[var(--color-ink-muted)]">
{r.herkunft === 'intern' ? 'Intern' : 'Extern'}
</span>
)}
<span className="rounded-full bg-black/5 px-2 py-0.5 text-[var(--color-ink-muted)]">
{RISK_STATUS_LABEL[r.status as RiskStatus]}
</span>
{r.strategie && (
<span className="rounded-full bg-black/5 px-2 py-0.5 text-[var(--color-ink-muted)]">
{RISK_STRATEGIE_LABEL[r.strategie as RiskStrategie]}
</span>
)}
{r.ownerUserId && userMap.get(r.ownerUserId) && (
<span className="rounded-full bg-black/5 px-2 py-0.5 text-[var(--color-ink-muted)]">
{userMap.get(r.ownerUserId)}
</span>
)}
</div>
{r.massnahme && (
<p className="mt-1 text-xs text-[var(--color-ink-muted)]">
{isChance ? 'Nutzung: ' : 'Gegenmaßnahme: '}
{r.massnahme}
</p>
)}
</div>
);
}
function AddRiskForm({
projectId,
kind,
users,
onDone,
}: {
projectId: string;
kind: 'risiko' | 'chance';
users: Array<{ id: string; name: string }>;
onDone: () => void;
}) {
const utils = trpc.useUtils();
const [title, setTitle] = useState('');
const [wahr, setWahr] = useState<Level>('mittel');
const [ausw, setAusw] = useState<Level>('mittel');
const [showstopper, setShowstopper] = useState(false);
const [massnahme, setMassnahme] = useState('');
const [strategie, setStrategie] = useState('');
const [owner, setOwner] = useState('');
const add = trpc.risk.create.useMutation({
onSuccess: async () => {
await utils.risk.forProject.invalidate({ projectId });
await utils.dashboard.overview.invalidate();
onDone();
},
});
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!title.trim()) return;
add.mutate({
projectId,
kind,
title: title.trim(),
wahrscheinlichkeit: wahr,
auswirkung: ausw,
showstopper: kind === 'risiko' ? showstopper : false,
massnahme: massnahme.trim() || undefined,
strategie:
kind === 'risiko' && strategie !== '' ? (strategie as RiskStrategie) : undefined,
ownerUserId: owner === '' ? undefined : owner,
});
}}
>
<p className="text-sm font-medium">{kind === 'risiko' ? 'Neues Risiko' : 'Neue Chance'}</p>
<textarea
value={title}
onChange={(e) => setTitle(e.target.value)}
rows={2}
placeholder={
kind === 'risiko'
? 'z. B. „Interne Ressourcen werden abgezogen.“'
: 'z. B. „Kunde will weitere Standorte anbinden.“'
}
className={inputCls}
/>
<div className="grid grid-cols-2 gap-2">
<LevelSelect label="Wahrscheinlichkeit" value={wahr} onChange={setWahr} />
<LevelSelect label="Auswirkung" value={ausw} onChange={setAusw} />
</div>
<div className="grid grid-cols-2 gap-2">
{kind === 'risiko' && (
<label className="text-xs text-[var(--color-ink-muted)]">
Strategie
<select
value={strategie}
onChange={(e) => setStrategie(e.target.value)}
className={inputCls}
>
<option value="">—</option>
{RISK_STRATEGIEN.map((st) => (
<option key={st} value={st}>
{RISK_STRATEGIE_LABEL[st]}
</option>
))}
</select>
</label>
)}
<label className="text-xs text-[var(--color-ink-muted)]">
Owner
<select value={owner} onChange={(e) => setOwner(e.target.value)} className={inputCls}>
<option value="">—</option>
{users.map((u) => (
<option key={u.id} value={u.id}>
{u.name}
</option>
))}
</select>
</label>
</div>
<input
value={massnahme}
onChange={(e) => setMassnahme(e.target.value)}
placeholder={kind === 'risiko' ? 'Gegenmaßnahme (optional)' : 'Wie nutzen? (optional)'}
className={inputCls}
/>
{kind === 'risiko' && (
<label className="flex items-center gap-2 text-sm">
<input
type="checkbox"
checked={showstopper}
onChange={(e) => setShowstopper(e.target.checked)}
/>
Showstopper
</label>
)}
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={onDone}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={add.isPending}>
Hinzufügen
</Button>
</div>
</form>
);
}
// --- Meilensteine (editierbar, Ergebnis/Kundennutzen, Datums-Warnung) -------
function MilestonesSection({
projectId,
milestones,
deadline,
}: {
projectId: string;
milestones: Milestone[];
deadline: string | null;
}) {
const [adding, setAdding] = useState(false);
const deadlineWarn = dateWarnings(deadline);
return (
<section>
<div className="mb-2 flex items-center justify-between">
<h2 className="text-lg font-semibold">Meilensteine</h2>
{!adding && (
<button
type="button"
onClick={() => setAdding(true)}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Plus size={13} /> Meilenstein
</button>
)}
</div>
{deadline && deadlineWarn.length > 0 && (
<p className="mb-2 flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={13} className="mt-0.5 shrink-0" />
Deadline {deadline}: {deadlineWarn.join(' ')}
</p>
)}
{milestones.length < 2 && (
<p className="mb-2 flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={13} className="mt-0.5 shrink-0" />
Jedes Projekt sollte mindestens 2 Meilensteine haben (Anfang & Ende).
</p>
)}
<Card.Root>
<Card.Body className="space-y-2">
{milestones.length === 0 && !adding && (
<p className="text-sm text-[var(--color-ink-muted)]">Noch keine Meilensteine.</p>
)}
{milestones.map((m) => (
<MilestoneRow key={m.id} projectId={projectId} milestone={m} />
))}
{adding && <AddMilestoneForm projectId={projectId} onDone={() => setAdding(false)} />}
</Card.Body>
</Card.Root>
</section>
);
}
function MilestoneRow({ projectId, milestone: m }: { projectId: string; milestone: Milestone }) {
const utils = trpc.useUtils();
const [editing, setEditing] = useState(false);
const invalidate = () => utils.project.byId.invalidate({ id: projectId });
const update = trpc.project.updateMilestone.useMutation({
onSuccess: async () => {
await invalidate();
setEditing(false);
},
});
const remove = trpc.project.removeMilestone.useMutation({ onSuccess: invalidate });
const confirm = useConfirm();
const [title, setTitle] = useState(m.title);
const [due, setDue] = useState(m.due ?? '');
const [status, setStatus] = useState(m.status);
const [ergebnis, setErgebnis] = useState(m.ergebnis ?? '');
const [kundennutzen, setKundennutzen] = useState(m.kundennutzen ?? '');
const warn = dateWarnings(m.due);
if (editing) {
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!title.trim()) return;
update.mutate({
milestoneId: m.id,
title: title.trim(),
due: due === '' ? null : due,
status,
ergebnis: ergebnis.trim() || null,
kundennutzen: kundennutzen.trim() || null,
});
}}
>
<div className="grid grid-cols-[1fr_auto_auto] gap-2">
<input
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Titel *"
className={inputCls}
/>
<input
type="date"
value={due}
onChange={(e) => setDue(e.target.value)}
className={inputCls}
/>
<select
value={status}
onChange={(e) => setStatus(e.target.value as Milestone['status'])}
className={inputCls}
>
<option value="open">Offen</option>
<option value="done">Erledigt</option>
<option value="overdue">Überfällig</option>
</select>
</div>
<textarea
value={ergebnis}
onChange={(e) => setErgebnis(e.target.value)}
rows={2}
placeholder="Ergebnis-Übersicht („Patchnotes“)"
className={inputCls}
/>
<input
value={kundennutzen}
onChange={(e) => setKundennutzen(e.target.value)}
placeholder="Konkreter Kundennutzen"
className={inputCls}
/>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={update.isPending}>
Speichern
</Button>
</div>
</form>
);
}
return (
<div className="rounded-[var(--radius-md)] border border-[var(--color-border)] p-3 text-sm">
<div className="flex items-start justify-between gap-2">
<div className="flex-1">
<p
className={clsx(
'font-medium',
m.status === 'done' && 'text-[var(--color-ink-muted)] line-through',
)}
>
{m.title}
</p>
<p className="text-xs text-[var(--color-ink-muted)]">
{m.due ?? 'kein Datum'} ·{' '}
{m.status === 'done' ? 'erledigt' : m.status === 'overdue' ? 'überfällig' : 'offen'}
</p>
{warn.length > 0 && (
<p className="mt-1 flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={12} className="mt-0.5 shrink-0" />
{warn.join(' ')}
</p>
)}
{m.ergebnis && <p className="mt-1 text-xs">Ergebnis: {m.ergebnis}</p>}
{m.kundennutzen && (
<p className="mt-0.5 text-xs text-[var(--color-ink-muted)]">
Kundennutzen: {m.kundennutzen}
</p>
)}
</div>
<div className="flex shrink-0 gap-1">
<button
type="button"
onClick={() => setEditing(true)}
aria-label="Bearbeiten"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ink)]"
>
<Pencil size={14} />
</button>
<button
type="button"
onClick={async () => {
if (
await confirm({
title: 'Meilenstein löschen?',
destructive: true,
confirmLabel: 'Löschen',
})
)
remove.mutate({ milestoneId: m.id });
}}
aria-label="Entfernen"
className="text-[var(--color-ink-faint)] hover:text-[var(--color-ampel-red-fg)]"
>
<Trash2 size={14} />
</button>
</div>
</div>
</div>
);
}
function AddMilestoneForm({ projectId, onDone }: { projectId: string; onDone: () => void }) {
const utils = trpc.useUtils();
const [title, setTitle] = useState('');
const [due, setDue] = useState('');
const add = trpc.project.addMilestone.useMutation({
onSuccess: async () => {
await utils.project.byId.invalidate({ id: projectId });
onDone();
},
});
const warn = dateWarnings(due);
return (
<form
className="space-y-2 rounded-[var(--radius-md)] border border-dashed border-[var(--color-border)] p-3"
onSubmit={(e) => {
e.preventDefault();
if (!title.trim()) return;
add.mutate({ projectId, title: title.trim(), due: due || undefined });
}}
>
<div className="grid grid-cols-[1fr_auto] gap-2">
<input
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Titel *"
className={inputCls}
/>
<input
type="date"
value={due}
onChange={(e) => setDue(e.target.value)}
className={inputCls}
/>
</div>
{warn.length > 0 && (
<p className="flex items-start gap-1.5 text-xs text-[var(--color-ampel-amber-fg)]">
<AlertTriangle size={12} className="mt-0.5 shrink-0" />
{warn.join(' ')}
</p>
)}
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={onDone}>
Abbrechen
</Button>
<Button type="submit" size="sm" disabled={add.isPending}>
Hinzufügen
</Button>
</div>
</form>
);
}
function AbschlussDialog({
projectId,
abschlussvermerk,
onClose,
}: {
projectId: string;
abschlussvermerk: string | null;
onClose: () => void;
}) {
const [url, setUrl] = useState('');
const [vermerk, setVermerk] = useState(abschlussvermerk ?? '');
const [checks, setChecks] = useState({ abnahme: false, aufraeumen: false, retro: false });
const navigate = useNavigate();
const utils = trpc.useUtils();
const mutation = trpc.project.archive.useMutation({
onSuccess: async () => {
toast(voice.toast.projectArchived);
await utils.project.byId.invalidate({ id: projectId });
await utils.project.listArchived.invalidate();
await utils.dashboard.overview.invalidate();
navigate('/archiv');
},
});
function submit(e: React.FormEvent) {
e.preventDefault();
mutation.mutate({
projectId,
lessonsLearnedUrl: url,
abschlussvermerk: vermerk.trim() || undefined,
});
}
const checkItems: Array<{ key: keyof typeof checks; label: string }> = [
{ key: 'abnahme', label: 'Abnahme — Liefergegenstände ohne offene Beanstandung abgenommen' },
{ key: 'aufraeumen', label: 'Aufräumen — Rechnungen, Zugänge, Verträge, Übergabe in Betrieb' },
{ key: 'retro', label: 'Retrospektive / Lessons Learned durchgeführt' },
];
return (
<Modal open onClose={onClose} title="Projekt abschließen">
<p className="mt-1 text-sm text-[var(--color-ink-muted)]">
Ein Projekt endet bewusst (Leitfaden Phase 4).
</p>
<form onSubmit={submit} className="mt-4 space-y-3">
<div className="space-y-1.5 rounded-[var(--radius-md)] border border-[var(--color-border)] p-3">
{checkItems.map((it) => (
<label key={it.key} className="flex items-start gap-2 text-sm">
<input
type="checkbox"
checked={checks[it.key]}
onChange={(e) => setChecks((c) => ({ ...c, [it.key]: e.target.checked }))}
className="mt-0.5"
/>
{it.label}
</label>
))}
</div>
<label className="block">
<span className="text-sm font-medium">Abschlussvermerk</span>
<textarea
value={vermerk}
onChange={(e) => setVermerk(e.target.value)}
rows={3}
maxLength={2000}
placeholder="Ziel erreicht? Aufwand gegen Plan? Wichtigste Erkenntnisse — eine halbe Seite, kein Roman."
className={clsx(inputCls, 'mt-1')}
/>
</label>
<label className="block">
<span className="text-sm font-medium">Lessons-Learned-URL (Outline)</span>
<input
required
type="url"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="https://outline.tool-ctrl.de/lessons-learned/..."
className={clsx(inputCls, 'mt-1')}
/>
</label>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" onClick={onClose}>
Abbrechen
</Button>
<Button type="submit" disabled={mutation.isPending}>
Abschließen
</Button>
</div>
</form>
</Modal>
);
}
const LINK_FIELDS = [
{
key: 'outlineSteckbriefUrl',
label: 'Outline-Steckbrief',
placeholder: 'https://wiki.tool-ctrl.de/doc/…',
},
{ key: 'planeProjectUrl', label: 'Plane-Board', placeholder: 'https://project.tool-ctrl.de/…' },
{ key: 'risikolisteUrl', label: 'Risikoliste', placeholder: 'https://… (z. B. Outline / Plane)' },
{ key: 'lessonsLearnedUrl', label: 'Lessons Learned', placeholder: 'https://… (Retro / Doku)' },
] as const;
function VerlinkungenSection({
projectId,
project: p,
}: {
projectId: string;
project: ProjectDetail;
}) {
const utils = trpc.useUtils();
const [editing, setEditing] = useState(false);
const [vals, setVals] = useState<Record<string, string>>({});
const update = trpc.project.update.useMutation({
onSuccess: async () => {
toast(voice.toast.saved);
await utils.project.byId.invalidate({ id: projectId });
setEditing(false);
},
});
function startEdit() {
setVals(Object.fromEntries(LINK_FIELDS.map((f) => [f.key, p[f.key] ?? ''])));
setEditing(true);
}
function save() {
update.mutate({
projectId,
...Object.fromEntries(LINK_FIELDS.map((f) => [f.key, (vals[f.key] ?? '').trim() || null])),
});
}
return (
<Card.Root>
<Card.Header className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Verlinkungen</h2>
{!editing && (
<button
type="button"
onClick={startEdit}
className="inline-flex items-center gap-1 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]"
>
<Pencil size={13} /> Bearbeiten
</button>
)}
</Card.Header>
<Card.Body className="space-y-2 text-sm">
{editing ? (
<div className="space-y-3">
{LINK_FIELDS.map((f) => (
<label key={f.key} className="block">
<span className="text-sm font-medium">{f.label}</span>
<input
type="url"
value={vals[f.key] ?? ''}
onChange={(e) => setVals((v) => ({ ...v, [f.key]: e.target.value }))}
placeholder={f.placeholder}
className={clsx(inputCls, 'mt-1')}
/>
</label>
))}
<p className="text-xs text-[var(--color-ink-faint)]">
Leer lassen entfernt den Link. URLs müssen mit http(s):// beginnen.
</p>
<div className="flex justify-end gap-2">
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>
Abbrechen
</Button>
<Button type="button" size="sm" onClick={save} disabled={update.isPending}>
Speichern
</Button>
</div>
</div>
) : (
LINK_FIELDS.map((f) => <LinkRow key={f.key} label={f.label} url={p[f.key]} />)
)}
</Card.Body>
</Card.Root>
);
}
function LinkRow({ label, url }: { label: string; url: string | null }) {
return (
<p className="flex items-center justify-between">
<span className="text-[var(--color-ink-muted)]">{label}</span>
{url ? (
<a href={url} target="_blank" rel="noreferrer" className="truncate hover:underline">
{url}
</a>
) : (
<span className="text-[var(--color-ink-faint)]">—</span>
)}
</p>
);
}