89 lines
2 KiB
JavaScript
89 lines
2 KiB
JavaScript
import {useEffect} from "react";
|
|
import PropTypes from "prop-types";
|
|
import {Box} from "@mui/material";
|
|
import {useDispatch,useSelector} from "react-redux";
|
|
import {inicializar} from "../redux";
|
|
import Cargando from "./Cargando";
|
|
import Error from "./Error";
|
|
import Notificacion from "./Notificacion";
|
|
import Idioma from "./Idioma";
|
|
import Tema from "./Tema";
|
|
import MainRouter from "./MainRouter";
|
|
|
|
const InicializarInner = ({devURL,basename,children}) => {
|
|
const aplicacion = useSelector(store => store.aplicacion);
|
|
|
|
return (
|
|
<Box sx={{
|
|
display: "flex",
|
|
flexDirection: "column",
|
|
minHeight: "100vh",
|
|
justifyContent: "flex-start",
|
|
backgroundColor: "background.default"
|
|
}}>
|
|
{aplicacion.inicializando ?
|
|
<Cargando />
|
|
: (aplicacion.error || !aplicacion.inicializado) ?
|
|
<Error titulo={"saas.inicializar.error.titulo"} texto={"saas.inicializar.error.mensaje"} />
|
|
:
|
|
<>
|
|
<MainRouter
|
|
devURL={devURL}
|
|
requiereLogin={aplicacion.instancia.requiereLogin}
|
|
basename={basename}
|
|
>
|
|
{children}
|
|
</MainRouter>
|
|
<Notificacion />
|
|
</>
|
|
}
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
InicializarInner.propTypes={
|
|
devURL: PropTypes.string,
|
|
basename: PropTypes.string,
|
|
children: PropTypes.element.isRequired
|
|
};
|
|
|
|
const Inicializar = ({
|
|
aplicacion,
|
|
devSaasURL,
|
|
devAuthURL,
|
|
messages,
|
|
idiomaDefecto,
|
|
basename,
|
|
children
|
|
}) => {
|
|
const dispatch = useDispatch();
|
|
|
|
useEffect(() => {
|
|
dispatch(inicializar({devURL: devSaasURL,aplicacion: aplicacion}));
|
|
},[dispatch,aplicacion,devSaasURL]);
|
|
|
|
return (
|
|
<Idioma messages={messages} idiomaDefecto={idiomaDefecto}>
|
|
<Tema>
|
|
<InicializarInner
|
|
devURL={devAuthURL}
|
|
basename={basename}
|
|
>
|
|
{children}
|
|
</InicializarInner>
|
|
</Tema>
|
|
</Idioma>
|
|
);
|
|
};
|
|
|
|
Inicializar.propTypes={
|
|
aplicacion: PropTypes.string.isRequired,
|
|
devSaasURL: PropTypes.string,
|
|
devAuthURL: PropTypes.string,
|
|
messages: PropTypes.object.isRequired,
|
|
idiomaDefecto: PropTypes.string,
|
|
basename: PropTypes.string,
|
|
children: PropTypes.element.isRequired
|
|
};
|
|
|
|
export default Inicializar;
|