Update: nueva version Horux Despachos

This commit is contained in:
consultoria-as
2026-04-27 22:09:36 -06:00
commit 6b36db1403
614 changed files with 125926 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import type { UserInfo } from '@horux/shared';
interface AuthState {
user: UserInfo | null;
isAuthenticated: boolean;
_hasHydrated: boolean;
setUser: (user: UserInfo | null) => void;
setTokens: (accessToken: string, refreshToken: string) => void;
logout: () => void;
setHasHydrated: (state: boolean) => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
isAuthenticated: false,
_hasHydrated: false,
setUser: (user) => set({ user, isAuthenticated: !!user }),
setTokens: (accessToken, refreshToken) => {
localStorage.setItem('accessToken', accessToken);
localStorage.setItem('refreshToken', refreshToken);
},
logout: () => {
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
// Limpia impersonación de admin global — sin esto, si un admin
// global usa el TenantSelector y luego logout, el siguiente user
// que entre en este browser hereda el X-View-Tenant y el tenant
// middleware le rechaza con 403.
localStorage.removeItem('horux-tenant-view');
set({ user: null, isAuthenticated: false });
},
setHasHydrated: (state) => set({ _hasHydrated: state }),
}),
{
name: 'horux-auth',
partialize: (state) => ({ user: state.user, isAuthenticated: state.isAuthenticated }),
onRehydrateStorage: () => (state) => {
state?.setHasHydrated(true);
},
}
)
);

View File

@@ -0,0 +1,25 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface ContribuyenteState {
selectedContribuyenteId: string | null;
selectedContribuyenteRfc: string | null;
selectedContribuyenteNombre: string | null;
setSelectedContribuyente: (id: string, rfc: string, nombre: string) => void;
clearSelectedContribuyente: () => void;
}
export const useContribuyenteStore = create<ContribuyenteState>()(
persist(
(set) => ({
selectedContribuyenteId: null,
selectedContribuyenteRfc: null,
selectedContribuyenteNombre: null,
setSelectedContribuyente: (id, rfc, nombre) =>
set({ selectedContribuyenteId: id, selectedContribuyenteRfc: rfc, selectedContribuyenteNombre: nombre }),
clearSelectedContribuyente: () =>
set({ selectedContribuyenteId: null, selectedContribuyenteRfc: null, selectedContribuyenteNombre: null }),
}),
{ name: 'horux-contribuyente' }
)
);

View File

@@ -0,0 +1,45 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface PeriodoState {
fechaInicio: string;
fechaFin: string;
setRango: (fechaInicio: string, fechaFin: string) => void;
resetActual: () => void;
}
/** Devuelve el primer y último día del mes en curso como ISO strings. */
function actual(): { fechaInicio: string; fechaFin: string } {
const d = new Date();
const año = d.getFullYear();
const mes = d.getMonth();
const inicio = new Date(año, mes, 1);
const fin = new Date(año, mes + 1, 0);
return {
fechaInicio: inicio.toISOString().split('T')[0],
fechaFin: fin.toISOString().split('T')[0],
};
}
/**
* Selector global de periodo (rango de fechas) usado en `/despachos/*` para
* filtrar métricas. Persistido en localStorage. Compatible con el componente
* `<PeriodSelector />` de @horux/shared-ui (recibe fechaInicio/fechaFin como
* strings YYYY-MM-DD).
*/
export const usePeriodoStore = create<PeriodoState>()(
persist(
(set) => ({
...actual(),
setRango: (fechaInicio, fechaFin) => set({ fechaInicio, fechaFin }),
resetActual: () => set(actual()),
}),
{ name: 'periodo-despacho' },
),
);
/** Helper: extrae año y mes del fechaInicio para queries que usan ese formato. */
export function añoMesFromFechaInicio(fechaInicio: string): { año: number; mes: number } {
const d = new Date(fechaInicio + 'T00:00:00');
return { año: d.getFullYear(), mes: d.getMonth() + 1 };
}

View File

@@ -0,0 +1,25 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface TenantViewState {
viewingTenantId: string | null;
viewingTenantName: string | null;
viewingTenantRfc: string | null;
setViewingTenant: (id: string | null, name: string | null, rfc?: string | null) => void;
clearViewingTenant: () => void;
}
export const useTenantViewStore = create<TenantViewState>()(
persist(
(set) => ({
viewingTenantId: null,
viewingTenantName: null,
viewingTenantRfc: null,
setViewingTenant: (id, name, rfc = null) => set({ viewingTenantId: id, viewingTenantName: name, viewingTenantRfc: rfc }),
clearViewingTenant: () => set({ viewingTenantId: null, viewingTenantName: null, viewingTenantRfc: null }),
}),
{
name: 'horux-tenant-view',
}
)
);

View File

@@ -0,0 +1,20 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import type { ThemeName } from '@/themes';
interface ThemeState {
theme: ThemeName;
setTheme: (theme: ThemeName) => void;
}
export const useThemeStore = create<ThemeState>()(
persist(
(set) => ({
theme: 'light',
setTheme: (theme) => set({ theme }),
}),
{
name: 'horux-theme',
}
)
);