fix(buchhaltung): prevent form reset on query refetch during transaction edit

This commit is contained in:
Matthias Hochmeister
2026-04-14 14:46:34 +02:00
parent 7392bfc29f
commit a94d486a42

View File

@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useRef } from 'react';
import { useParams, useNavigate, useSearchParams } from 'react-router-dom';
import { useQuery, useMutation } from '@tanstack/react-query';
import {
@@ -74,9 +74,12 @@ export default function BuchhaltungTransaktionForm() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [haushaltsjahre]);
// Pre-fill from existing transaction when editing
const hasPrefilled = useRef(false);
// Pre-fill from existing transaction when editing — only once
useEffect(() => {
if (existing) {
if (existing && !hasPrefilled.current) {
hasPrefilled.current = true;
setForm({
haushaltsjahr_id: existing.haushaltsjahr_id,
typ: existing.typ as 'einnahme' | 'ausgabe',