fix: invalidate kontenTree cache on konto mutations, remove Kontotyp field from dialog
This commit is contained in:
@@ -196,7 +196,6 @@ function KontoDialog({
|
|||||||
konten: Konto[];
|
konten: Konto[];
|
||||||
onSave: (data: KontoFormData) => void;
|
onSave: (data: KontoFormData) => void;
|
||||||
}) {
|
}) {
|
||||||
const { data: kontoTypen = [] } = useQuery({ queryKey: ['konto-typen'], queryFn: buchhaltungApi.getKontoTypen });
|
|
||||||
const empty: KontoFormData = { haushaltsjahr_id: haushaltsjahrId, kontonummer: '', bezeichnung: '', budget_gwg: 0, budget_anlagen: 0, budget_instandhaltung: 0, parent_id: null, notizen: '' };
|
const empty: KontoFormData = { haushaltsjahr_id: haushaltsjahrId, kontonummer: '', bezeichnung: '', budget_gwg: 0, budget_anlagen: 0, budget_instandhaltung: 0, parent_id: null, notizen: '' };
|
||||||
const [form, setForm] = useState<KontoFormData>(empty);
|
const [form, setForm] = useState<KontoFormData>(empty);
|
||||||
|
|
||||||
@@ -221,7 +220,7 @@ function KontoDialog({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (existing) {
|
if (existing) {
|
||||||
setForm({ haushaltsjahr_id: haushaltsjahrId, konto_typ_id: existing.konto_typ_id ?? undefined, kontonummer: existing.kontonummer, bezeichnung: existing.bezeichnung, budget_gwg: existing.budget_gwg, budget_anlagen: existing.budget_anlagen, budget_instandhaltung: existing.budget_instandhaltung, parent_id: existing.parent_id, notizen: existing.notizen || '' });
|
setForm({ haushaltsjahr_id: haushaltsjahrId, kontonummer: existing.kontonummer, bezeichnung: existing.bezeichnung, budget_gwg: existing.budget_gwg, budget_anlagen: existing.budget_anlagen, budget_instandhaltung: existing.budget_instandhaltung, parent_id: existing.parent_id, notizen: existing.notizen || '' });
|
||||||
} else {
|
} else {
|
||||||
setForm({ ...empty, haushaltsjahr_id: haushaltsjahrId });
|
setForm({ ...empty, haushaltsjahr_id: haushaltsjahrId });
|
||||||
}
|
}
|
||||||
@@ -245,13 +244,6 @@ function KontoDialog({
|
|||||||
helperText={parentPrefix ? `Vollständige Nummer: ${form.kontonummer || parentPrefix + '…'}` : undefined}
|
helperText={parentPrefix ? `Vollständige Nummer: ${form.kontonummer || parentPrefix + '…'}` : undefined}
|
||||||
/>
|
/>
|
||||||
<TextField label="Bezeichnung" value={form.bezeichnung} onChange={e => setForm(f => ({ ...f, bezeichnung: e.target.value }))} required />
|
<TextField label="Bezeichnung" value={form.bezeichnung} onChange={e => setForm(f => ({ ...f, bezeichnung: e.target.value }))} required />
|
||||||
<FormControl fullWidth>
|
|
||||||
<InputLabel>Kontotyp</InputLabel>
|
|
||||||
<Select value={form.konto_typ_id ?? ''} label="Kontotyp" onChange={e => setForm(f => ({ ...f, konto_typ_id: e.target.value ? Number(e.target.value) : undefined }))}>
|
|
||||||
<MenuItem value=""><em>Kein Typ</em></MenuItem>
|
|
||||||
{kontoTypen.map(kt => <MenuItem key={kt.id} value={kt.id}>{kt.bezeichnung}</MenuItem>)}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
|
||||||
<FormControl fullWidth margin="dense">
|
<FormControl fullWidth margin="dense">
|
||||||
<InputLabel>Elternkonto (optional)</InputLabel>
|
<InputLabel>Elternkonto (optional)</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
@@ -486,7 +478,6 @@ function KontoManageRow({ konto, depth = 0, canManage, onEdit, onDelete }: {
|
|||||||
<Typography variant="body2">{konto.kontonummer} — {konto.bezeichnung}</Typography>
|
<Typography variant="body2">{konto.kontonummer} — {konto.bezeichnung}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{konto.konto_typ_bezeichnung || '–'}</TableCell>
|
|
||||||
<TableCell align="right">{fmtEur(konto.budget_gwg)}</TableCell>
|
<TableCell align="right">{fmtEur(konto.budget_gwg)}</TableCell>
|
||||||
<TableCell align="right">{fmtEur(konto.budget_anlagen)}</TableCell>
|
<TableCell align="right">{fmtEur(konto.budget_anlagen)}</TableCell>
|
||||||
<TableCell align="right">{fmtEur(konto.budget_instandhaltung)}</TableCell>
|
<TableCell align="right">{fmtEur(konto.budget_instandhaltung)}</TableCell>
|
||||||
@@ -1000,17 +991,17 @@ function KontenTab({ haushaltsjahre, selectedJahrId, onJahrChange }: {
|
|||||||
|
|
||||||
const createKontoMut = useMutation({
|
const createKontoMut = useMutation({
|
||||||
mutationFn: buchhaltungApi.createKonto,
|
mutationFn: buchhaltungApi.createKonto,
|
||||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); setKontoDialog({ open: false }); showSuccess('Konto erstellt'); },
|
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); qc.invalidateQueries({ queryKey: ['kontenTree'] }); setKontoDialog({ open: false }); showSuccess('Konto erstellt'); },
|
||||||
onError: () => showError('Konto konnte nicht erstellt werden'),
|
onError: () => showError('Konto konnte nicht erstellt werden'),
|
||||||
});
|
});
|
||||||
const updateKontoMut = useMutation({
|
const updateKontoMut = useMutation({
|
||||||
mutationFn: ({ id, data }: { id: number; data: Partial<KontoFormData> }) => buchhaltungApi.updateKonto(id, data),
|
mutationFn: ({ id, data }: { id: number; data: Partial<KontoFormData> }) => buchhaltungApi.updateKonto(id, data),
|
||||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); setKontoDialog({ open: false }); showSuccess('Konto aktualisiert'); },
|
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); qc.invalidateQueries({ queryKey: ['kontenTree'] }); setKontoDialog({ open: false }); showSuccess('Konto aktualisiert'); },
|
||||||
onError: () => showError('Konto konnte nicht aktualisiert werden'),
|
onError: () => showError('Konto konnte nicht aktualisiert werden'),
|
||||||
});
|
});
|
||||||
const deleteKontoMut = useMutation({
|
const deleteKontoMut = useMutation({
|
||||||
mutationFn: buchhaltungApi.deleteKonto,
|
mutationFn: buchhaltungApi.deleteKonto,
|
||||||
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); showSuccess('Konto deaktiviert'); },
|
onSuccess: () => { qc.invalidateQueries({ queryKey: ['buchhaltung-konten'] }); qc.invalidateQueries({ queryKey: ['kontenTree'] }); showSuccess('Konto deaktiviert'); },
|
||||||
onError: () => showError('Löschen fehlgeschlagen'),
|
onError: () => showError('Löschen fehlgeschlagen'),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1088,7 +1079,6 @@ function KontenTab({ haushaltsjahre, selectedJahrId, onJahrChange }: {
|
|||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell>Konto</TableCell>
|
<TableCell>Konto</TableCell>
|
||||||
<TableCell>Typ</TableCell>
|
|
||||||
<TableCell align="right">GWG</TableCell>
|
<TableCell align="right">GWG</TableCell>
|
||||||
<TableCell align="right">Anlagen</TableCell>
|
<TableCell align="right">Anlagen</TableCell>
|
||||||
<TableCell align="right">Instandh.</TableCell>
|
<TableCell align="right">Instandh.</TableCell>
|
||||||
@@ -1097,7 +1087,7 @@ function KontenTab({ haushaltsjahre, selectedJahrId, onJahrChange }: {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{kontenTree.length === 0 && <TableRow><TableCell colSpan={canManage ? 7 : 6} align="center"><Typography color="text.secondary">Keine Konten</Typography></TableCell></TableRow>}
|
{kontenTree.length === 0 && <TableRow><TableCell colSpan={canManage ? 6 : 5} align="center"><Typography color="text.secondary">Keine Konten</Typography></TableCell></TableRow>}
|
||||||
{kontenTree.map(k => (
|
{kontenTree.map(k => (
|
||||||
<KontoManageRow
|
<KontoManageRow
|
||||||
key={k.id}
|
key={k.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user