Finanzen: Einstellungen, Rechnungen am Kunden, InvoiceNinja aus der Oberflaeche entfernt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-01 15:12:18 +00:00
1 parent 24a3cc41ef
commit 2aacdb2d56
24 files changed
+1410 -499

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ export function useCustomers() {
const fetchCustomers = useCallback(async () => {
try {
// Direkt aus Appwrite: die Admin-API des Portals liefert gekuerzte Daten
// (ohne Stern und InvoiceNinja-Verknuepfung)
// (zum Beispiel ohne Stern)
const response = await databases.listDocuments(
DATABASE_ID,
COLLECTIONS.CUSTOMERS,
+36
View File
@@ -0,0 +1,36 @@
import { useCallback, useEffect, useRef, useState } from 'react'
/**
* Lädt eine Ressource der Finanzen-API (z. B. getSettings) und hält sie.
* data bleibt beim erneuten Laden stehen; error ist die Meldung des letzten fehlgeschlagenen Versuchs (leer, solange
* alles in Ordnung ist). reload() liefert ein Promise, das nie wirft; nur der jüngste Aufruf zählt.
*/
export function useFinanceResource(load, fallbackError) {
const [state, setState] = useState({ data: null, loading: true, error: '' })
const aliveRef = useRef(true)
const seqRef = useRef(0)
const loadRef = useRef(load)
loadRef.current = load
const reload = useCallback(async () => {
const mine = ++seqRef.current
const current = () => aliveRef.current && mine === seqRef.current
setState((s) => ({ ...s, loading: true, error: '' }))
try {
const data = await loadRef.current()
if (current()) setState({ data: data && typeof data === 'object' ? data : {}, loading: false, error: '' })
} catch (err) {
if (current()) setState((s) => ({ ...s, loading: false, error: err?.message || fallbackError }))
}
}, [fallbackError])
useEffect(() => {
aliveRef.current = true
reload()
return () => {
aliveRef.current = false
}
}, [reload])
return { ...state, reload }
}
-24
View File
@@ -1,24 +0,0 @@
import { useState, useEffect, useCallback } from 'react'
import { integrationsApi } from '../lib/integrationsApi'
export function useFinanceSummary() {
const [summary, setSummary] = useState(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState(null)
const load = useCallback(async () => {
setLoading(true)
setError(null)
try {
setSummary(await integrationsApi.invoicesSummary())
} catch (err) {
setError(err.message)
} finally {
setLoading(false)
}
}, [])
useEffect(() => { load() }, [load])
return { summary, loading, error, refresh: load }
}
-36
View File
@@ -1,36 +0,0 @@
import { useState, useEffect, useCallback } from 'react'
import { integrationsApi } from '../lib/integrationsApi'
/**
* Laedt die InvoiceNinja-Rechnungen eines verknuepften Clients.
* clientId = customers.invoiceNinjaClientId (oder null -> nichts laden).
*/
export function useInvoices(clientId) {
const [invoices, setInvoices] = useState([])
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
const fetchInvoices = useCallback(async () => {
if (!clientId) {
setInvoices([])
return
}
setLoading(true)
setError(null)
try {
const data = await integrationsApi.listInvoices(clientId)
setInvoices(data.invoices || [])
} catch (err) {
setError(err.message)
setInvoices([])
} finally {
setLoading(false)
}
}, [clientId])
useEffect(() => {
fetchInvoices()
}, [fetchInvoices])
return { invoices, loading, error, refresh: fetchInvoices }
}