Ein <input type="date"> zeigt das Datum im Format der Spracheinstellung des Browsers oder des Betriebssystems, auf einem englisch eingestellten Rechner also als MM/DD/YYYY. Jedes Datumsfeld ist jetzt ein Textfeld mit TT.MM.JJJJ und einem Knopf fuer den Kalender des Browsers; gemeldet wird weiterhin JJJJ-MM-TT. Angenommen werden 1.3.2026, 01.03.2026, Komma oder Schraegstrich als Trenner (die Zifferntastatur am Telefon), acht Ziffern ohne Trenner und ein eingefuegtes JJJJ-MM-TT. Ein unvollstaendiges oder unmoegliches Datum geht nicht hinaus und zeigt beim Verlassen einen Hinweis; ein Datum ausserhalb der Schranken nennt die Grenze. Der Stichtag im Organigramm nutzt dieselbe Logik (useDatumEingabe). Geprueft: lint, tsc, 1029 Tests, Waechter.
97 lines
4.0 KiB
TypeScript
97 lines
4.0 KiB
TypeScript
"use client";
|
|
|
|
import { CalendarClock } from "lucide-react";
|
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
import { Button } from "@/components/ui/Button";
|
|
import { FILTER_SELECT_CLASS, KalenderKnopf, useDatumEingabe } from "@/components/ui/Field";
|
|
import { fmtDate } from "@/lib/format";
|
|
|
|
type AsOfPickerProps = {
|
|
asOf: string;
|
|
today: string;
|
|
/** Placements projected from effective-dated changes not yet applied. */
|
|
projectedCount: number;
|
|
/** Earliest date the assignment history covers; before that it is today's placement. */
|
|
historyStartsAt: string | null;
|
|
};
|
|
|
|
export function AsOfPicker({ asOf, today, projectedCount, historyStartsAt }: AsOfPickerProps) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const searchParams = useSearchParams();
|
|
|
|
function setAsOf(value: string | undefined) {
|
|
const sp = new URLSearchParams(searchParams.toString());
|
|
if (value && value !== today) sp.set("asOf", value);
|
|
else sp.delete("asOf");
|
|
router.push(sp.size > 0 ? `${pathname}?${sp}` : pathname, { scroll: false });
|
|
}
|
|
|
|
// Dieselben Regeln wie in DateField: TT.MM.JJJJ, gemeldet wird nur ein
|
|
// vollständiges Datum. Hier ist jede Meldung eine Navigation.
|
|
const datum = useDatumEingabe({ value: asOf, onChange: (d) => setAsOf(d || undefined) });
|
|
|
|
const isToday = asOf === today;
|
|
const isFuture = asOf > today;
|
|
// The assignment history only reaches back to historyStartsAt; asking for a
|
|
// date before that yields today's placement for everyone, which is worth
|
|
// saying out loud rather than quietly implying.
|
|
const beforeHistory = historyStartsAt !== null && asOf < historyStartsAt;
|
|
|
|
return (
|
|
<div className="rounded border border-border bg-white p-3">
|
|
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
|
<label htmlFor="orgchart-asof" className="flex items-center gap-1.5 text-sm font-semibold text-ink">
|
|
<CalendarClock className="h-4 w-4 text-ink-muted" />
|
|
Stichtag
|
|
</label>
|
|
<div className="relative">
|
|
<input
|
|
id="orgchart-asof"
|
|
type="text"
|
|
inputMode="decimal"
|
|
autoComplete="off"
|
|
placeholder="TT.MM.JJJJ"
|
|
value={datum.text}
|
|
aria-invalid={datum.fehler ? true : undefined}
|
|
aria-describedby={datum.fehler ? "orgchart-asof-fehler" : undefined}
|
|
onChange={(e) => datum.tippen(e.target.value)}
|
|
onBlur={datum.verlassenFeld}
|
|
className={`${FILTER_SELECT_CLASS} w-36 pr-9 tabular-nums ${datum.fehler ? "border-danger-solid" : ""}`}
|
|
/>
|
|
<KalenderKnopf wert={datum.kalenderwert} min={datum.untere} max={datum.obere} onWaehlen={datum.waehlen} />
|
|
</div>
|
|
{datum.fehler && (
|
|
<span id="orgchart-asof-fehler" className="text-xs font-semibold text-danger-text">
|
|
{datum.fehler}
|
|
</span>
|
|
)}
|
|
{!isToday && (
|
|
<Button variant="ghost" size="sm" onClick={() => setAsOf(undefined)} className="!px-1 text-brand-700 hover:!bg-transparent hover:underline">
|
|
Heute
|
|
</Button>
|
|
)}
|
|
<span className="text-xs text-ink-muted">
|
|
{isToday ? "Aktuelle Organisationsstruktur." : `Struktur zum ${fmtDate(asOf)}.`}
|
|
</span>
|
|
</div>
|
|
|
|
{isFuture && (
|
|
<p className="mt-2 rounded bg-info-bg px-3 py-2 text-xs text-info-text">
|
|
Vorschau: {projectedCount > 0
|
|
? `${projectedCount} geplante Versetzung(en) oder Beförderung(en) sind eingerechnet.`
|
|
: "Für diesen Zeitraum sind keine Versetzungen vorgemerkt."}{" "}
|
|
Ein-/Austritte und Karenzen sind berücksichtigt.
|
|
</p>
|
|
)}
|
|
|
|
{beforeHistory && (
|
|
<p className="mt-2 rounded bg-warning-bg px-3 py-2 text-xs text-warning-text">
|
|
Vor dem {fmtDate(historyStartsAt)} wurde die Zuordnungshistorie noch nicht aufgezeichnet. Wer beschäftigt war,
|
|
stimmt; Team und Vorgesetzte zeigen für diesen Stichtag die heutige Zuordnung.
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|