From 4bbe8dfea54038efb338052d695ab53fcd513128 Mon Sep 17 00:00:00 2001 From: Mariela Date: Fri, 12 Aug 2022 21:01:18 -0600 Subject: [PATCH] add pagina 404 --- web-ui/web-react/src/App.js | 122 ++++++--- .../src/components/{LogIn.js => LogInUser.js} | 37 +-- .../src/components/LoginLocalStorage.js | 231 ------------------ web-ui/web-react/src/components/MenuAdmin.js | 102 -------- .../src/components/MenuAdminCommunity.js | 119 --------- web-ui/web-react/src/components/Page404.js | 20 ++ 6 files changed, 131 insertions(+), 500 deletions(-) rename web-ui/web-react/src/components/{LogIn.js => LogInUser.js} (86%) delete mode 100644 web-ui/web-react/src/components/LoginLocalStorage.js delete mode 100644 web-ui/web-react/src/components/MenuAdmin.js delete mode 100644 web-ui/web-react/src/components/MenuAdminCommunity.js create mode 100644 web-ui/web-react/src/components/Page404.js diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 3381887e..ef05324a 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -53,8 +53,8 @@ import './App.scss'; import { PrimeIcons } from 'primereact/api'; import AreasComunes from './components/AreasComunes'; import { useCookies } from "react-cookie"; -import Login from './components/Login'; - +import LogInUser from './components/LogInUser'; +import Page404 from './components/Page404' const App = () => { @@ -69,6 +69,7 @@ const App = () => { const copyTooltipRef = useRef(); const location = useLocation(); const [cookies, setCookies] = useCookies(); + const [logged, setLogged] = useState() PrimeReact.ripple = true; @@ -89,6 +90,12 @@ const App = () => { copyTooltipRef.current.updateTargetEvents(); }, [location]); + + + + + + const onInputStyleChange = (inputStyle) => { setInputStyle(inputStyle); }; @@ -405,6 +412,9 @@ const App = () => { 'layout-theme-light': layoutColorMode === 'light', }); + + + return ( @@ -424,43 +434,89 @@ const App = () => {
- - } /> + {(() => { + if (!cookies.email) { + return ( + <> + + + + + + ) + } else { + + if (cookies.type == '1') { + return ( + <> + } /> + + + + + + + ) + + } else if (cookies.type == '2') { + return ( + <> + } /> + + + + + + + ) + } else { + return ( + + ) + } + + + return ( + <> + } /> + + + + + + + + + + + + + + + {/**/} + + + } /> + + + + + + + + + + ) + + } + })()} - - - - - - - - - - - - - - {/**/} - - - } /> - - - - - - - - - - -
- +
diff --git a/web-ui/web-react/src/components/LogIn.js b/web-ui/web-react/src/components/LogInUser.js similarity index 86% rename from web-ui/web-react/src/components/LogIn.js rename to web-ui/web-react/src/components/LogInUser.js index b70037de..2d25e73e 100644 --- a/web-ui/web-react/src/components/LogIn.js +++ b/web-ui/web-react/src/components/LogInUser.js @@ -2,11 +2,12 @@ import React, { Component, Fragment, useRef } from 'react'; import Cookies from 'universal-cookie'; import { InputText } from 'primereact/inputtext'; import { Button } from 'primereact/button'; +import { Toast } from 'primereact/toast'; const baseUrl = "http://localhost:4000/user/loginUser"; const cookies = new Cookies(); -class Login extends Component { +class LogInUser extends Component { constructor(props) { super(props); this.state = { @@ -30,7 +31,7 @@ class Login extends Component { } validaciones = (data) => { - let error = true; + let error = false; if (data.email == '') { this.setState({ errorEmail: true @@ -87,20 +88,26 @@ class Login extends Component { if (response.message) { const user = response.message; - cookies.set('id', user._id, { path: "/" }); - cookies.set('name', user.name, { path: "/" }); - cookies.set('email', user.email, { path: "/" }); - cookies.set('type', user.user_type, { path: "/" }); - if (user.user_type != '1') { - cookies.set('community_id', user.community_id, { path: "/" }); + + if(user.user_type == '1' || user.user_type == '2'){ + cookies.set('id', user._id, { path: "/" }); + cookies.set('name', user.name, { path: "/" }); + cookies.set('email', user.email, { path: "/" }); + cookies.set('type', user.user_type, { path: "/" }); + if (user.user_type != '1') { + cookies.set('community_id', user.community_id, { path: "/" }); + } + // alert(`Bienvenido ${user.name}`); + document.getElementById('notification').hidden = true; + document.getElementById('notification2').hidden = false; + + document.getElementById("message2").innerHTML = `Bienvenido ${user.name}`; + + window.location.href = "/"; } - // alert(`Bienvenido ${user.name}`); - document.getElementById('notification').hidden = true; - document.getElementById('notification2').hidden = false; + window.location.href = "/page404"; - document.getElementById("message2").innerHTML = `Bienvenido ${user.name}`; - - window.location.href = "/"; + } else { document.getElementById('notification2').hidden = true; document.getElementById('notification').hidden = false; @@ -216,4 +223,4 @@ class Login extends Component { } } -export default Login; \ No newline at end of file +export default LogInUser; \ No newline at end of file diff --git a/web-ui/web-react/src/components/LoginLocalStorage.js b/web-ui/web-react/src/components/LoginLocalStorage.js deleted file mode 100644 index fbd74f0f..00000000 --- a/web-ui/web-react/src/components/LoginLocalStorage.js +++ /dev/null @@ -1,231 +0,0 @@ -import DashboardAdmin from "./DashboardAdmin"; -import React, { Component, Fragment, useRef } from 'react'; -import Cookies from 'universal-cookie'; -import { InputText } from 'primereact/inputtext'; -import { Button } from 'primereact/button'; -import { Toast } from 'primereact/toast'; - -const baseUrl = "http://localhost:4000/user/loginUser"; -const cookies = new Cookies(); - -class LoginLocalStorage extends Component { - constructor(props) { - super(props); - this.state = { - form: { - email: '', - password: '' - }, - errorEmail: false, - errorPassword: false, - logged: null - } - } - - handleChange = async e => { - await this.setState({ - form: { - ...this.state.form, - [e.target.name]: e.target.value - } - }); - } - - validaciones = (data) => { - let error = true; - if (data.email == '') { - this.setState({ - errorEmail: true - }) - error = true; - } else { - this.setState({ - errorEmail: false - }) - } - if (data.password == '') { - this.setState({ - errorPassword: true - }) - error = true; - } else { - this.setState({ - errorPassword: false - }) - } - - return error; - - } - - iniciarSesion = async () => { - const data = { - email: this.state.form.email, - password: this.state.form.password - } - - console.log(data); - - if (!this.validaciones(data)) { - this.setState({ - email: true, - password: true - }) - await fetch(baseUrl, { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json' - } - }) - .then(response => { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else return response.json(); - }) - .then(response => { - console.log(response.message); - - if (response.message) { - const user = response.message; - cookies.set('id', user._id, { path: "/" }); - cookies.set('name', user.name, { path: "/" }); - cookies.set('email', user.email, { path: "/" }); - cookies.set('type', user.user_type, { path: "/" }); - if (user.user_type != '1') { - cookies.set('community_id', user.community_id, { path: "/" }); - } - // alert(`Bienvenido ${user.name}`); - document.getElementById('notification').hidden = true; - document.getElementById('notification2').hidden = false; - - - document.getElementById("message2").innerHTML = `Bienvenido ${user.name}`; - - //document.getElementById("message").remove('p-message p-message-error') - // document.getElementById("message").append(`Bienvenido ${user.name}`); - // document.getElementById("message").classList('p-message p-message-success') - // window.location.href = "/"; - - - } else { - document.getElementById('notification2').hidden = true; - document.getElementById('notification').hidden = false; - - - //alert('El usuario o la contraseña no son correctos'); - document.getElementById("message").innerHTML = "El usuario o la contraseña son incorrectos"; - // document.getElementById("message").remove('p-message p-message-success') - // document.getElementById("message").append('El usuario o la contraseña son incorrectos'); - // document.getElementById("message").add.className('p-message p-message-error') - } - }) - .catch(error => { - console.log(error); - }) - } - } - - componentDidMount() { - if (cookies.get('email')) { - window.location.href = "/"; - } - } - - renderErrorMessage = (name) => - name === this.state.errorMessages.name && ( -
{this.state.errorMessages.message}
- ); - - errors = { - email: "Correo requerido", - pass: "Contraseña requerida" - }; - - render() { - return ( - - - - -
-
- - - - -
-
- -
-
Iniciar Sesión
-
- -
- -
-
- - - - -
- {this.state.errorEmail && ( - Correo electrónico es requerido - )} - -
-
-
- -
-
- - - - -
- {this.state.errorPassword && ( - Contraseña es requerida - )} -
-
- - -
-
-
-
-
- - - - ); - } -} - -export default LoginLocalStorage; \ No newline at end of file diff --git a/web-ui/web-react/src/components/MenuAdmin.js b/web-ui/web-react/src/components/MenuAdmin.js deleted file mode 100644 index 334ccf04..00000000 --- a/web-ui/web-react/src/components/MenuAdmin.js +++ /dev/null @@ -1,102 +0,0 @@ -import React, { Component } from 'react'; -import Cookies from 'universal-cookie'; -import AdministradoresComunidad from '../components/AdministradoresComunidad'; -import AdministradoresSistema from '../components/AdministradoresSistema'; -import Communities from '../components/ComunidadViviendas'; -import Dashboard from '../templates/Dashboard'; -import { BrowserRouter, Switch, Route } from 'react-router-dom'; -import { AppMenu } from '../AppMenu'; -import { CSSTransition } from 'react-transition-group'; - -const cookies = new Cookies(); - -const menu = [ - { - label: 'Home', - items: [ - { label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/' }, - { label: 'Administradores del sistema', icon: 'pi pi-fw pi-id-card', to: '/administradoresSistema' }, - { label: 'Administradores de comunidad', icon: 'pi pi-fw pi-id-card', to: '/administradoresComunidad' }, - { label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas' }, - ] - }, -]; - -class MenuAdmin extends Component { - - constructor(){ - super() - this.state = { - layoutColorMode: 'light', - layoutMode: 'static', - menuClick: false, - mobileTopbarMenuClick: false, - overlayMenuActive: false, - mobileMenuActive: false - } - - } - - onSidebarClick = () => { - this.setState({ - menuClick: true - }) - - } - - onMenuItemClick = (event) => { - if (!event.item.items) { - this.state.overlayMenuActive = false; - this.state.mobileMenuActive = false; - this.setState({ - overlayMenuActive: true, - mobileMenuActive:false - }) - - } - } - - cerrarSesion = () => { - cookies.remove('id', { path: "/" }); - cookies.remove('email', { path: "/" }); - cookies.remove('name', { path: "/" }); - cookies.remove('type', { path: "/" }); - window.location.href = '/login'; - } - - componentDidMount() { - if (!cookies.get('email')) { - window.location.href = "/login"; - } - } - - render() { - - return ( -
- Menu Principal -
- - - -
- -
-
- } /> - - - -
- -
-
- -
-
-
- ); - } -} - -export default MenuAdmin; \ No newline at end of file diff --git a/web-ui/web-react/src/components/MenuAdminCommunity.js b/web-ui/web-react/src/components/MenuAdminCommunity.js deleted file mode 100644 index db982561..00000000 --- a/web-ui/web-react/src/components/MenuAdminCommunity.js +++ /dev/null @@ -1,119 +0,0 @@ -import React, { Component } from 'react'; -import Cookies from 'universal-cookie'; -import Inquilinos from './Inquilinos'; -import GuardasSeguridad from './GuardasSeguridad'; -import Dashboard from '../templates/Dashboard'; -import { BrowserRouter, Switch, Route } from 'react-router-dom'; -import { AppMenu } from '../AppMenu'; - -const cookies = new Cookies(); - -const menu = [ - { - label: 'Home', - items: [ - { label: 'Dashboard', icon: 'pi pi-fw pi-home', to: '/' }, - { label: 'Inquilinos', icon: 'pi pi-fw pi-id-card', to: '/inquilinos' }, - { label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad' }, - ] - }, -]; - -class MenuAdminCommunity extends Component { - - constructor() { - super() - this.state = { - layoutColorMode: 'light', - layoutMode: 'static', - menuClick: false, - mobileTopbarMenuClick: false, - overlayMenuActive: false, - mobileMenuActive: false - } - - } - - onSidebarClick = () => { - this.setState({ - menuClick: true - }) - - } - - onMenuItemClick = (event) => { - if (!event.item.items) { - this.setState({ - overlayMenuActive: false, - mobileMenuActive: false - }) - - } - } - - cerrarSesion = () => { - cookies.remove('id', { path: "/" }); - cookies.remove('email', { path: "/" }); - cookies.remove('name', { path: "/" }); - cookies.remove('type', { path: "/" }); - cookies.remove('community_id', { path: "/" }); - window.location.href = '/login'; - } - - componentDidMount() { - if (!cookies.get('email')) { - window.location.href = "/login"; - } - } - - - onWrapperClick = (event) => { - if (!this.state.menuClick) { - this.setState({ - overlayMenuActive: false, - mobileMenuActive: false - }) - } - - if (!this.state.mobileTopbarMenuClick) { - this.setState({ - mobileTopbarMenuClick: false, - }) - } - - this.setState({ - mobileTopbarMenuClick: false, - menuClick: false - }) - } - - render() { - - return ( - -
- -
- Menu Principal -
- - - -
- -
-
- } /> - - -
- -
-
-
-
- ); - } -} - -export default MenuAdminCommunity; \ No newline at end of file diff --git a/web-ui/web-react/src/components/Page404.js b/web-ui/web-react/src/components/Page404.js new file mode 100644 index 00000000..f19e4881 --- /dev/null +++ b/web-ui/web-react/src/components/Page404.js @@ -0,0 +1,20 @@ +import React from 'react'; + + +const Page404 = () => { + + return ( +
+
+
+
+
404
+
No se encuentra la página
+
+
+
+
+ ) +} + +export default React.memo(Page404)