feat(alertas): add alerts CRUD with stats and management UI
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
33
apps/web/lib/api/alertas.ts
Normal file
33
apps/web/lib/api/alertas.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { apiClient } from './client';
|
||||
import type { AlertaFull, AlertaCreate, AlertaUpdate, AlertasStats } from '@horux/shared';
|
||||
|
||||
export async function getAlertas(filters?: { leida?: boolean; resuelta?: boolean }): Promise<AlertaFull[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.leida !== undefined) params.set('leida', String(filters.leida));
|
||||
if (filters?.resuelta !== undefined) params.set('resuelta', String(filters.resuelta));
|
||||
const response = await apiClient.get<AlertaFull[]>(`/alertas?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getStats(): Promise<AlertasStats> {
|
||||
const response = await apiClient.get<AlertasStats>('/alertas/stats');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createAlerta(data: AlertaCreate): Promise<AlertaFull> {
|
||||
const response = await apiClient.post<AlertaFull>('/alertas', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateAlerta(id: number, data: AlertaUpdate): Promise<AlertaFull> {
|
||||
const response = await apiClient.patch<AlertaFull>(`/alertas/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteAlerta(id: number): Promise<void> {
|
||||
await apiClient.delete(`/alertas/${id}`);
|
||||
}
|
||||
|
||||
export async function markAllAsRead(): Promise<void> {
|
||||
await apiClient.post('/alertas/mark-all-read');
|
||||
}
|
||||
28
apps/web/lib/api/calendario.ts
Normal file
28
apps/web/lib/api/calendario.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { apiClient } from './client';
|
||||
import type { EventoFiscal, EventoCreate, EventoUpdate } from '@horux/shared';
|
||||
|
||||
export async function getEventos(año: number, mes?: number): Promise<EventoFiscal[]> {
|
||||
const params = new URLSearchParams({ año: año.toString() });
|
||||
if (mes) params.set('mes', mes.toString());
|
||||
const response = await apiClient.get<EventoFiscal[]>(`/calendario?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getProximos(dias = 30): Promise<EventoFiscal[]> {
|
||||
const response = await apiClient.get<EventoFiscal[]>(`/calendario/proximos?dias=${dias}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createEvento(data: EventoCreate): Promise<EventoFiscal> {
|
||||
const response = await apiClient.post<EventoFiscal>('/calendario', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateEvento(id: number, data: EventoUpdate): Promise<EventoFiscal> {
|
||||
const response = await apiClient.patch<EventoFiscal>(`/calendario/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteEvento(id: number): Promise<void> {
|
||||
await apiClient.delete(`/calendario/${id}`);
|
||||
}
|
||||
36
apps/web/lib/api/reportes.ts
Normal file
36
apps/web/lib/api/reportes.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { apiClient } from './client';
|
||||
import type { EstadoResultados, FlujoEfectivo, ComparativoPeriodos, ConcentradoRfc } from '@horux/shared';
|
||||
|
||||
export async function getEstadoResultados(fechaInicio?: string, fechaFin?: string): Promise<EstadoResultados> {
|
||||
const params = new URLSearchParams();
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<EstadoResultados>(`/reportes/estado-resultados?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getFlujoEfectivo(fechaInicio?: string, fechaFin?: string): Promise<FlujoEfectivo> {
|
||||
const params = new URLSearchParams();
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<FlujoEfectivo>(`/reportes/flujo-efectivo?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getComparativo(año?: number): Promise<ComparativoPeriodos> {
|
||||
const params = año ? `?año=${año}` : '';
|
||||
const response = await apiClient.get<ComparativoPeriodos>(`/reportes/comparativo${params}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getConcentradoRfc(
|
||||
tipo: 'cliente' | 'proveedor',
|
||||
fechaInicio?: string,
|
||||
fechaFin?: string
|
||||
): Promise<ConcentradoRfc[]> {
|
||||
const params = new URLSearchParams({ tipo });
|
||||
if (fechaInicio) params.set('fechaInicio', fechaInicio);
|
||||
if (fechaFin) params.set('fechaFin', fechaFin);
|
||||
const response = await apiClient.get<ConcentradoRfc[]>(`/reportes/concentrado-rfc?${params}`);
|
||||
return response.data;
|
||||
}
|
||||
21
apps/web/lib/api/usuarios.ts
Normal file
21
apps/web/lib/api/usuarios.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { apiClient } from './client';
|
||||
import type { UserListItem, UserInvite, UserUpdate } from '@horux/shared';
|
||||
|
||||
export async function getUsuarios(): Promise<UserListItem[]> {
|
||||
const response = await apiClient.get<UserListItem[]>('/usuarios');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function inviteUsuario(data: UserInvite): Promise<UserListItem> {
|
||||
const response = await apiClient.post<UserListItem>('/usuarios/invite', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateUsuario(id: string, data: UserUpdate): Promise<UserListItem> {
|
||||
const response = await apiClient.patch<UserListItem>(`/usuarios/${id}`, data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteUsuario(id: string): Promise<void> {
|
||||
await apiClient.delete(`/usuarios/${id}`);
|
||||
}
|
||||
61
apps/web/lib/hooks/use-alertas.ts
Normal file
61
apps/web/lib/hooks/use-alertas.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import * as alertasApi from '../api/alertas';
|
||||
import type { AlertaCreate, AlertaUpdate } from '@horux/shared';
|
||||
|
||||
export function useAlertas(filters?: { leida?: boolean; resuelta?: boolean }) {
|
||||
return useQuery({
|
||||
queryKey: ['alertas', filters],
|
||||
queryFn: () => alertasApi.getAlertas(filters),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAlertasStats() {
|
||||
return useQuery({
|
||||
queryKey: ['alertas-stats'],
|
||||
queryFn: alertasApi.getStats,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateAlerta() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: AlertaCreate) => alertasApi.createAlerta(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas-stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateAlerta() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: AlertaUpdate }) => alertasApi.updateAlerta(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas-stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteAlerta() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => alertasApi.deleteAlerta(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas-stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useMarkAllAsRead() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: alertasApi.markAllAsRead,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['alertas-stats'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
47
apps/web/lib/hooks/use-calendario.ts
Normal file
47
apps/web/lib/hooks/use-calendario.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import * as calendarioApi from '../api/calendario';
|
||||
import type { EventoCreate, EventoUpdate } from '@horux/shared';
|
||||
|
||||
export function useEventos(año: number, mes?: number) {
|
||||
return useQuery({
|
||||
queryKey: ['calendario', año, mes],
|
||||
queryFn: () => calendarioApi.getEventos(año, mes),
|
||||
});
|
||||
}
|
||||
|
||||
export function useProximosEventos(dias = 30) {
|
||||
return useQuery({
|
||||
queryKey: ['calendario-proximos', dias],
|
||||
queryFn: () => calendarioApi.getProximos(dias),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateEvento() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: EventoCreate) => calendarioApi.createEvento(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['calendario'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateEvento() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: EventoUpdate }) => calendarioApi.updateEvento(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['calendario'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteEvento() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => calendarioApi.deleteEvento(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['calendario'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
30
apps/web/lib/hooks/use-reportes.ts
Normal file
30
apps/web/lib/hooks/use-reportes.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import * as reportesApi from '../api/reportes';
|
||||
|
||||
export function useEstadoResultados(fechaInicio?: string, fechaFin?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['estado-resultados', fechaInicio, fechaFin],
|
||||
queryFn: () => reportesApi.getEstadoResultados(fechaInicio, fechaFin),
|
||||
});
|
||||
}
|
||||
|
||||
export function useFlujoEfectivo(fechaInicio?: string, fechaFin?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['flujo-efectivo', fechaInicio, fechaFin],
|
||||
queryFn: () => reportesApi.getFlujoEfectivo(fechaInicio, fechaFin),
|
||||
});
|
||||
}
|
||||
|
||||
export function useComparativo(año?: number) {
|
||||
return useQuery({
|
||||
queryKey: ['comparativo', año],
|
||||
queryFn: () => reportesApi.getComparativo(año),
|
||||
});
|
||||
}
|
||||
|
||||
export function useConcentradoRfc(tipo: 'cliente' | 'proveedor', fechaInicio?: string, fechaFin?: string) {
|
||||
return useQuery({
|
||||
queryKey: ['concentrado-rfc', tipo, fechaInicio, fechaFin],
|
||||
queryFn: () => reportesApi.getConcentradoRfc(tipo, fechaInicio, fechaFin),
|
||||
});
|
||||
}
|
||||
40
apps/web/lib/hooks/use-usuarios.ts
Normal file
40
apps/web/lib/hooks/use-usuarios.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import * as usuariosApi from '../api/usuarios';
|
||||
import type { UserInvite, UserUpdate } from '@horux/shared';
|
||||
|
||||
export function useUsuarios() {
|
||||
return useQuery({
|
||||
queryKey: ['usuarios'],
|
||||
queryFn: usuariosApi.getUsuarios,
|
||||
});
|
||||
}
|
||||
|
||||
export function useInviteUsuario() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: UserInvite) => usuariosApi.inviteUsuario(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['usuarios'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateUsuario() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: UserUpdate }) => usuariosApi.updateUsuario(id, data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['usuarios'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteUsuario() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => usuariosApi.deleteUsuario(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['usuarios'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user