diff --git a/apps/web/lib/api/dashboard.ts b/apps/web/lib/api/dashboard.ts new file mode 100644 index 0000000..fb37a50 --- /dev/null +++ b/apps/web/lib/api/dashboard.ts @@ -0,0 +1,33 @@ +import { apiClient } from './client'; +import type { KpiData, IngresosEgresosData, ResumenFiscal, Alerta } from '@horux/shared'; + +export async function getKpis(año?: number, mes?: number): Promise { + const params = new URLSearchParams(); + if (año) params.set('año', año.toString()); + if (mes) params.set('mes', mes.toString()); + + const response = await apiClient.get(`/dashboard/kpis?${params}`); + return response.data; +} + +export async function getIngresosEgresos(año?: number): Promise { + const params = new URLSearchParams(); + if (año) params.set('año', año.toString()); + + const response = await apiClient.get(`/dashboard/ingresos-egresos?${params}`); + return response.data; +} + +export async function getResumenFiscal(año?: number, mes?: number): Promise { + const params = new URLSearchParams(); + if (año) params.set('año', año.toString()); + if (mes) params.set('mes', mes.toString()); + + const response = await apiClient.get(`/dashboard/resumen-fiscal?${params}`); + return response.data; +} + +export async function getAlertas(limit = 5): Promise { + const response = await apiClient.get(`/dashboard/alertas?limit=${limit}`); + return response.data; +} diff --git a/apps/web/lib/hooks/use-dashboard.ts b/apps/web/lib/hooks/use-dashboard.ts new file mode 100644 index 0000000..ea02a94 --- /dev/null +++ b/apps/web/lib/hooks/use-dashboard.ts @@ -0,0 +1,30 @@ +import { useQuery } from '@tanstack/react-query'; +import * as dashboardApi from '@/lib/api/dashboard'; + +export function useKpis(año?: number, mes?: number) { + return useQuery({ + queryKey: ['kpis', año, mes], + queryFn: () => dashboardApi.getKpis(año, mes), + }); +} + +export function useIngresosEgresos(año?: number) { + return useQuery({ + queryKey: ['ingresos-egresos', año], + queryFn: () => dashboardApi.getIngresosEgresos(año), + }); +} + +export function useResumenFiscal(año?: number, mes?: number) { + return useQuery({ + queryKey: ['resumen-fiscal', año, mes], + queryFn: () => dashboardApi.getResumenFiscal(año, mes), + }); +} + +export function useAlertas(limit = 5) { + return useQuery({ + queryKey: ['alertas', limit], + queryFn: () => dashboardApi.getAlertas(limit), + }); +}