chore: initial commit of HouseholdBudgetBook (backend, frontend, desktop)
This commit is contained in:
commit
4a5db3f1f9
167 files changed
+21732
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { api, ApiError } from '@/lib/api'
|
||||
import { queryKeys } from '@/lib/queryKeys'
|
||||
|
||||
export function useReports() {
|
||||
const fetchOverview = async (year: number, month: number, type: 'income' | 'expense' = 'expense') => {
|
||||
return api.getReportOverview(year, month, type)
|
||||
}
|
||||
|
||||
return { fetchOverview }
|
||||
}
|
||||
|
||||
export function useReportOverview(year: number, month: number, type: 'income' | 'expense') {
|
||||
const query = useQuery({
|
||||
queryKey: queryKeys.reports.overview(year, month, type),
|
||||
queryFn: () => api.getReportOverview(year, month, type),
|
||||
})
|
||||
|
||||
return {
|
||||
overview: query.data ?? null,
|
||||
loading: query.isLoading,
|
||||
error: query.error instanceof ApiError ? query.error.message : query.error ? '获取报表失败' : null,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user