Initial commit - Horux Despachos NL
This commit is contained in:
47
apps/web/lib/hooks/use-dashboard.ts
Normal file
47
apps/web/lib/hooks/use-dashboard.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import * as dashboardApi from '../api/dashboard';
|
||||
import { useTenantViewStore } from '@/stores/tenant-view-store';
|
||||
import { useContribuyenteStore } from '@/stores/contribuyente-store';
|
||||
|
||||
function useTenantKey() {
|
||||
const { viewingTenantId } = useTenantViewStore();
|
||||
return viewingTenantId || 'own';
|
||||
}
|
||||
|
||||
export function useKpis(fechaInicio: string, fechaFin: string, conciliacion?: boolean) {
|
||||
const tenantKey = useTenantKey();
|
||||
const { selectedContribuyenteId } = useContribuyenteStore();
|
||||
return useQuery({
|
||||
queryKey: ['kpis', tenantKey, fechaInicio, fechaFin, conciliacion, selectedContribuyenteId],
|
||||
queryFn: () => dashboardApi.getKpis(fechaInicio, fechaFin, conciliacion, selectedContribuyenteId),
|
||||
enabled: !!fechaInicio && !!fechaFin,
|
||||
});
|
||||
}
|
||||
|
||||
export function useIngresosEgresos(año?: number, conciliacion?: boolean) {
|
||||
const tenantKey = useTenantKey();
|
||||
const { selectedContribuyenteId } = useContribuyenteStore();
|
||||
return useQuery({
|
||||
queryKey: ['ingresos-egresos', tenantKey, año, conciliacion, selectedContribuyenteId],
|
||||
queryFn: () => dashboardApi.getIngresosEgresos(año, conciliacion, selectedContribuyenteId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRegimenesDelPeriodo(fechaInicio: string, fechaFin: string, conciliacion?: boolean) {
|
||||
const tenantKey = useTenantKey();
|
||||
const { selectedContribuyenteId } = useContribuyenteStore();
|
||||
return useQuery({
|
||||
queryKey: ['regimenes-periodo', tenantKey, fechaInicio, fechaFin, conciliacion, selectedContribuyenteId],
|
||||
queryFn: () => dashboardApi.getRegimenesDelPeriodo(fechaInicio, fechaFin, conciliacion, selectedContribuyenteId),
|
||||
enabled: !!fechaInicio && !!fechaFin,
|
||||
});
|
||||
}
|
||||
|
||||
export function useAlertas(limit = 5) {
|
||||
const tenantKey = useTenantKey();
|
||||
const { selectedContribuyenteId } = useContribuyenteStore();
|
||||
return useQuery({
|
||||
queryKey: ['alertas', tenantKey, limit, selectedContribuyenteId],
|
||||
queryFn: () => dashboardApi.getAlertas(limit, selectedContribuyenteId),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user