// src/routes/AppRoutes.tsx import React, { type JSX } from 'react'; import { BrowserRouter, Routes, Route, Navigate, Outlet } from 'react-router-dom'; import LoginPage from '../pages/LoginPage'; import HomePage from '../pages/HomePage'; import { useAuth } from '../contexts/AuthContext'; import MainLayout from '../layouts/MainLayout'; import { Typography } from '@mui/material'; // Distribución import DistribucionIndexPage from '../pages/Distribucion/DistribucionIndexPage'; import ESCanillasPage from '../pages/Distribucion/ESCanillasPage'; import ControlDevolucionesPage from '../pages/Distribucion/ControlDevolucionesPage'; import GestionarCanillitasPage from '../pages/Distribucion/GestionarCanillitasPage'; import GestionarDistribuidoresPage from '../pages/Distribucion/GestionarDistribuidoresPage'; import GestionarPublicacionesPage from '../pages/Distribucion/GestionarPublicacionesPage'; import GestionarSeccionesPublicacionPage from '../pages/Distribucion/GestionarSeccionesPublicacionPage'; import GestionarPreciosPublicacionPage from '../pages/Distribucion/GestionarPreciosPublicacionPage'; import GestionarRecargosPublicacionPage from '../pages/Distribucion/GestionarRecargosPublicacionPage'; import GestionarPorcentajesPagoPage from '../pages/Distribucion/GestionarPorcentajesPagoPage'; import GestionarPorcMonCanillaPage from '../pages/Distribucion/GestionarPorcMonCanillaPage'; import GestionarOtrosDestinosPage from '../pages/Distribucion/GestionarOtrosDestinosPage'; import GestionarZonasPage from '../pages/Distribucion/GestionarZonasPage'; import GestionarEmpresasPage from '../pages/Distribucion/GestionarEmpresasPage'; import GestionarSalidasOtrosDestinosPage from '../pages/Distribucion/GestionarSalidasOtrosDestinosPage'; import GestionarEntradasSalidasDistPage from '../pages/Distribucion/GestionarEntradasSalidasDistPage'; // Impresión import ImpresionIndexPage from '../pages/Impresion/ImpresionIndexPage'; import GestionarPlantasPage from '../pages/Impresion/GestionarPlantasPage'; import GestionarTiposBobinaPage from '../pages/Impresion/GestionarTiposBobinaPage'; import GestionarEstadosBobinaPage from '../pages/Impresion/GestionarEstadosBobinaPage'; import GestionarStockBobinasPage from '../pages/Impresion/GestionarStockBobinasPage'; import GestionarTiradasPage from '../pages/Impresion/GestionarTiradasPage'; // Contables import ContablesIndexPage from '../pages/Contables/ContablesIndexPage'; import GestionarTiposPagoPage from '../pages/Contables/GestionarTiposPagoPage'; // Usuarios import UsuariosIndexPage from '../pages/Usuarios/UsuariosIndexPage'; // Crear este componente import GestionarPerfilesPage from '../pages/Usuarios/GestionarPerfilesPage'; import GestionarPermisosPage from '../pages/Usuarios/GestionarPermisosPage'; import AsignarPermisosAPerfilPage from '../pages/Usuarios/AsignarPermisosAPerfilPage'; import GestionarUsuariosPage from '../pages/Usuarios/GestionarUsuariosPage'; // --- ProtectedRoute y PublicRoute SIN CAMBIOS --- const ProtectedRoute: React.FC<{ children: JSX.Element }> = ({ children }) => { const { isAuthenticated, isLoading } = useAuth(); // console.log("ProtectedRoute Check:", { path: window.location.pathname, isAuthenticated, isLoading }); if (isLoading) return null; if (!isAuthenticated) { // console.log("ProtectedRoute: Not authenticated, redirecting to /login"); return ; } // console.log("ProtectedRoute: Authenticated, rendering children"); return children; }; const PublicRoute: React.FC<{ children: JSX.Element }> = ({ children }) => { const { isAuthenticated, isLoading } = useAuth(); // console.log("PublicRoute Check:", { path: window.location.pathname, isAuthenticated, isLoading }); if (isLoading) return null; if (isAuthenticated) { // console.log("PublicRoute: Authenticated, redirecting to /"); return ; } // console.log("PublicRoute: Not authenticated, rendering children"); return children; }; // --- Fin Protected/Public --- const MainLayoutWrapper: React.FC = () => ( ); // Placeholder simple const PlaceholderPage: React.FC<{ moduleName: string }> = ({ moduleName }) => ( Página Principal del Módulo: {moduleName} ); const AppRoutes = () => { return ( {/* Un solo de nivel superior */} } /> {/* Rutas Protegidas que usan el MainLayout */} } > {/* Rutas hijas que se renderizarán en el Outlet de MainLayoutWrapper */} } /> {/* Para la ruta exacta "/" */} {/* Módulo de Distribución (anidado) */} }> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Rutas para Publicaciones y sus detalles */} }> {/* Contenedor para sub-rutas de publicaciones */} } /> {/* Lista de publicaciones */} } /> } /> } /> } /> } /> {/* Módulo Contable (anidado) */} }> } /> } /> {/* Futuras sub-rutas de contables aquí */} {/* Módulo de Impresión (anidado) */} }> } /> } /> } /> } /> } /> } /> {/* Otros Módulos Principales (estos son "finales", no tienen más hijos) */} } /> } /> {/* Módulo de Usuarios (anidado) */} }> } /> {/* Redirigir a la primera subpestaña */} } /> } /> } /> } /> {/* Ruta catch-all DENTRO del layout protegido */} } /> {/* Cierre de la ruta padre "/" */} {/* Podrías tener un catch-all global aquí si una ruta no coincide EN ABSOLUTO, pero el path="*" dentro de la ruta "/" ya debería manejar la mayoría de los casos después de un login exitoso. Si un usuario no autenticado intenta una ruta inválida, ProtectedRoute lo manda a /login. */} {/* } /> */} ); }; export default AppRoutes;