Files
alpenwerk-hr/components/shell/StandorteContext.tsx
Andrei Laas c6f617093f
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m1s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m40s
CI / Ausrollen (push) Successful in 6s
Versetzung mit Standortwechsel; Standort aenderbar ueber change_employee_data
- Versetzen: Feld "Standort", vorbelegt mit dem bisherigen. Ein anderer
  Standort wechselt zum selben Tag, in derselben Transaktion wie die
  Versetzung (sofort oder vorgemerkt).
- change_employee_data, Nachtlauf und Feldkarte kennen den Standort
  (Gruppe role): Historienzeile "Standort", berichtigbar und
  zuruecknehmbar. In der Historie steht die Kennung, angezeigt wird der
  Name (StandorteContext).

Rauchtest: Schritt 30.

Geprueft: lint, tsc, types:check, 949 Tests, Uebergabe-Waechter
2026-10-22 14:50:19 +02:00

29 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { createContext, useContext, type ReactNode } from "react";
// Die Standorte, einmal mit der Hülle geladen. Die Historie speichert beim
// Feld „Standort" die Kennung; angezeigt und gewählt wird der Name — wie bei
// der zuständigen HR (HrBenutzerContext).
export type StandortEintrag = { id: string; name: string };
/** Die Bezeichnung des Feldes in app_feld_karte und in der Historie. */
export const STANDORT_FELD = "Standort";
const StandorteContext = createContext<StandortEintrag[]>([]);
export function StandorteProvider({ standorte, children }: { standorte: StandortEintrag[]; children: ReactNode }) {
return <StandorteContext.Provider value={standorte}>{children}</StandorteContext.Provider>;
}
export function useStandorte(): StandortEintrag[] {
return useContext(StandorteContext);
}
/** Der Name zu einer Kennung; die Kennung selbst, wenn der Standort nicht mehr existiert. */
export function standortName(liste: StandortEintrag[], id: string | null | undefined): string {
if (!id) return "–";
return liste.find((s) => s.id === id)?.name ?? id;
}