Reflexion/ToDo-Bearbeitung war nur bis 06:00 des Folgetags moeglich. Jetzt 3-Tage-Nachfrist (isEditableWithinGrace) und ein Bearbeiten-Weg aus der Historie: - werktag: isEditableWithinGrace(entryDate, now, 3) + Tests - submitReflection/editTodoTitle: Sperre auf die 3-Tage-Nachfrist gelockert - neue Query dayEntry.ownForDate(date): eigener Tageseintrag + editable-Flag - reflexion.tsx liest ?date= und laedt vergangene Tage; Felder werden mit der bestehenden Reflexion vorbefuellt - historie.tsx: "Bearbeiten"-Button am eigenen Eintrag (wenn <= 3 Tage) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
234 lines
8.1 KiB
TypeScript
234 lines
8.1 KiB
TypeScript
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<AppRouter>['dayEntry']['historyForDate']['entries'][number];
|
|
|
|
const AMPEL_META: Record<string, { label: string; badge: string }> = {
|
|
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<string, string> = {
|
|
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<string | undefined>(undefined);
|
|
const me = useCurrentUser();
|
|
const navigate = useNavigate();
|
|
const q = trpc.dayEntry.historyForDate.useQuery({ date });
|
|
|
|
if (q.isPending) return <SkeletonCard lines={6} />;
|
|
if (q.isError || !q.data)
|
|
return (
|
|
<ErrorState
|
|
message="Historie konnte nicht geladen werden."
|
|
onRetry={() => void q.refetch()}
|
|
/>
|
|
);
|
|
const { date: current, prevDate, nextDate, entries, ohneEintrag } = q.data;
|
|
const editableDay = isWithinGraceFE(current);
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<header>
|
|
<h1 className="text-3xl font-bold">Historie</h1>
|
|
<p className="text-[var(--color-ink-muted)]">
|
|
Was hat das Team an einem Tag gemacht — Reflexion & ToDos.
|
|
</p>
|
|
</header>
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => prevDate && setDate(prevDate)}
|
|
disabled={!prevDate}
|
|
aria-label="Vorheriger Tag mit Eintrag"
|
|
className="inline-flex h-9 w-9 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)] disabled:opacity-40 disabled:hover:border-[var(--color-border)]"
|
|
>
|
|
<ChevronLeft size={16} />
|
|
</button>
|
|
<span className="min-w-[200px] text-center font-medium">{formatDateLong(current)}</span>
|
|
<button
|
|
type="button"
|
|
onClick={() => nextDate && setDate(nextDate)}
|
|
disabled={!nextDate}
|
|
aria-label="Nächster Tag mit Eintrag"
|
|
className="inline-flex h-9 w-9 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)] disabled:opacity-40 disabled:hover:border-[var(--color-border)]"
|
|
>
|
|
<ChevronRight size={16} />
|
|
</button>
|
|
<input
|
|
type="date"
|
|
value={current}
|
|
max={todayStr}
|
|
onChange={(e) => 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"
|
|
/>
|
|
</div>
|
|
|
|
{entries.length === 0 ? (
|
|
<Card.Root>
|
|
<Card.Body>
|
|
<p className="text-sm text-[var(--color-ink-muted)]">Keine Einträge an diesem Tag.</p>
|
|
</Card.Body>
|
|
</Card.Root>
|
|
) : (
|
|
<div className="space-y-3">
|
|
{entries.map((p) => (
|
|
<PersonCard
|
|
key={p.userId}
|
|
person={p}
|
|
canEdit={p.userId === me?.id && editableDay}
|
|
onEdit={() => navigate(`/reflexion?date=${current}`)}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{ohneEintrag.length > 0 && (
|
|
<p className="text-xs text-[var(--color-ink-faint)]">
|
|
Ohne Eintrag an diesem Tag: {ohneEintrag.join(', ')}
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PersonCard({
|
|
person: p,
|
|
canEdit,
|
|
onEdit,
|
|
}: {
|
|
person: HistoryPerson;
|
|
canEdit: boolean;
|
|
onEdit: () => void;
|
|
}) {
|
|
const ampel = p.ampel ? AMPEL_META[p.ampel] : null;
|
|
return (
|
|
<Card.Root>
|
|
<Card.Body className="space-y-2">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<p className="font-semibold">{p.name}</p>
|
|
{ampel && (
|
|
<span className={clsx('rounded-full px-2 py-0.5 text-xs font-medium', ampel.badge)}>
|
|
{ampel.label}
|
|
</span>
|
|
)}
|
|
{p.trend && (
|
|
<span className="text-xs text-[var(--color-ink-muted)]">
|
|
{TREND_LABEL[p.trend] ?? p.trend}
|
|
</span>
|
|
)}
|
|
{p.status === 'begun' && (
|
|
<span className="rounded-full bg-black/5 px-2 py-0.5 text-xs text-[var(--color-ink-muted)]">
|
|
nicht reflektiert
|
|
</span>
|
|
)}
|
|
{canEdit && (
|
|
<Button size="sm" variant="ghost" className="ml-auto" onClick={onEdit}>
|
|
<Pencil size={13} /> Bearbeiten
|
|
</Button>
|
|
)}
|
|
</div>
|
|
|
|
{p.todos.length > 0 && (
|
|
<ul className="space-y-1 text-sm">
|
|
{p.todos.map((t) => (
|
|
<li key={t.id} className="flex items-start gap-2">
|
|
<span
|
|
className={clsx(
|
|
'mt-1.5 inline-block h-2 w-2 shrink-0 rounded-full',
|
|
t.status === 'done'
|
|
? 'bg-[var(--color-ampel-green-fg)]'
|
|
: t.status === 'dropped'
|
|
? 'bg-[var(--color-ink-faint)]'
|
|
: 'bg-[var(--color-border-strong)]',
|
|
)}
|
|
/>
|
|
<div className="flex-1">
|
|
<span
|
|
className={clsx(
|
|
t.status === 'dropped' && 'text-[var(--color-ink-muted)] line-through',
|
|
)}
|
|
>
|
|
{t.title}
|
|
{t.unplanned && (
|
|
<span className="ml-2 rounded-full bg-black/5 px-1.5 py-0.5 text-[10px] text-[var(--color-ink-muted)]">
|
|
ungeplant
|
|
</span>
|
|
)}
|
|
</span>
|
|
{t.dropReason && (
|
|
<span className="mt-0.5 block whitespace-pre-wrap text-xs text-[var(--color-ink-muted)]">
|
|
{t.dropReason}
|
|
</span>
|
|
)}
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
|
|
{p.reflectionText && (
|
|
<p className="whitespace-pre-wrap text-sm text-[var(--color-ink)]">{p.reflectionText}</p>
|
|
)}
|
|
{p.url && (
|
|
<a
|
|
href={p.url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="block truncate text-sm text-[var(--color-ink-muted)] underline hover:text-[var(--color-ink)]"
|
|
>
|
|
{p.url}
|
|
</a>
|
|
)}
|
|
{p.todos.length === 0 && !p.reflectionText && !p.url && (
|
|
<p className="text-xs text-[var(--color-ink-faint)]">Keine Details.</p>
|
|
)}
|
|
</Card.Body>
|
|
</Card.Root>
|
|
);
|
|
}
|