feat(web): add dashboard API client and hooks
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
33
apps/web/lib/api/dashboard.ts
Normal file
33
apps/web/lib/api/dashboard.ts
Normal 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;
|
||||||
|
}
|
||||||
30
apps/web/lib/hooks/use-dashboard.ts
Normal file
30
apps/web/lib/hooks/use-dashboard.ts
Normal 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),
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user