From a8265b98220093a4c2b16d3fdd76cd4dfc22b0a3 Mon Sep 17 00:00:00 2001 From: Consultoria AS Date: Thu, 22 Jan 2026 02:28:06 +0000 Subject: [PATCH] feat(web): add dashboard API client and hooks Co-Authored-By: Claude Opus 4.5 --- apps/web/lib/api/dashboard.ts | 33 +++++++++++++++++++++++++++++ apps/web/lib/hooks/use-dashboard.ts | 30 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 apps/web/lib/api/dashboard.ts create mode 100644 apps/web/lib/hooks/use-dashboard.ts 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), + }); +}