diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 4f7d2c96..d6fa404a 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -1,7 +1,8 @@ import React, { useState, useEffect, useRef } from 'react'; import classNames from 'classnames'; -import { Route, useLocation } from 'react-router-dom'; +import { Route, useLocation, BrowserRouter} from 'react-router-dom'; import { CSSTransition } from 'react-transition-group'; +import Routes from './routes/Routes' import { AppTopbar } from './AppTopbar'; import { AppFooter } from './AppFooter'; @@ -50,6 +51,7 @@ import './assets/demo/Demos.scss'; import './assets/layout/layout.scss'; import './App.scss'; import LogIn from './components/LogIn'; +import LoginLocalStorage from './components/LoginLocalStorage'; const App = () => { const [layoutMode, setLayoutMode] = useState('static'); @@ -63,6 +65,15 @@ const App = () => { const copyTooltipRef = useRef(); const location = useLocation(); + const handleLogout=()=>{ + localStorage.clear(); + window.location.reload(); + } + + + + + PrimeReact.ripple = true; let menuClick = false; @@ -171,7 +182,8 @@ const App = () => { {label: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad'}, {label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas'}, {label: 'Inquilinos', icon: 'pi pi-fw pi-id-card', to: '/inquilinos'}, - {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'} + {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'}, + {label: 'Log out', icon: 'pi pi-fw pi-id-card', to: '/logOut'} ] }, { @@ -289,61 +301,11 @@ const App = () => { }); return ( -
- - - - -
- -
- -
-
- } /> - - - - - - - - - - - - - - - - - } /> - - - - - - - - - - - -
- - -
- - - - -
-
- - -
+
+ + + +
); } diff --git a/web-ui/web-react/src/components/DashboardAdmin.js b/web-ui/web-react/src/components/DashboardAdmin.js new file mode 100644 index 00000000..0911d706 --- /dev/null +++ b/web-ui/web-react/src/components/DashboardAdmin.js @@ -0,0 +1,360 @@ +import React, { useState, useEffect, useRef } from 'react'; +import classNames from 'classnames'; +import { Route, useLocation } from 'react-router-dom'; +import { CSSTransition } from 'react-transition-group'; + +import { AppTopbar } from '../AppTopbar'; +import { AppFooter } from '../AppFooter'; +import { AppMenu } from '../AppMenu'; +import { AppConfig } from '../AppConfig'; + +import Dashboard from '../templates/Dashboard'; +import ButtonDemo from '../templates/ButtonDemo'; +import ChartDemo from '../templates/ChartDemo'; +import Documentation from '../templates/Documentation'; +import FileDemo from '../templates/FileDemo'; +import FloatLabelDemo from '../templates/FloatLabelDemo'; +import FormLayoutDemo from '../templates/FormLayoutDemo'; +import InputDemo from '../templates/InputDemo'; +import ListDemo from '../templates/ListDemo'; +import MenuDemo from '../templates/MenuDemo'; +import MessagesDemo from '../templates/MessagesDemo'; +import MiscDemo from '../templates/MiscDemo'; +import OverlayDemo from '../templates/OverlayDemo'; +import MediaDemo from '../templates/MediaDemo'; +import PanelDemo from '../templates/PanelDemo'; +import TableDemo from '../templates/TableDemo'; +import TreeDemo from '../templates/TreeDemo'; +import InvalidStateDemo from '../templates/InvalidStateDemo'; +import BlocksDemo from '../templates/BlocksDemo'; +import IconsDemo from '../templates/IconsDemo'; +import AdministradoresSistema from '../components/AdministradoresSistema'; +import AdministradoresComunidad from '../components/AdministradoresComunidad'; +import GuardasSeguridad from '../components/GuardasSeguridad'; +import Communities from '../components/ComunidadViviendas'; +import Inquilinos from '../components/Inquilinos'; + +import Crud from '../pages/Crud'; +import EmptyPage from '../pages/EmptyPage'; +import TimelineDemo from '../pages/TimelineDemo'; + +import PrimeReact from 'primereact/api'; +import { Tooltip } from 'primereact/tooltip'; + +import 'primereact/resources/primereact.css'; +import 'primeicons/primeicons.css'; +import 'primeflex/primeflex.css'; +import 'prismjs/themes/prism-coy.css'; +import '../assets/demo/flags/flags.css'; +import '../assets/demo/Demos.scss'; +import '../assets/layout/layout.scss'; +import '../App.scss'; +import LogIn from '../components/LogIn'; +import LoginLocalStorage from '../components/LoginLocalStorage'; + +const DashboardAdmin = () => { + const [layoutMode, setLayoutMode] = useState('static'); + const [layoutColorMode, setLayoutColorMode] = useState('light') + const [inputStyle, setInputStyle] = useState('outlined'); + const [ripple, setRipple] = useState(true); + const [staticMenuInactive, setStaticMenuInactive] = useState(false); + const [overlayMenuActive, setOverlayMenuActive] = useState(false); + const [mobileMenuActive, setMobileMenuActive] = useState(false); + const [mobileTopbarMenuActive, setMobileTopbarMenuActive] = useState(false); + const copyTooltipRef = useRef(); + const location = useLocation(); + + const handleLogout=()=>{ + localStorage.clear(); + window.location.reload(); + } + + PrimeReact.ripple = true; + + let menuClick = false; + let mobileTopbarMenuClick = false; + + useEffect(() => { + if (mobileMenuActive) { + addClass(document.body, "body-overflow-hidden"); + } else { + removeClass(document.body, "body-overflow-hidden"); + } + }, [mobileMenuActive]); + + useEffect(() => { + copyTooltipRef && copyTooltipRef.current && copyTooltipRef.current.updateTargetEvents(); + }, [location]); + + const onInputStyleChange = (inputStyle) => { + setInputStyle(inputStyle); + } + + const onRipple = (e) => { + PrimeReact.ripple = e.value; + setRipple(e.value) + } + + const onLayoutModeChange = (mode) => { + setLayoutMode(mode) + } + + const onColorModeChange = (mode) => { + setLayoutColorMode(mode) + } + + const onWrapperClick = (event) => { + if (!menuClick) { + setOverlayMenuActive(false); + setMobileMenuActive(false); + } + + if (!mobileTopbarMenuClick) { + setMobileTopbarMenuActive(false); + } + + mobileTopbarMenuClick = false; + menuClick = false; + } + + const onToggleMenuClick = (event) => { + menuClick = true; + + if (isDesktop()) { + if (layoutMode === 'overlay') { + if (mobileMenuActive === true) { + setOverlayMenuActive(true); + } + + setOverlayMenuActive((prevState) => !prevState); + setMobileMenuActive(false); + } + else if (layoutMode === 'static') { + setStaticMenuInactive((prevState) => !prevState); + } + } + else { + setMobileMenuActive((prevState) => !prevState); + } + + event.preventDefault(); + } + + const onSidebarClick = () => { + menuClick = true; + } + + const onMobileTopbarMenuClick = (event) => { + mobileTopbarMenuClick = true; + + setMobileTopbarMenuActive((prevState) => !prevState); + event.preventDefault(); + } + + const onMobileSubTopbarMenuClick = (event) => { + mobileTopbarMenuClick = true; + + event.preventDefault(); + } + + const onMenuItemClick = (event) => { + if (!event.item.items) { + setOverlayMenuActive(false); + setMobileMenuActive(false); + } + } + const isDesktop = () => { + return window.innerWidth >= 992; + } + + 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: 'Guardas de seguridad', icon: 'pi pi-fw pi-id-card', to: '/guardasSeguridad'}, + {label: 'Comunidadades', icon: 'pi pi-fw pi-id-card', to: '/comunidadesViviendas'}, + {label: 'Inquilinos', icon: 'pi pi-fw pi-id-card', to: '/inquilinos'}, + {label: 'Log in', icon: 'pi pi-fw pi-id-card', to: '/logIn'}, + {label: 'Log out', icon: 'pi pi-fw pi-id-card', to: '/logOut'} + ] + }, + { + label: 'UI Components', icon: 'pi pi-fw pi-sitemap', + items: [ + { label: 'Form Layout', icon: 'pi pi-fw pi-id-card', to: '/formlayout' }, + { label: 'Input', icon: 'pi pi-fw pi-check-square', to: '/input' }, + { label: "Float Label", icon: "pi pi-fw pi-bookmark", to: "/floatlabel" }, + { label: "Invalid State", icon: "pi pi-fw pi-exclamation-circle", to: "invalidstate" }, + { label: 'Button', icon: 'pi pi-fw pi-mobile', to: '/button' }, + { label: 'Table', icon: 'pi pi-fw pi-table', to: '/table' }, + { label: 'List', icon: 'pi pi-fw pi-list', to: '/list' }, + { label: 'Tree', icon: 'pi pi-fw pi-share-alt', to: '/tree' }, + { label: 'Panel', icon: 'pi pi-fw pi-tablet', to: '/panel' }, + { label: 'Overlay', icon: 'pi pi-fw pi-clone', to: '/overlay' }, + { label: "Media", icon: "pi pi-fw pi-image", to: "/media" }, + { label: 'Menu', icon: 'pi pi-fw pi-bars', to: '/menu' }, + { label: 'Message', icon: 'pi pi-fw pi-comment', to: '/messages' }, + { label: 'File', icon: 'pi pi-fw pi-file', to: '/file' }, + { label: 'Chart', icon: 'pi pi-fw pi-chart-bar', to: '/chart' }, + { label: 'Misc', icon: 'pi pi-fw pi-circle-off', to: '/misc' }, + ] + }, + { + label: 'UI Blocks', + items: [ + { label: 'Free Blocks', icon: 'pi pi-fw pi-eye', to: '/blocks', badge: "NEW" }, + { label: 'All Blocks', icon: 'pi pi-fw pi-globe', url: 'https://www.primefaces.org/primeblocks-react' } + ] + }, + { + label: 'Icons', + items: [ + { label: 'PrimeIcons', icon: 'pi pi-fw pi-prime', to: '/icons' } + ] + }, + { + label: 'Pages', icon: 'pi pi-fw pi-clone', + items: [ + { label: 'Crud', icon: 'pi pi-fw pi-user-edit', to: '/crud' }, + { label: 'Timeline', icon: 'pi pi-fw pi-calendar', to: '/timeline' }, + { label: 'Empty', icon: 'pi pi-fw pi-circle-off', to: '/empty' } + ] + }, + { + label: 'Menu Hierarchy', icon: 'pi pi-fw pi-search', + items: [ + { + label: 'Submenu 1', icon: 'pi pi-fw pi-bookmark', + items: [ + { + label: 'Submenu 1.1', icon: 'pi pi-fw pi-bookmark', + items: [ + { label: 'Submenu 1.1.1', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 1.1.2', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 1.1.3', icon: 'pi pi-fw pi-bookmark' }, + ] + }, + { + label: 'Submenu 1.2', icon: 'pi pi-fw pi-bookmark', + items: [ + { label: 'Submenu 1.2.1', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 1.2.2', icon: 'pi pi-fw pi-bookmark' } + ] + }, + ] + }, + { + label: 'Submenu 2', icon: 'pi pi-fw pi-bookmark', + items: [ + { + label: 'Submenu 2.1', icon: 'pi pi-fw pi-bookmark', + items: [ + { label: 'Submenu 2.1.1', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 2.1.2', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 2.1.3', icon: 'pi pi-fw pi-bookmark' }, + ] + }, + { + label: 'Submenu 2.2', icon: 'pi pi-fw pi-bookmark', + items: [ + { label: 'Submenu 2.2.1', icon: 'pi pi-fw pi-bookmark' }, + { label: 'Submenu 2.2.2', icon: 'pi pi-fw pi-bookmark' } + ] + } + ] + } + ] + } + ]; + + const addClass = (element, className) => { + if (element.classList) + element.classList.add(className); + else + element.className += ' ' + className; + } + + const removeClass = (element, className) => { + if (element.classList) + element.classList.remove(className); + else + element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); + } + + const wrapperClass = classNames('layout-wrapper', { + 'layout-overlay': layoutMode === 'overlay', + 'layout-static': layoutMode === 'static', + 'layout-static-sidebar-inactive': staticMenuInactive && layoutMode === 'static', + 'layout-overlay-sidebar-active': overlayMenuActive && layoutMode === 'overlay', + 'layout-mobile-sidebar-active': mobileMenuActive, + 'p-input-filled': inputStyle === 'filled', + 'p-ripple-disabled': ripple === false, + 'layout-theme-light': layoutColorMode === 'light' + }); + + return ( +
+ + + + +
+ +
+ +
+
+ } /> + + + + + + + + + + + + + + + + + } /> + + + + + + + + + + + + +
+ + +
+ + + + +
+
+ + +
+ + ); + +} + +export default DashboardAdmin; diff --git a/web-ui/web-react/src/components/LocalStorage.js b/web-ui/web-react/src/components/LocalStorage.js new file mode 100644 index 00000000..37edbadb --- /dev/null +++ b/web-ui/web-react/src/components/LocalStorage.js @@ -0,0 +1,17 @@ +import React, { useRef } from "react"; + +function LocalStorage(){ + const data=useRef(); + const handleClick=()=>{ + console.log(data.current.value,"initial value") + localStorage.setItem("inputValue",data.current.value) + } + console.log(localStorage.getItem("inputValue"),"****") + return( + <> + + + + ); +} +export default LocalStorage; \ 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 new file mode 100644 index 00000000..206a7ab1 --- /dev/null +++ b/web-ui/web-react/src/components/LoginLocalStorage.js @@ -0,0 +1,104 @@ +import DashboardAdmin from "./DashboardAdmin"; +import React, { Component, Fragment } from 'react'; +import Cookies from 'universal-cookie'; +import { InputText } from 'primereact/inputtext'; + +const baseUrl = "http://localhost:4000/user/loginUser"; +const cookies = new Cookies(); + + +class LoginLocalStorage extends Component { + state = { + form: { + username: '', + password: '' + } + } + + handleChange = async e => { + await this.setState({ + form: { + ...this.state.form, + [e.target.name]: e.target.value + } + }); + } + + iniciarSesion = async () => { + const data = { + email: this.state.form.email, + password: this.state.form.password + } + + await fetch(baseUrl, { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }) + .then(response => { + 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.username, { path: "/" }); + alert(`Bienvenido ${user.name}`); + window.location.href = "./menu"; + } else { + alert('El usuario o la contraseña no son correctos'); + } + }) + .catch(error => { + console.log(error); + }) + + + + } + + componentDidMount() { + if (cookies.get('email')) { + window.location.href = "./menu"; + } + } + + + render() { + return ( + + +
+
+
+
Iniciar Sesión
+
+
+ + +
+
+ + +
+ + +
+
+
+
+ +
+ + + + ); + } +} + +export default LoginLocalStorage; \ No newline at end of file diff --git a/web-ui/web-react/src/index.js b/web-ui/web-react/src/index.js index fb5e7a3f..991c96b9 100644 --- a/web-ui/web-react/src/index.js +++ b/web-ui/web-react/src/index.js @@ -9,7 +9,8 @@ import ScrollToTop from './ScrollToTop'; ReactDOM.render( - + + , document.getElementById('root') diff --git a/web-ui/web-react/src/pages/Menu.js b/web-ui/web-react/src/pages/Menu.js new file mode 100644 index 00000000..379eb986 --- /dev/null +++ b/web-ui/web-react/src/pages/Menu.js @@ -0,0 +1,35 @@ +import React, { Component } from 'react'; +import Cookies from 'universal-cookie'; + +const cookies = new Cookies(); + +class Menu extends Component { + cerrarSesion=()=>{ + cookies.remove('id', {path: "/"}); + cookies.remove('name', {path: "/"}); + cookies.remove('email', {path: "/"}); + window.location.href='/'; + } + + componentDidMount() { + if(!cookies.get('email')){ + window.location.href="./"; + } + } + + render() { + console.log('id: '+ cookies.get('id')); + console.log('name: '+cookies.get('name')); + console.log('email: '+cookies.get('email')); + return ( +
+ Menu Principal + +
+ +
+ ); + } +} + +export default Menu; \ No newline at end of file diff --git a/web-ui/web-react/src/routes/Routes.js b/web-ui/web-react/src/routes/Routes.js new file mode 100644 index 00000000..a9d8860a --- /dev/null +++ b/web-ui/web-react/src/routes/Routes.js @@ -0,0 +1,17 @@ +import React from 'react'; +import {BrowserRouter, Switch, Route} from 'react-router-dom'; +import LoginLocalStorage from '../components/LoginLocalStorage'; +import Menu from '../pages/Menu'; + +function Routes() { + return ( + + + + + + + ); +} + +export default Routes; \ No newline at end of file