Mitarbeiter:innen, Organisationsstruktur, Planstellen, Eintritt, Austritt, Versetzung, Befoerderung, Karenz, On- und Offboarding, Berichte, Massenimport und ein lueckenloser Nachweis jeder Aenderung. Next.js 16 mit React 19 und TypeScript, PostgreSQL 17 ueber Kysely, Anmeldung ueber Microsoft Entra ID. Die Fachlogik liegt in der Datenbank: rund dreissig PL/pgSQL-Funktionen fuehren eine Aenderung, ihren Historieneintrag und ihren Protokolleintrag in einer Transaktion aus. Die Zugriffsschranke ist Row Level Security, nicht die Oberflaeche. Betrieb auf Windows Server ohne Docker: ein fertiges Paket, ein Windows-Dienst, der IIS als HTTPS-Vorschaltung und zwei geplante Aufgaben. Siehe deploy/windows/README.md.
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from "react";
|
|
|
|
type ToastVariant = "success" | "error" | "info";
|
|
type ToastItem = { id: number; message: string; variant: ToastVariant };
|
|
type ToastContextValue = { showToast: (message: string, variant?: ToastVariant) => void };
|
|
|
|
const ToastContext = createContext<ToastContextValue | null>(null);
|
|
|
|
const VARIANT_STYLES: Record<ToastVariant, string> = {
|
|
success: "bg-success-text",
|
|
error: "bg-danger-solid",
|
|
info: "bg-info-text",
|
|
};
|
|
|
|
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);
|
|
}, []);
|
|
|
|
// 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.
|
|
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>
|
|
))}
|
|
</div>
|
|
</ToastContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useToast(): ToastContextValue {
|
|
const ctx = useContext(ToastContext);
|
|
if (!ctx) throw new Error("useToast must be used within a ToastProvider");
|
|
return ctx;
|
|
}
|