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:
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