From 36f352de58b19d160d8934aa3d545eda280d882f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20X=2E=20F=C3=BCrst?= Date: Fri, 27 Feb 2026 20:08:32 +0000 Subject: [PATCH] Auto --- components/AusgabenForm.tsx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/components/AusgabenForm.tsx b/components/AusgabenForm.tsx index 0e56bde..ca1f368 100644 --- a/components/AusgabenForm.tsx +++ b/components/AusgabenForm.tsx @@ -31,6 +31,10 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben const [month, setMonth] = useState(''); const [year, setYear] = useState(''); const [isLoadingStats, setIsLoadingStats] = useState(false); + + // Autocomplete data + const [autoCompleteWo, setAutoCompleteWo] = useState([]); + const [autoCompleteWas, setAutoCompleteWas] = useState([]); const fetchStats = useCallback(async (y: string, m: string) => { if (!y || !m) return; @@ -49,6 +53,19 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben } }, [typ]); + const fetchAutoComplete = useCallback(async () => { + try { + const response = await fetch(`/api/ausgaben/autocomplete?typ=${typ}`); + const data = await response.json(); + if (data.success) { + setAutoCompleteWo(data.data.wo); + setAutoCompleteWas(data.data.was); + } + } catch (error) { + console.error('Error fetching autocomplete data:', error); + } + }, [typ]); + // Initialize month/year on first load useEffect(() => { const now = new Date(); @@ -65,6 +82,11 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben } }, [month, year, typ, fetchStats]); + // Fetch autocomplete data when typ changes + useEffect(() => { + fetchAutoComplete(); + }, [typ, fetchAutoComplete]); + const handleMonthChange = (newMonth: string) => { setMonth(newMonth); }; @@ -248,8 +270,14 @@ export default function AusgabenForm({ onSuccess, selectedEntry, typ }: Ausgaben onChange={(e) => setFormData({ ...formData, Wo: e.target.value })} className="w-full px-2 py-1 text-base rounded border-2 border-gray-400 bg-white focus:border-blue-500 focus:outline-none" placeholder="Geschäft/Ort" + list="wo-suggestions" required /> + + {autoCompleteWo.map((wo, index) => ( + setFormData({ ...formData, Was: e.target.value })} className="w-full px-2 py-1 text-base rounded border-2 border-gray-400 bg-white focus:border-blue-500 focus:outline-none" placeholder="Beschreibung" + list="was-suggestions" required /> + + {autoCompleteWas.map((was, index) => ( +