Alter der Angehoerigen, Berichte nach Datum, deutlichere Meldung, Chip
- Angehoerige: das Alter in Klammern hinter dem Geburtsdatum, wie in den Stammdaten. - Berichte: die Namen unter einer Gruppe stehen nach Datum, das juengste zuerst, bei gleichem Datum nach Namen (nachDatumAbsteigend). Gilt fuer Bestands- und Ereignisberichte. - Rueckmeldung nach einem Vorgang: groesser, mit Zeichen, mittig unten und sechs statt vier Sekunden. Sie ist die einzige Auskunft darueber, ob ein Vorgang stattgefunden hat. - Onboarding-Checkliste: "Chip" unter der Willkommensmappe. In schon angelegten Checklisten erscheint er als offener Punkt. Geprueft: lint, tsc, 830 Tests (zwei neue fuer die Sortierung), Waechter.
This commit is contained in:
@@ -6,7 +6,7 @@ import { useState } from "react";
|
||||
import { deleteEmployeeDependent } from "@/actions/employees";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { useToast } from "@/components/ui/Toast";
|
||||
import { fmtDate, todayIso } from "@/lib/format";
|
||||
import { fmtAge, fmtDate, todayIso } from "@/lib/format";
|
||||
import type { Database } from "@/lib/types";
|
||||
import { AddDependentModal } from "./AddDependentModal";
|
||||
|
||||
@@ -69,7 +69,13 @@ export function AngehoerigeSection({ employeeId, dependents, effectiveDate }: {
|
||||
</td>
|
||||
<td className="px-4 py-2.5 text-ink-body">{d.relationship}</td>
|
||||
<td className="px-4 py-2.5 text-ink-body">{d.sv_nummer ?? "–"}</td>
|
||||
<td className="px-4 py-2.5 text-ink-body">{fmtDate(d.birth_date)}</td>
|
||||
{/* Das Alter in Klammern wie in den Stammdaten: bei
|
||||
Angehörigen ist es die eigentliche Frage (Mitversicherung,
|
||||
Familienbonus), und sie liesse sich sonst nur im Kopf
|
||||
aus dem Geburtsdatum beantworten. */}
|
||||
<td className="px-4 py-2.5 text-ink-body">
|
||||
{d.birth_date ? `${fmtDate(d.birth_date)} (${fmtAge(d.birth_date)} Jahre)` : "–"}
|
||||
</td>
|
||||
<td className="px-4 py-2.5 text-right">
|
||||
{/* Berichtigen statt löschen-und-neu-anlegen: ein
|
||||
Tippfehler hinterliesse sonst zwei Einträge in der
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { CheckCircle2, Info, TriangleAlert, type LucideIcon } from "lucide-react";
|
||||
import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from "react";
|
||||
|
||||
type ToastVariant = "success" | "error" | "info";
|
||||
@@ -14,33 +15,57 @@ const VARIANT_STYLES: Record<ToastVariant, string> = {
|
||||
info: "bg-info-text",
|
||||
};
|
||||
|
||||
const VARIANT_ICONS: Record<ToastVariant, LucideIcon> = {
|
||||
success: CheckCircle2,
|
||||
error: TriangleAlert,
|
||||
info: Info,
|
||||
};
|
||||
|
||||
// ── Warum die Meldung so gross ist ──────────────────────────────────────
|
||||
//
|
||||
// Sie ist die einzige Rückmeldung darüber, ob ein Vorgang stattgefunden hat —
|
||||
// etwa eine Einstellung, deren Eingabe eine halbe Stunde gekostet hat. Wird
|
||||
// sie übersehen, bleibt nur die Vermutung, und die nächste Handlung ist, es
|
||||
// noch einmal zu versuchen. Deshalb gross, mit Zeichen, und mittig statt in
|
||||
// einer Ecke.
|
||||
//
|
||||
// Sechs Sekunden: die Meldungen sind ganze Sätze („… wurde eingestellt"),
|
||||
// und kürzer reicht nicht, um einen Satz zu finden und zu lesen.
|
||||
const ANZEIGEDAUER_MS = 6000;
|
||||
|
||||
export function ToastProvider({ children }: { children: ReactNode }) {
|
||||
const [toasts, setToasts] = useState<ToastItem[]>([]);
|
||||
|
||||
const showToast = useCallback((message: string, variant: ToastVariant = "success") => {
|
||||
const id = Date.now() + Math.random();
|
||||
setToasts((prev) => [...prev, { id, message, variant }]);
|
||||
setTimeout(() => setToasts((prev) => prev.filter((t) => t.id !== id)), 4000);
|
||||
setTimeout(() => setToasts((prev) => prev.filter((t) => t.id !== id)), ANZEIGEDAUER_MS);
|
||||
}, []);
|
||||
|
||||
// This provider wraps the whole app, so an inline object literal here would
|
||||
// hand every consumer a new context value on each toast and re-render the
|
||||
// entire tree for a 4-second banner.
|
||||
// entire tree for a short-lived banner.
|
||||
const value = useMemo(() => ({ showToast }), [showToast]);
|
||||
|
||||
return (
|
||||
<ToastContext.Provider value={value}>
|
||||
{children}
|
||||
<div className="pointer-events-none fixed bottom-4 right-4 z-[100] flex flex-col gap-2">
|
||||
{toasts.map((t) => (
|
||||
<div
|
||||
key={t.id}
|
||||
role="status"
|
||||
className={`pointer-events-auto rounded px-4 py-2 text-sm font-semibold text-white shadow-lg ${VARIANT_STYLES[t.variant]}`}
|
||||
>
|
||||
{t.message}
|
||||
</div>
|
||||
))}
|
||||
{/* Die Breite ist begrenzt, damit ein langer Satz nicht quer über den
|
||||
Bildschirm läuft. */}
|
||||
<div className="pointer-events-none fixed inset-x-0 bottom-6 z-[100] flex flex-col items-center gap-2 px-4">
|
||||
{toasts.map((t) => {
|
||||
const Icon = VARIANT_ICONS[t.variant];
|
||||
return (
|
||||
<div
|
||||
key={t.id}
|
||||
role="status"
|
||||
className={`pointer-events-auto flex max-w-xl items-center gap-3 rounded-lg px-5 py-4 text-base font-semibold text-white shadow-xl ring-1 ring-black/10 ${VARIANT_STYLES[t.variant]}`}
|
||||
>
|
||||
<Icon className="h-6 w-6 shrink-0" aria-hidden />
|
||||
<span>{t.message}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
|
||||
@@ -79,6 +79,11 @@ export const ONBOARDING_GRUPPEN: readonly AufgabenGruppe[] = [
|
||||
{ key: "cv", label: "CV", art: "haken" },
|
||||
{ key: "goodies", label: "Goodies", art: "haken" },
|
||||
{ key: "willkommensmappe", label: "Willkommensmappe", art: "haken" },
|
||||
// Der Chip für Zutritt und Zeiterfassung wird mit der Mappe übergeben.
|
||||
// Fehlt er, steht die neue Person am ersten Tag vor der Tür. In einer
|
||||
// schon angelegten Checkliste erscheint er als offener Punkt; der Haken
|
||||
// legt die Zeile an (set_onboarding_task schreibt per upsert).
|
||||
{ key: "chip", label: "Chip", art: "haken" },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -338,6 +338,27 @@ export function measureValue(rows: ReportEmployee[], measure: Measure, asOf: str
|
||||
}
|
||||
|
||||
export type ReportPerson = { id: string; name: string; title: string; team: string; entry_date: string };
|
||||
|
||||
/**
|
||||
* Die Namen unter einer Gruppe — das jüngste Datum zuerst.
|
||||
*
|
||||
* Ohne Sortierung stünden sie in der Reihenfolge, in der die Datenbank sie
|
||||
* herausgibt, also in keiner; wer nachsehen will, wer zuletzt eingetreten
|
||||
* ist, fände es bei achthundert Zeilen nicht. Absteigend, weil das Datum in
|
||||
* beiden Berichtsarten das des Vorgangs ist (Eintritt beziehungsweise
|
||||
* Ereignis) und die Frage praktisch immer „was ist zuletzt passiert" lautet.
|
||||
*
|
||||
* Verglichen wird als Zeichenkette: das Datum kommt als „JJJJ-MM-TT" aus dem
|
||||
* Treiber (lib/db/pool.ts), und in dieser Form ist die alphabetische Ordnung
|
||||
* die zeitliche. Bei gleichem Datum entscheidet der Name, damit die Liste
|
||||
* zwischen zwei Aufrufen dieselbe bleibt.
|
||||
*/
|
||||
export function nachDatumAbsteigend(people: readonly ReportPerson[]): ReportPerson[] {
|
||||
return [...people].sort((a, b) =>
|
||||
a.entry_date === b.entry_date ? a.name.localeCompare(b.name, "de") : a.entry_date < b.entry_date ? 1 : -1
|
||||
);
|
||||
}
|
||||
|
||||
export type ReportSplitRow = { key: string; value: number; count: number };
|
||||
export type ReportRow = { key: string; value: number; count: number; people: ReportPerson[]; split?: ReportSplitRow[] };
|
||||
|
||||
@@ -367,7 +388,7 @@ export function aggregateReport(
|
||||
team: e.org_unit_id ? (lookups.teamName.get(e.org_unit_id) ?? "–") : "–",
|
||||
entry_date: e.entry_date,
|
||||
}));
|
||||
const row: ReportRow = { key, value, count: rowsForGroup.length, people };
|
||||
const row: ReportRow = { key, value, count: rowsForGroup.length, people: nachDatumAbsteigend(people) };
|
||||
if (split) {
|
||||
const bySplit = new Map<string, ReportEmployee[]>();
|
||||
for (const e of rowsForGroup) {
|
||||
@@ -545,7 +566,7 @@ export function aggregateEvents(
|
||||
team: e.org_unit_id ? (lookups.teamName.get(e.org_unit_id) ?? "–") : "–",
|
||||
entry_date: e.event_date,
|
||||
}));
|
||||
const row: ReportRow = { key, value: rowsForGroup.length, count: rowsForGroup.length, people };
|
||||
const row: ReportRow = { key, value: rowsForGroup.length, count: rowsForGroup.length, people: nachDatumAbsteigend(people) };
|
||||
if (split) {
|
||||
const bySplit = new Map<string, ReportEvent[]>();
|
||||
for (const e of rowsForGroup) {
|
||||
|
||||
@@ -25,9 +25,9 @@ describe("Das Verzeichnis", () => {
|
||||
});
|
||||
|
||||
it("bildet jeden Punkt aus dem Blatt ab", () => {
|
||||
// 25 vom Blatt, dazu „Firmenfahrzeug" als fachliche Ergänzung.
|
||||
expect(ONBOARDING_PUNKTE).toHaveLength(26);
|
||||
for (const key of ["dienstzettel", "meldezettel", "salmonellenbefund", "willkommensmappe", "webreise", "firmenfahrzeug"]) {
|
||||
// 25 vom Blatt, dazu „Firmenfahrzeug" und „Chip" als fachliche Ergänzungen.
|
||||
expect(ONBOARDING_PUNKTE).toHaveLength(27);
|
||||
for (const key of ["dienstzettel", "meldezettel", "salmonellenbefund", "willkommensmappe", "chip", "webreise", "firmenfahrzeug"]) {
|
||||
expect(punktZu(key), key).toBeDefined();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
measureValue,
|
||||
MEASURE_LABELS,
|
||||
messgroesseLabel,
|
||||
nachDatumAbsteigend,
|
||||
REPORT_PRESETS,
|
||||
GROUP_LABELS,
|
||||
type OrgLookups,
|
||||
@@ -337,6 +338,26 @@ describe("aggregateReport", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("nachDatumAbsteigend", () => {
|
||||
const person = (name: string, entry_date: string) => ({ id: name, name, title: "", team: "", entry_date });
|
||||
|
||||
it("stellt das jüngste Datum nach oben, bei gleichem Datum nach Namen", () => {
|
||||
const sortiert = nachDatumAbsteigend([
|
||||
person("Berger", "2019-03-01"),
|
||||
person("Zach", "2026-10-01"),
|
||||
person("Auer", "2026-10-01"),
|
||||
person("Moser", "2024-01-15"),
|
||||
]);
|
||||
expect(sortiert.map((p) => p.name)).toEqual(["Auer", "Zach", "Moser", "Berger"]);
|
||||
});
|
||||
|
||||
it("lässt die Eingabe unverändert", () => {
|
||||
const eingabe = [person("A", "2020-01-01"), person("B", "2021-01-01")];
|
||||
nachDatumAbsteigend(eingabe);
|
||||
expect(eingabe.map((p) => p.name)).toEqual(["A", "B"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveStatusAsOf", () => {
|
||||
const base = { entry_date: "2020-01-01", exit_date: null as string | null, karenz_start_date: null as string | null, karenz_return_date: null as string | null };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user