This repository has been archived on 2026-11-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
everythingbutwork/apps/web/src/routes/dashboard.tsx
T
Raffael SheikhandClaude Opus 4.8 8b0df9cc4e UI: Fehler-States statt weißer Leerseiten bei Query-Fehlern
Dashboard/Projekt/Lead/Team/Historie rendern bei fehlgeschlagener Query nicht
mehr ein stilles `return null` (leere weisse Seite), sondern einen Hinweis mit
"Neu laden"-Button.

- Neue Komponente ErrorState (Meldung + optionaler Retry)
- 5 Routen: if (q.isError || !q.data) -> ErrorState mit q.refetch()

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

393 lines
15 KiB
TypeScript

import { Link } from 'react-router';
import { trpc } from '../lib/trpc';
import { voice } from '../lib/voice';
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 { TeamTimeSection } from '../components/time/TeamTimeSection';
import { MODUS_META, type ProjectModus } from '../lib/project-meta';
import { AlertTriangle } from 'lucide-react';
import { clsx } from 'clsx';
import { ProjectLogo } from '../components/project/ProjectLogo';
export function DashboardRoute() {
const q = trpc.dashboard.overview.useQuery();
const today = trpc.dayEntry.today.useQuery();
if (q.isPending) {
return (
<div className="grid grid-cols-1 gap-6 md:grid-cols-3">
<SkeletonCard />
<SkeletonCard />
<SkeletonCard />
</div>
);
}
if (q.isError || !q.data)
return (
<ErrorState
message="Dashboard konnte nicht geladen werden."
onRetry={() => void q.refetch()}
/>
);
const isCheckedIn =
today.data?.entry?.status !== undefined && today.data.entry.status !== 'absent';
return (
<div className="space-y-8">
<header className="flex items-end justify-between">
<div>
<h1 className="text-3xl font-bold">Dashboard</h1>
<p className="text-[var(--color-ink-muted)]">
Stand: {formatDate(q.data.date)} · Jourfixe {q.data.jourfixe.label}
</p>
</div>
{!isCheckedIn && (
<Link
to="/heute"
className="inline-flex h-11 items-center rounded-[var(--radius-md)] bg-[var(--color-brand)] px-5 text-sm font-medium text-[var(--color-brand-fg)] hover:bg-black/85"
>
{voice.hint.notCheckedInToday} → {voice.cta.checkIn}
</Link>
)}
</header>
{q.data.showstoppers.length > 0 && (
<section>
<Card.Root className="border-[var(--color-ampel-red-fg)]">
<Card.Header>
<h2 className="flex items-center gap-2 text-lg font-semibold text-[var(--color-ampel-red-fg)]">
<AlertTriangle size={18} /> Showstopper
</h2>
</Card.Header>
<Card.Body>
<ul className="space-y-2">
{q.data.showstoppers.map((s) => (
<li
key={s.id}
className="flex items-start justify-between gap-3 rounded-[var(--radius-md)] border border-[var(--color-border)] p-3"
>
<span className="text-sm">{s.title}</span>
<Link
to={`/projekt/${s.projectId}`}
className="shrink-0 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
>
{s.projectName} →
</Link>
</li>
))}
</ul>
</Card.Body>
</Card.Root>
</section>
)}
{q.data.meilensteine.length > 0 && (
<section>
<h2 className="mb-2 text-lg font-semibold">Anstehende Meilensteine</h2>
<Card.Root>
<Card.Body className="p-0">
<ul className="divide-y divide-[var(--color-border)]">
{q.data.meilensteine.map((m) => (
<li key={m.id} className="flex items-center justify-between gap-3 px-4 py-3">
<div className="min-w-0">
<p className="truncate text-sm font-medium">{m.title}</p>
<div className="mt-0.5 flex items-center gap-2 text-xs">
<span
className={clsx(
m.ueberfaellig
? 'font-medium text-[var(--color-ampel-red-fg)]'
: 'text-[var(--color-ink-muted)]',
)}
>
{formatDate(m.due!)}
{m.ueberfaellig && ' · überfällig'}
</span>
<span className="text-[var(--color-ink-faint)]">·</span>
<span className="text-[var(--color-ink-muted)]">{relativeDays(m.due!, q.data.date)}</span>
</div>
</div>
<Link
to={`/projekt/${m.projectId}`}
className="inline-flex shrink-0 items-center gap-2 text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
>
<ProjectLogo url={m.projectLogoUrl} name={m.projectName} size={20} />
{m.projectName} →
</Link>
</li>
))}
</ul>
</Card.Body>
</Card.Root>
</section>
)}
{q.data.kritischeModi.length > 0 && (
<section>
<h2 className="mb-2 text-lg font-semibold">Projekte in Eskalation / Taskforce</h2>
<div className="flex flex-wrap gap-2">
{q.data.kritischeModi.map((p) => (
<Link
key={p.id}
to={`/projekt/${p.id}`}
className="inline-flex items-center gap-2 rounded-[var(--radius-md)] border border-[var(--color-border)] px-3 py-1.5 text-sm hover:border-[var(--color-ink)]"
>
<span
className={clsx(
'rounded-full px-2 py-0.5 text-[10px] font-medium',
MODUS_META[p.modus as ProjectModus].badge,
)}
>
{MODUS_META[p.modus as ProjectModus].label}
</span>
{p.name}
</Link>
))}
</div>
</section>
)}
<section className="grid grid-cols-1 gap-6 md:grid-cols-3">
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Heute</h2>
</Card.Header>
<Card.Body>
<p className="text-2xl font-bold">
{q.data.heuteQuote.gepingt} / {q.data.heuteQuote.gesamt}
</p>
<p className="text-sm text-[var(--color-ink-muted)]">Locked in</p>
{q.data.heuteQuote.fehlende.length > 0 && (
<details className="mt-3">
<summary className="cursor-pointer text-sm text-[var(--color-ink-muted)] hover:text-[var(--color-ink)]">
{q.data.heuteQuote.fehlende.length} fehlt heute noch
</summary>
<ul className="mt-2 space-y-1 text-sm">
{q.data.heuteQuote.fehlende.map((u) => (
<li key={u.id}>{u.name}</li>
))}
</ul>
</details>
)}
</Card.Body>
</Card.Root>
<Card.Root className="md:col-span-2">
<Card.Header>
<h2 className="text-lg font-semibold">Bereichsübergreifend offen</h2>
</Card.Header>
<Card.Body>
{q.data.blockers.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">{voice.empty.blockers}</p>
) : (
<ul className="space-y-2">
{q.data.blockers.map((b) => (
<li
key={b.id}
className="flex items-center justify-between rounded-[var(--radius-md)] border border-[var(--color-border)] p-3"
>
<span className="text-sm font-medium">{b.title}</span>
<span className="text-xs text-[var(--color-ink-muted)]">
seit {formatDate(b.openedAt.toString())}
</span>
</li>
))}
</ul>
)}
</Card.Body>
</Card.Root>
</section>
{q.data.pflichtMinimumOffen.length > 0 && (
<Card.Root>
<Card.Header>
<h2 className="text-lg font-semibold">Pflicht-Minimum offen</h2>
</Card.Header>
<Card.Body>
<ul className="space-y-1 text-sm">
{q.data.pflichtMinimumOffen.map((p) => (
<li key={p.id}>
<Link to={`/projekt/${p.id}`} className="inline-flex items-center gap-2 hover:underline">
<ProjectLogo url={p.logoUrl} name={p.name} size={20} />
{p.name}
</Link>
</li>
))}
</ul>
</Card.Body>
</Card.Root>
)}
<TeamHeuteSection />
<TeamTimeSection />
<section aria-labelledby="feed-heading">
<div className="mb-3 flex items-baseline justify-between">
<h2 id="feed-heading" className="text-lg font-semibold">
Gestern im Team
</h2>
<Link
to="/historie"
className="text-xs text-[var(--color-ink-muted)] hover:text-[var(--color-ink)] hover:underline"
>
Ganze Historie →
</Link>
</div>
{q.data.feed.length === 0 ? (
<Card.Root>
<Card.Body>
<p className="text-sm text-[var(--color-ink-muted)]">{voice.empty.feed}</p>
</Card.Body>
</Card.Root>
) : (
<div className="space-y-2">
{q.data.feed.map((entry) => (
<Card.Root key={entry.id}>
<Card.Body>
<div className="flex items-start justify-between gap-3">
<div>
<p className="text-sm font-semibold">{entry.userName}</p>
<p className="text-xs text-[var(--color-ink-muted)]">{entry.date}</p>
</div>
{entry.ampel && <AmpelBadge ampel={entry.ampel} />}
</div>
{entry.reflectionText && <p className="mt-2 text-sm">{entry.reflectionText}</p>}
</Card.Body>
</Card.Root>
))}
</div>
)}
</section>
</div>
);
}
function AmpelBadge({ ampel }: { ampel: 'green' | 'amber' | 'red' }) {
const cls = {
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)]',
}[ampel];
const label = { green: 'Im Plan', amber: 'Gefährdet', red: 'Blockiert' }[ampel];
return (
<span
className={clsx(
'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium',
cls,
)}
>
<span className="h-1.5 w-1.5 rounded-full bg-current" />
{label}
</span>
);
}
function TeamHeuteSection() {
const team = trpc.dayEntry.todayTeam.useQuery();
const users = trpc.user.list.useQuery();
if (team.isPending) return null;
const data = team.data ?? [];
const userMap = new Map((users.data ?? []).map((u) => [u.id, u.name]));
const lockedInLabel =
data.length === 0
? 'Heute ist noch niemand locked in.'
: data.length === 1
? 'Heute ist 1 Person locked in.'
: `Heute sind ${data.length} Personen locked in.`;
if (data.length === 0) {
return (
<section>
<h2 className="mb-3 text-lg font-semibold">{lockedInLabel}</h2>
</section>
);
}
return (
<section>
<h2 className="mb-3 text-lg font-semibold">{lockedInLabel}</h2>
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
{data.map((u) => (
<Card.Root key={u.userId}>
<Card.Body>
<div className="flex items-center justify-between">
<p className="text-sm font-semibold">{userMap.get(u.userId) ?? '—'}</p>
<span
className={clsx(
'rounded-full px-2 py-0.5 text-xs',
u.entryStatus === 'full'
? 'bg-[var(--color-ampel-green-bg)] text-[var(--color-ampel-green-fg)]'
: u.entryStatus === 'begun'
? 'bg-black/5 text-[var(--color-ink-muted)]'
: 'bg-black/5 text-[var(--color-ink-muted)]',
)}
>
{u.entryStatus === 'full'
? 'reflektiert'
: u.entryStatus === 'begun'
? 'locked in'
: 'abwesend'}
</span>
</div>
{u.todos.length === 0 ? (
<p className="mt-2 text-xs text-[var(--color-ink-faint)]">Keine ToDos eingetragen.</p>
) : (
<ul className="mt-2 space-y-1.5 text-sm">
{u.todos.map((t) => (
<li key={t.id} className="flex items-start gap-2">
<span
className={clsx(
'mt-1 inline-block h-2 w-2 rounded-full shrink-0',
t.status === 'done'
? 'bg-[var(--color-ampel-green-fg)]'
: t.status === 'dropped'
? 'bg-[var(--color-ink-faint)]'
: 'bg-[var(--color-border-strong)]',
)}
/>
<span
className={clsx(
t.status === 'dropped' && 'line-through text-[var(--color-ink-muted)]',
)}
>
{t.title}
</span>
</li>
))}
</ul>
)}
</Card.Body>
</Card.Root>
))}
</div>
</section>
);
}
function formatDate(input: string | Date): string {
const dt = input instanceof Date ? input : new Date(input);
if (Number.isNaN(dt.getTime())) return '—';
return new Intl.DateTimeFormat('de-DE', {
weekday: 'short',
day: 'numeric',
month: 'long',
}).format(dt);
}
// Relative Tagesangabe für Meilensteine ("heute", "in 3 Tagen", "vor 2 Tagen").
function relativeDays(dueIso: string, todayIso: string): string {
const due = new Date(`${dueIso}T00:00:00`);
const today = new Date(`${todayIso}T00:00:00`);
if (Number.isNaN(due.getTime()) || Number.isNaN(today.getTime())) return '';
const diff = Math.round((due.getTime() - today.getTime()) / 86_400_000);
if (diff === 0) return 'heute';
if (diff === 1) return 'morgen';
if (diff === -1) return 'gestern';
if (diff > 0) return `in ${diff} Tagen`;
return `vor ${Math.abs(diff)} Tagen`;
}
// Button als referenz behalten (Linter)
void Button;