Datumsformat konfigurierbar (Einstellungen -> Darstellung)
MHD wurde in den Ansichten noch roh als YYYY-MM-DD ausgegeben. Jetzt: - Neue Einstellung date_format (23.12.2026 | 23.12.26 | 23. Dezember 2026 | 2026-12-23 | 12/23/2026) mit Live-Beispiel auf der Einstellungsseite. - SettingsProvider stellt Format und formatDate() app-weit bereit und laedt die Einstellungen nach dem Login. - Verwendet in Uebersicht (bald ablaufend), Produktdetail (Chargen) und Auslagern (Chargenauswahl). Datumsfelder zur Eingabe bleiben ISO, wie es das HTML-Datumsfeld verlangt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
45
web/src/settings.jsx
Normal file
45
web/src/settings.jsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
||||
import { api } from "./api";
|
||||
import { useAuth } from "./auth";
|
||||
import { formatDate } from "./units";
|
||||
|
||||
export const DATE_FORMAT_KEY = "date_format";
|
||||
const DEFAULT_FORMAT = "de";
|
||||
|
||||
const SettingsContext = createContext({
|
||||
dateFormat: DEFAULT_FORMAT,
|
||||
formatDate: (iso) => formatDate(iso, DEFAULT_FORMAT),
|
||||
reload: () => {},
|
||||
});
|
||||
|
||||
/** Lädt die anzeigerelevanten Einstellungen einmal nach dem Login. */
|
||||
export function SettingsProvider({ children }) {
|
||||
const { user } = useAuth();
|
||||
const [dateFormat, setDateFormat] = useState(DEFAULT_FORMAT);
|
||||
|
||||
const reload = useCallback(async () => {
|
||||
try {
|
||||
const rows = await api.listSettings();
|
||||
const row = rows.find((r) => r.key === DATE_FORMAT_KEY);
|
||||
setDateFormat(row?.value || DEFAULT_FORMAT);
|
||||
} catch {
|
||||
/* Einstellungen sind optional – Standard bleibt bestehen. */
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (user) reload();
|
||||
}, [user, reload]);
|
||||
|
||||
const value = {
|
||||
dateFormat,
|
||||
formatDate: (iso) => formatDate(iso, dateFormat),
|
||||
reload,
|
||||
};
|
||||
|
||||
return <SettingsContext.Provider value={value}>{children}</SettingsContext.Provider>;
|
||||
}
|
||||
|
||||
export function useSettings() {
|
||||
return useContext(SettingsContext);
|
||||
}
|
||||
Reference in New Issue
Block a user