Übergabestand 2026-10-14

Alpenwerk HR — HR-Stammdatenverwaltung

Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt,
Versetzung, Beförderung, Karenz, On- und Offboarding, Berichte, Exporte,
Massenimport und ein lückenloser Nachweis jeder Änderung.

Next.js 16, React 19 und TypeScript; PostgreSQL über Kysely; Anmeldung
ausschliesslich über Microsoft Entra ID. Die Fachlogik liegt in der
Datenbank, die Zugriffsschranke ist Row Level Security.

Betrieb auf Windows Server: siehe deploy/windows/README.md.
Sicherheitskonzept: docs/sicherheitskonzept.md.
This commit is contained in:
2026-10-14 10:12:22 +02:00
commit b47dec6387
410 changed files with 73368 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
"use client";
import { useCallback, useState, type ReactNode } from "react";
import type { OpenNote } from "@/lib/notes";
import { Sidebar } from "./Sidebar";
import { Topbar } from "./Topbar";
// Owns the one piece of state the shell needs (is the mobile drawer open),
// so app/(app)/layout.tsx can stay a Server Component and keep doing its
// auth check and data loading on the server.
export function AppShell({
userLabel,
openNotes,
kollegen,
children,
}: {
userLabel: string;
openNotes: OpenNote[];
kollegen: { id: string; name: string; sichtbar: boolean }[];
children: ReactNode;
}) {
const [navOpen, setNavOpen] = useState(false);
const closeNav = useCallback(() => setNavOpen(false), []);
// Auf Papier gehört von der Hülle nichts hin: Navigation, Glocke und
// Abmelde-Knopf sind Bedienelemente, und gedruckt sind sie bestenfalls
// Zierrat — auf einer Checkliste, die in eine Personalakte geht, sogar
// irreführend. Die Regel steht hier und nicht auf der einzelnen Druckseite,
// damit jede weitere sie mitbekommt, statt sie zu wiederholen.
//
// Auch die Ränder fallen weg: die Satzfläche bestimmt @page auf der
// Druckseite selbst, und die Polsterung der Hülle käme obendrauf.
return (
<div className="min-h-dvh print:min-h-0">
<div className="print:hidden">
<Sidebar open={navOpen} onClose={closeNav} />
</div>
<div className="flex min-h-dvh flex-col lg:ml-[236px] print:ml-0 print:block print:min-h-0">
<div className="print:hidden">
<Topbar userLabel={userLabel} openNotes={openNotes} kollegen={kollegen} onOpenNav={() => setNavOpen(true)} />
</div>
<main className="flex-1 px-4 py-4 pb-[max(1rem,env(safe-area-inset-bottom))] sm:px-6 sm:py-6 print:p-0">
<div className="mx-auto w-full max-w-[1280px] print:max-w-none">{children}</div>
</main>
</div>
</div>
);
}

View File

@@ -0,0 +1,39 @@
"use client";
import { createContext, useContext, type ReactNode } from "react";
import type { HrBenutzer } from "@/lib/shell-data";
// Die HR-Konten für das Feld „Zuständige HR". Geladen einmal mit der Hülle
// (lib/shell-data.ts) und hier verteilt — an den Einstellungsassistenten, an
// „Daten ändern", an die Akte und an die Historie, die aus einer Kennung
// wieder einen Namen macht.
const HrBenutzerContext = createContext<HrBenutzer[]>([]);
export function HrBenutzerProvider({ hrBenutzer, children }: { hrBenutzer: HrBenutzer[]; children: ReactNode }) {
return <HrBenutzerContext.Provider value={hrBenutzer}>{children}</HrBenutzerContext.Provider>;
}
export function useHrBenutzer(): HrBenutzer[] {
return useContext(HrBenutzerContext);
}
/** Der Name zu einer Kennung; „–" ohne Zuordnung, die Kennung selbst, wenn das Konto nicht mehr existiert. */
export function hrName(liste: HrBenutzer[], id: string | null | undefined): string {
if (!id) return "–";
return liste.find((h) => h.id === id)?.name ?? id;
}
/**
* Die Auswahl: alle aktiven Konten, dazu die aktuelle Zuordnung, auch wenn
* ihr Konto bereits abgeschaltet ist — sonst stünde im Feld nichts, und
* ein Speichern löschte die Zuordnung, ohne dass es jemand gewollt hätte.
*/
export function hrOptionen(liste: HrBenutzer[], aktuell: string): { value: string; label: string }[] {
return [
{ value: "", label: "– nicht zugeordnet –" },
...liste
.filter((h) => h.aktiv || h.id === aktuell)
.map((h) => ({ value: h.id, label: h.aktiv ? h.name : `${h.name} (Konto abgeschaltet)` })),
];
}

