- 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
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
"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;
|
||
}
|