V1.0.0 Es funktioniert soweit Alles

This commit is contained in:
2026-02-27 16:41:03 +00:00
parent 14bb3fd2cd
commit 5981a7a6db
4 changed files with 48 additions and 20 deletions

View File

@@ -21,7 +21,6 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: '',
Wie: defaultZahlungsart,
TYP: typ,
OK: 0,
});
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -95,26 +94,41 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: selectedEntry.Wieviel.toString(),
Wie: selectedEntry.Wie,
TYP: selectedEntry.TYP,
OK: selectedEntry.OK || 0,
});
setEditId(selectedEntry.ID);
// Handle both uppercase and lowercase ID field names
const entryId = (selectedEntry as any).id || selectedEntry.ID;
setEditId(entryId);
} else {
// Initialize with current date for new entry
// Reset form for new entry
const now = new Date();
const dateStr = now.toISOString().split('T')[0];
const weekday = getWeekday(now);
setFormData(prev => ({
...prev,
setFormData({
Datum: dateStr,
WochTag: weekday,
Wo: '',
Was: '',
Wieviel: '',
Wie: defaultZahlungsart,
TYP: typ,
}));
});
setEditId(null);
}
}, [selectedEntry, typ]);
}, [selectedEntry]);
// Update TYP when tab changes
useEffect(() => {
if (!selectedEntry) {
setFormData(prev => ({
...prev,
TYP: typ,
Wie: defaultZahlungsart,
}));
}
}, [typ]);
const getWeekday = (date: Date): string => {
const weekdays = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
@@ -143,12 +157,22 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
const url = editId ? `/api/ausgaben/${editId}` : '/api/ausgaben';
const method = editId ? 'PUT' : 'POST';
// Send only the fields we need, excluding any extra fields
const dataToSend = {
Datum: formData.Datum,
Wo: formData.Wo,
Was: formData.Was,
Wieviel: formData.Wieviel,
Wie: formData.Wie,
TYP: formData.TYP,
};
const response = await fetch(url, {
method: method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
body: JSON.stringify(dataToSend),
});
if (response.ok) {
@@ -180,7 +204,7 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben
Wieviel: '',
Wie: defaultZahlungsart,
TYP: typ,
OK: 0,
});
setEditId(null);