- 11 archivos corregidos: agente-ia, alta-clientes, cobranza, cotizador, dashboards, mi-dia, landing (auth.ts, api.ts, mi-dia.ts, reportes.ts, push.ts, notas.ts, recordatorios.ts, reporte-mi-tablero.ts) - ?? solo cubre null/undefined, || cubre string vacío - 7 apps reconstruidas
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { conAuth, manejar401 } from './auth'
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL || '/api'
|
|
|
|
async function fetchJson<T>(path: string, init: RequestInit = {}): Promise<T> {
|
|
const res = await fetch(`${API_URL}${path}`, conAuth(init))
|
|
manejar401(res)
|
|
if (!res.ok) {
|
|
const body = (await res.json().catch(() => null)) as { error?: string } | null
|
|
throw new Error(body?.error ?? `Error ${res.status}`)
|
|
}
|
|
return (await res.json()) as T
|
|
}
|
|
|
|
// ---------- Interfaces ----------
|
|
|
|
export interface MiTablero {
|
|
generadoEn: string
|
|
leadsPorDia: { fecha: string; cantidad: number }[]
|
|
conversion: {
|
|
leads: number
|
|
oportunidades: number
|
|
apartados: number
|
|
vendidos: number
|
|
}
|
|
ventasMes: {
|
|
monto: number
|
|
unidades: number
|
|
}
|
|
porOrigen: {
|
|
origen: string
|
|
total: number
|
|
convertidos: number
|
|
}[]
|
|
porDesarrollo: {
|
|
desarrollo: string
|
|
ventas: number
|
|
}[]
|
|
actividadesHoy: number
|
|
actividadesPendientes: number
|
|
}
|
|
|
|
// ---------- Fetch ----------
|
|
|
|
export function fetchMiTablero(): Promise<MiTablero> {
|
|
return fetchJson<MiTablero>('/reportes/mi-tablero')
|
|
}
|