feat(web): add dashboard API client and hooks

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Consultoria AS
2026-01-22 02:28:06 +00:00
parent ccfc795d41
commit a8265b9822
2 changed files with 63 additions and 0 deletions

View File

@@ -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<KpiData> {
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<KpiData>(`/dashboard/kpis?${params}`);
return response.data;
}
export async function getIngresosEgresos(año?: number): Promise<IngresosEgresosData[]> {
const params = new URLSearchParams();
if (año) params.set('año', año.toString());
const response = await apiClient.get<IngresosEgresosData[]>(`/dashboard/ingresos-egresos?${params}`);
return response.data;
}
export async function getResumenFiscal(año?: number, mes?: number): Promise<ResumenFiscal> {
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<ResumenFiscal>(`/dashboard/resumen-fiscal?${params}`);
return response.data;
}
export async function getAlertas(limit = 5): Promise<Alerta[]> {
const response = await apiClient.get<Alerta[]>(`/dashboard/alertas?limit=${limit}`);
return response.data;
}

View File

@@ -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),
});
}