import { useState } from 'react';
import { useParams, Link, useNavigate } from 'react-router';
import { ArrowLeft } from 'lucide-react';
import { trpc } from '../lib/trpc';
import { Card } from '../components/ui/Card';
import { Button } from '../components/ui/Button';
import { SkeletonCard } from '../components/ui/SkeletonCard';
import { useCurrentUser } from '../hooks/useCurrentUser';
import { voice } from '../lib/voice';
import { toast } from 'sonner';
import { clsx } from 'clsx';
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.data) return null;
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' },
{ key: 'status_aktuell', label: 'Status-Ampel aktuell (≤ 7 Werktage)' },
{ key: 'retrospektive', label: 'Abschluss-Retrospektive (bei beendeten Projekten)' },
];
function goBack() {
// Wenn der History-Stack einen Vorgänger hat, dorthin; sonst auf den Bereich.
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'} ·{' '}
{p.arbeitsmodus ?? '—'} · {p.deadline ? `Deadline ${p.deadline}` : 'kein Deadline'}
{p.description && (
{p.description}
)}
{abschlussOpen && (
setAbschlussOpen(false)} />
)}
Verlinkungen
Pflicht-Minimum
{pflichtKeys.map(({ key, label }) => {
const ok = p.pflichtMinimumState[key] === true;
return (
-
{label}
);
})}
Meilensteine
{milestones.length === 0 ? (
Noch keine Meilensteine.
) : (
{milestones.map((m) => (
-
{m.title}
{m.due ?? '—'} · {m.status}
))}
)}
{p.dodText && (
Definition of Done
{p.dodText}
)}
);
}
function AbschlussDialog({ projectId, onClose }: { projectId: string; onClose: () => void }) {
const [url, setUrl] = useState('');
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 });
}
return (
e.stopPropagation()}
>
Projekt abschließen
Lessons-Learned-URL ist Pflicht (Leitfaden §9 Punkt 6).
);
}
function LinkRow({ label, url }: { label: string; url: string | null }) {
return (
{label}
{url ? (
{url}
) : (
—
)}
);
}