bug fix for atemschutz
This commit is contained in:
@@ -68,10 +68,12 @@ 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 YYYY-MM-DD
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(iso)) return iso;
|
||||
// Full ISO timestamp — take the first 10 chars (YYYY-MM-DD)
|
||||
return iso.substring(0, 10);
|
||||
// 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 {
|
||||
@@ -255,17 +257,24 @@ function Atemschutz() {
|
||||
setForm((prev) => ({ ...prev, [field]: value }));
|
||||
};
|
||||
|
||||
/** Normalize dates before submit: ensure 4-digit years, drop invalid values */
|
||||
/** Normalize dates before submit: parse DD.MM.YYYY or YYYY-MM-DD → YYYY-MM-DD for API */
|
||||
const normalizeDate = (val: string | undefined): string | undefined => {
|
||||
if (!val) return undefined;
|
||||
// Match YYYY-MM-DD but with potentially short year
|
||||
const m = val.match(/^(\d{1,4})-(\d{2})-(\d{2})$/);
|
||||
if (!m) return undefined;
|
||||
const year = m[1].padStart(4, '0');
|
||||
// Reject obviously wrong years (< 1900 or > 2100)
|
||||
const y = parseInt(year, 10);
|
||||
if (y < 1900 || y > 2100) return undefined;
|
||||
return `${year}-${m[2]}-${m[3]}`;
|
||||
// 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 handleSubmit = async () => {
|
||||
@@ -643,10 +652,10 @@ function Atemschutz() {
|
||||
label="Lehrgang Datum"
|
||||
size="small"
|
||||
fullWidth
|
||||
placeholder="JJJJ-MM-TT"
|
||||
placeholder="TT.MM.JJJJ"
|
||||
value={form.lehrgang_datum}
|
||||
onChange={(e) => handleFormChange('lehrgang_datum', e.target.value)}
|
||||
helperText="Format: 2025-03-01"
|
||||
helperText="Format: 01.03.2025"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -662,10 +671,10 @@ function Atemschutz() {
|
||||
label="Untersuchung Datum"
|
||||
size="small"
|
||||
fullWidth
|
||||
placeholder="JJJJ-MM-TT"
|
||||
placeholder="TT.MM.JJJJ"
|
||||
value={form.untersuchung_datum}
|
||||
onChange={(e) => handleFormChange('untersuchung_datum', e.target.value)}
|
||||
helperText="Format: 2023-02-08"
|
||||
helperText="Format: 08.02.2023"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -674,10 +683,10 @@ function Atemschutz() {
|
||||
label="Gültig bis"
|
||||
size="small"
|
||||
fullWidth
|
||||
placeholder="JJJJ-MM-TT"
|
||||
placeholder="TT.MM.JJJJ"
|
||||
value={form.untersuchung_gueltig_bis}
|
||||
onChange={(e) => handleFormChange('untersuchung_gueltig_bis', e.target.value)}
|
||||
helperText="Format: 2028-02-08"
|
||||
helperText="Format: 08.02.2028"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -712,10 +721,10 @@ function Atemschutz() {
|
||||
label="Leistungstest Datum"
|
||||
size="small"
|
||||
fullWidth
|
||||
placeholder="JJJJ-MM-TT"
|
||||
placeholder="TT.MM.JJJJ"
|
||||
value={form.leistungstest_datum}
|
||||
onChange={(e) => handleFormChange('leistungstest_datum', e.target.value)}
|
||||
helperText="Format: 2025-08-25"
|
||||
helperText="Format: 25.08.2025"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
@@ -724,10 +733,10 @@ function Atemschutz() {
|
||||
label="Gültig bis"
|
||||
size="small"
|
||||
fullWidth
|
||||
placeholder="JJJJ-MM-TT"
|
||||
placeholder="TT.MM.JJJJ"
|
||||
value={form.leistungstest_gueltig_bis}
|
||||
onChange={(e) => handleFormChange('leistungstest_gueltig_bis', e.target.value)}
|
||||
helperText="Format: 2026-08-25"
|
||||
helperText="Format: 25.08.2026"
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user