View File

@@ -0,0 +1,19 @@
"use client";
import { Plus } from "lucide-react";
import { useHireWizard } from "@/components/hire/HireWizardContext";
import { Button } from "@/components/ui/Button";
export function NewHireButton() {
const { openWizard } = useHireWizard();
return (
<Button size="sm" onClick={() => openWizard()}>
<Plus className="h-4 w-4" />
{/* The label is the first thing worth dropping on a narrow bar; the
icon plus the accessible name carry it from there. */}
<span className="hidden sm:inline">Neueinstellung</span>
<span className="sr-only sm:hidden">Neueinstellung</span>
</Button>
);
}

View File

@@ -0,0 +1,177 @@
"use client";
import { Bell, Users } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { completeEmployeeNote } from "@/actions/employees";
import { setNotizSichtbarkeit } from "@/actions/notes";
import { useToast } from "@/components/ui/Toast";
import { NOTE_CATEGORY_STYLES } from "@/lib/colors";
import { fmtDate } from "@/lib/format";
import type { OpenNote } from "@/lib/notes";
export type Kollege = { id: string; name: string; sichtbar: boolean };
// Click-outside mechanics borrowed from CountryPicker (useRef + mousedown
// listener) — without its draft-text reset, which has no equivalent here.
export function NotesBell({ notes, kollegen }: { notes: OpenNote[]; kollegen: Kollege[] }) {
const { showToast } = useToast();
const router = useRouter();
const [open, setOpen] = useState(false);
const [completingId, setCompletingId] = useState<string | null>(null);
const [zeigeEinstellung, setZeigeEinstellung] = useState(false);
// Der Haken springt sofort um und wird zurückgedreht, wenn das Speichern
// scheitert. Ohne das fühlt sich jeder Klick wie eine halbe Sekunde
// Bedenkzeit an — die Liste wird beim Durchgehen mehrfach angetippt.
const [eigen, setEigen] = useState<Record<string, boolean>>({});
const containerRef = useRef<HTMLDivElement>(null);
const sichtbarkeit = (k: Kollege) => eigen[k.id] ?? k.sichtbar;
const dazugewaehlt = kollegen.filter((k) => sichtbarkeit(k)).length;
async function schalte(k: Kollege) {
const neu = !sichtbarkeit(k);
setEigen((v) => ({ ...v, [k.id]: neu }));
const result = await setNotizSichtbarkeit({ kollegeId: k.id, sichtbar: neu });
if (result.success) {
router.refresh();
} else {
setEigen((v) => ({ ...v, [k.id]: !neu }));
showToast(result.error ?? "Fehler beim Speichern.", "error");
}
}
useEffect(() => {
function onClickOutside(e: MouseEvent) {
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
setOpen(false);
}
}
document.addEventListener("mousedown", onClickOutside);
return () => document.removeEventListener("mousedown", onClickOutside);
}, []);
async function handleComplete(note: OpenNote) {
setCompletingId(note.id);
const result = await completeEmployeeNote({ note_id: note.id, employee_id: note.employee_id });
setCompletingId(null);
if (result.success) {
showToast("Notiz erledigt.");
router.refresh();
} else {
showToast(result.error ?? "Fehler beim Speichern.", "error");
}
}
return (
<div ref={containerRef} className="relative">
{/* brand-700 statt ink-muted: die Glocke sitzt im rosa Markenband der
Kopfzeile, und ink-muted kommt darauf nur auf 2.33:1. */}
<button type="button" onClick={() => setOpen((o) => !o)} aria-label="Meine Notizen" className="relative rounded p-1.5 text-brand-700 hover:bg-accent-100">
<Bell className="h-4 w-4" />
{notes.length > 0 && (
// danger-text statt danger-solid: als Flaeche auf dem rosa Band kaeme
// das hellere Rot nur auf 2.78:1 und bliebe damit unter den 3:1, die
// WCAG 1.4.11 fuer ein bedeutungstragendes Element verlangt. Der
// dunklere Ton derselben Familie erreicht 3.26:1, und die Ziffer
// darin steht mit 7.12:1.
<span className="absolute -right-1 -top-1 flex h-4 min-w-4 items-center justify-center rounded-full bg-danger-text px-1 text-[10px] font-bold text-white">
{notes.length}
</span>
)}
</button>
{open && (
<div className="absolute right-0 z-20 mt-2 max-h-[28rem] w-96 overflow-y-auto rounded border border-border bg-white shadow-[var(--shadow-card-hover)]">
<div className="flex items-center justify-between gap-2 border-b border-border px-4 py-2.5">
<span className="text-xs font-bold uppercase tracking-wide text-ink-muted">
Meine Notizen ({notes.length})
</span>
<button
type="button"
onClick={() => setZeigeEinstellung((v) => !v)}
aria-expanded={zeigeEinstellung}
className={`flex items-center gap-1 rounded px-1.5 py-0.5 text-xs font-semibold hover:bg-surface focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500 ${
zeigeEinstellung ? "text-brand-700" : "text-ink-muted"
}`}
>
<Users className="h-3.5 w-3.5" />
Kolleg:innen
{/* Nur wenn jemand dazugewählt ist: eine „0" bei jedem
Aufschlagen zu lesen, sagt nichts. */}
{dazugewaehlt > 0 && <span className="text-brand-700">+{dazugewaehlt}</span>}
</button>
</div>
{zeigeEinstellung && (
<div className="border-b border-border bg-surface px-4 py-3">
{/* Dass die Auswahl auch die Entwürfe auf der Übersicht
steuert, steht hier und nicht nur dort: sie wird hier
getroffen, und eine Wirkung, die zwei Klicks entfernt
sichtbar wird, sucht sonst niemand. */}
<p className="mb-2 text-xs text-ink-muted">
Wessen Notizen hier und wessen Entwürfe auf der Übersicht zusätzlich erscheinen. Die
eigenen sind immer dabei.
</p>
{kollegen.length === 0 ? (
<p className="py-2 text-sm text-ink-muted">Keine weiteren HR-Kolleg:innen freigeschaltet.</p>
) : (
<ul className="flex flex-col gap-1">
{kollegen.map((k) => (
<li key={k.id}>
<label className="flex cursor-pointer items-center gap-2 rounded px-1 py-1 text-sm hover:bg-white">
<input
type="checkbox"
checked={sichtbarkeit(k)}
onChange={() => schalte(k)}
className="h-4 w-4 rounded border-border text-brand-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-500"
/>
<span className={sichtbarkeit(k) ? "text-ink" : "text-ink-muted line-through"}>{k.name}</span>
</label>
</li>
))}
</ul>
)}
</div>
)}
{notes.length === 0 ? (
<p className="px-4 py-6 text-center text-sm text-ink-muted">Keine offenen Notizen.</p>
) : (
<ul className="divide-y divide-border">
{notes.map((n) => (
<li key={n.id} className="px-4 py-3">
<div className="flex flex-wrap items-center gap-2">
<span className={`rounded-full px-2 py-0.5 text-xs font-semibold ${NOTE_CATEGORY_STYLES[n.category]}`}>{n.category}</span>
<Link href={`/employees/${n.employee_id}`} className="text-sm font-semibold text-ink hover:text-brand-700 hover:underline">
{n.employeeName}
</Link>
<span className="text-xs text-ink-muted">{fmtDate(n.created_at)}</span>
</div>
<p className="mt-1 text-sm text-ink-body">{n.note_text}</p>
{/* Von wem die Notiz stammt. Sichtbar sind die eigenen und
die hinzugewählten — ohne diese Zeile wäre nicht zu
unterscheiden, welche davon man gerade liest. „Ich"
statt des eigenen Namens: den kennt man. */}
<p className="mt-1 text-xs text-ink-muted">
{n.vonMir ? "von mir" : `von ${n.author_name}`}
</p>
{n.due_date && <p className="mt-1 text-xs text-warning-text">🔔 fällig {fmtDate(n.due_date)}</p>}
<button
type="button"
onClick={() => handleComplete(n)}
disabled={completingId === n.id}
className="mt-2 text-xs font-semibold text-success-text hover:underline disabled:opacity-50"
>
✓ Erledigt
</button>
</li>
))}
</ul>
)}
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,104 @@
"use client";
import { BarChart3, Building2, History, LayoutGrid, Network, Upload, Users, X } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
import { AppWortmarke } from "@/components/brand/Logo";
const NAV_ITEMS = [
{ href: "/", label: "Übersicht", icon: LayoutGrid },
{ href: "/employees", label: "Mitarbeiter:innen", icon: Users },
{ href: "/orgchart", label: "Organigramm", icon: Network },
{ href: "/positions", label: "Positionen", icon: Building2 },
{ href: "/reports", label: "Berichte", icon: BarChart3 },
// „Geplante Änderungen" steht bewusst nicht hier, sondern als zweiter Reiter
// im Audit-Log (/audit/geplant). Beide Seiten beantworten dieselbe Frage —
// was mit den Daten geschieht —, das Log rückwärts, die andere vorwärts.
// Zwei Einträge in der Leiste liessen sie wie zwei Themen aussehen.
{ href: "/audit", label: "Audit-Log", icon: History },
{ href: "/import", label: "Import", icon: Upload },
] as const;
export function isActiveRoute(pathname: string, href: string): boolean {
return href === "/" ? pathname === "/" : pathname.startsWith(href);
}
// Permanent rail from lg up, slide-in drawer below it. Same markup either
// way — the breakpoint only changes how the <nav> is positioned — so the
// nav list has exactly one definition.
export function Sidebar({ open, onClose }: { open: boolean; onClose: () => void }) {
const pathname = usePathname();
// A route change means the user tapped a nav item; the drawer has to get
// out of the way on its own, since it covers the page it just navigated to.
useEffect(() => {
onClose();
}, [pathname, onClose]);
useEffect(() => {
if (!open) return;
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose();
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [open, onClose]);
return (
<>
<div
onClick={onClose}
aria-hidden
className={`fixed inset-0 z-40 bg-black/40 transition-opacity lg:hidden ${
open ? "opacity-100" : "pointer-events-none opacity-0"
}`}
/>
<nav
aria-label="Hauptnavigation"
className={`fixed left-0 top-0 z-50 flex h-dvh w-[264px] flex-col border-r border-border bg-white transition-transform duration-200 lg:z-30 lg:w-[236px] lg:translate-x-0 ${
open ? "translate-x-0" : "-translate-x-full"
}`}
>
{/* pl-2 statt pl-5: der Freiraum des Logos bringt seinen eigenen
Abstand mit (siehe components/brand/Logo.tsx), und beides
uebereinander schoebe die Wortmarke sichtbar aus der Flucht der
Navigationspunkte darunter. */}
{/* Rosa wie die Kopfzeile daneben: beide zusammen sind ein
durchgehendes Band ueber der Anwendung, in dem das Logo mit seinem
eigenen rosa Feld aufgeht statt als Rechteck darauf zu liegen. */}
<div className="flex h-14 shrink-0 items-center justify-between border-b border-accent-600/40 bg-accent-500 pl-2 pr-3">
<AppWortmarke hoehe={24} aufRosa textKlasse="text-brand-700" />
<button
type="button"
onClick={onClose}
aria-label="Navigation schließen"
className="-mr-1 rounded p-2 text-brand-700 hover:bg-accent-100 lg:hidden"
>
<X className="h-5 w-5" />
</button>
</div>
{/* pb keeps the last item clear of the iOS home indicator. */}
<ul className="flex-1 space-y-1 overflow-y-auto px-3 py-4 pb-[max(1rem,env(safe-area-inset-bottom))]">
{NAV_ITEMS.map(({ href, label, icon: Icon }) => {
const active = isActiveRoute(pathname, href);
return (
<li key={href}>
<Link
href={href}
aria-current={active ? "page" : undefined}
className={`flex items-center gap-3 rounded px-3 py-2.5 text-sm font-semibold transition-colors ${
active ? "bg-brand-100 text-brand-700" : "text-ink-body hover:bg-surface"
}`}
>
<Icon className="h-4 w-4 shrink-0" />
{label}
</Link>
</li>
);
})}
</ul>
</nav>
</>
);
}

View File

@@ -0,0 +1,83 @@
"use client";
import { LogOut, Menu } from "lucide-react";
import { usePathname } from "next/navigation";
import { logout } from "@/actions/auth";
import type { OpenNote } from "@/lib/notes";
import { NewHireButton } from "./NewHireButton";
import { NotesBell } from "./NotesBell";
const TITLES: Record<string, string> = {
"/": "Übersicht",
"/employees": "Mitarbeiter:innen",
"/orgchart": "Organigramm",
"/positions": "Positionen",
"/reports": "Berichte",
// Vor "/audit" eingetragen und nicht danach: titleFor sucht den ersten
// Schlüssel, der Präfix des Pfades ist, und "/audit" wäre für
// "/audit/geplant" ebenfalls einer. Die Reihenfolge entscheidet.
"/audit/geplant": "Geplante Änderungen",
"/audit": "Audit-Log",
};
function titleFor(pathname: string): string {
if (TITLES[pathname]) return TITLES[pathname];
const match = Object.keys(TITLES).find((key) => key !== "/" && pathname.startsWith(key));
return match ? TITLES[match] : "Alpenwerk HR";
}
type TopbarProps = {
userLabel: string;
openNotes: OpenNote[];
kollegen: { id: string; name: string; sichtbar: boolean }[];
onOpenNav: () => void;
};
export function Topbar({ userLabel, openNotes, kollegen, onOpenNav }: TopbarProps) {
const pathname = usePathname();
return (
// Sticky, with the notch inset added to its top padding: on an iPhone in
// landscape the bar would otherwise sit under the rounded corner.
//
// Rosa und nicht Weiss: zusammen mit dem Kopf der Seitenleiste bildet
// dieser Streifen das durchgehende Markenband ueber der Anwendung. Auf
// Weiss stuende das Logo daneben als ausgeschnittenes Rechteck, weil es
// sein rosa Feld mitbringt; in einem rosa Band geht es darin auf.
//
// Geschrieben wird darauf in brand-700 und nicht in ink: Schwarz auf Rosa
// traegt zwar (7.47:1), sieht aber aus wie Text, der aus Versehen auf der
// Marke gelandet ist. Dunkelblau auf Rosa ist dieselbe Paarung, aus der
// der Schriftzug selbst besteht, und kommt auf 6.60:1.
//
// Gedaempftes gibt es hier nicht: ink-muted liegt auf Rosa bei
// 2.33:1. Gestuft wird ueber Groesse und Gewicht.
<header className="sticky top-0 z-20 flex h-14 shrink-0 items-center justify-between border-b border-accent-600/40 bg-accent-500 px-3 pt-[env(safe-area-inset-top)] sm:px-6">
<div className="flex min-w-0 items-center gap-2">
<button
type="button"
onClick={onOpenNav}
aria-label="Navigation öffnen"
className="-ml-1 rounded p-2 text-brand-700 hover:bg-accent-100 lg:hidden"
>
<Menu className="h-5 w-5" />
</button>
<h1 className="truncate text-base font-bold text-brand-700">{titleFor(pathname)}</h1>
</div>
<div className="flex shrink-0 items-center gap-1 sm:gap-4">
<NotesBell notes={openNotes} kollegen={kollegen} />
<NewHireButton />
<div className="flex items-center gap-2 text-sm sm:border-l sm:border-brand-700/25 sm:pl-4">
{/* The name is the first thing worth dropping on a narrow screen —
the account is still reachable via the sign-out control. */}
<span className="hidden font-semibold text-brand-700 md:inline">{userLabel}</span>
<form action={logout}>
<button type="submit" aria-label="Abmelden" className="rounded p-2 text-brand-700 hover:bg-accent-100">
<LogOut className="h-4 w-4" />
</button>
</form>
</div>
</div>
</header>
);
}