new features, bookstack
This commit is contained in:
@@ -45,6 +45,7 @@ import { atemschutzApi } from '../services/atemschutz';
|
||||
import { membersService } from '../services/members';
|
||||
import { useNotification } from '../contexts/NotificationContext';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { toGermanDate, fromGermanDate } from '../utils/dateInput';
|
||||
import type {
|
||||
AtemschutzUebersicht,
|
||||
AtemschutzStats,
|
||||
@@ -66,17 +67,6 @@ function formatDate(iso: string | null): string {
|
||||
});
|
||||
}
|
||||
|
||||
/** Extract YYYY-MM-DD from an ISO timestamp or date string for <input type="date"> */
|
||||
function toInputDate(iso: string | null | undefined): string {
|
||||
if (!iso) return '';
|
||||
// Already DD.MM.YYYY
|
||||
if (/^\d{2}\.\d{2}\.\d{4}$/.test(iso)) return iso;
|
||||
// YYYY-MM-DD → DD.MM.YYYY
|
||||
const m = iso.match(/^(\d{4})-(\d{2})-(\d{2})/);
|
||||
if (m) return `${m[3]}.${m[2]}.${m[1]}`;
|
||||
return '';
|
||||
}
|
||||
|
||||
function getDisplayName(item: AtemschutzUebersicht): string {
|
||||
if (item.user_family_name || item.user_given_name) {
|
||||
return [item.user_family_name, item.user_given_name].filter(Boolean).join(', ');
|
||||
@@ -240,12 +230,12 @@ function Atemschutz() {
|
||||
setForm({
|
||||
user_id: item.user_id,
|
||||
atemschutz_lehrgang: item.atemschutz_lehrgang,
|
||||
lehrgang_datum: toInputDate(item.lehrgang_datum),
|
||||
untersuchung_datum: toInputDate(item.untersuchung_datum),
|
||||
untersuchung_gueltig_bis: toInputDate(item.untersuchung_gueltig_bis),
|
||||
lehrgang_datum: toGermanDate(item.lehrgang_datum),
|
||||
untersuchung_datum: toGermanDate(item.untersuchung_datum),
|
||||
untersuchung_gueltig_bis: toGermanDate(item.untersuchung_gueltig_bis),
|
||||
untersuchung_ergebnis: item.untersuchung_ergebnis || '',
|
||||
leistungstest_datum: toInputDate(item.leistungstest_datum),
|
||||
leistungstest_gueltig_bis: toInputDate(item.leistungstest_gueltig_bis),
|
||||
leistungstest_datum: toGermanDate(item.leistungstest_datum),
|
||||
leistungstest_gueltig_bis: toGermanDate(item.leistungstest_gueltig_bis),
|
||||
leistungstest_bestanden: item.leistungstest_bestanden || false,
|
||||
bemerkung: item.bemerkung || '',
|
||||
});
|
||||
@@ -267,24 +257,11 @@ function Atemschutz() {
|
||||
setForm((prev) => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
/** Normalize dates before submit: parse DD.MM.YYYY or YYYY-MM-DD → YYYY-MM-DD for API */
|
||||
/** Normalize dates before submit: parse DD.MM.YYYY → YYYY-MM-DD for API */
|
||||
const normalizeDate = (val: string | undefined): string | undefined => {
|
||||
if (!val) return undefined;
|
||||
// DD.MM.YYYY format (German)
|
||||
const dmy = val.match(/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/);
|
||||
if (dmy) {
|
||||
const y = parseInt(dmy[3], 10);
|
||||
if (y < 1900 || y > 2100) return undefined;
|
||||
return `${dmy[3]}-${dmy[2].padStart(2, '0')}-${dmy[1].padStart(2, '0')}`;
|
||||
}
|
||||
// YYYY-MM-DD format (ISO)
|
||||
const iso = val.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||
if (iso) {
|
||||
const y = parseInt(iso[1], 10);
|
||||
if (y < 1900 || y > 2100) return undefined;
|
||||
return val;
|
||||
}
|
||||
return undefined;
|
||||
const iso = fromGermanDate(val);
|
||||
return iso || undefined;
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
|
||||
Reference in New Issue
Block a user