Browse Source

list item refactor and use node v16

amenpunk 3 years ago
parent
commit
e5e1936e38

+ 2 - 2
Jenkinsfile

@@ -12,14 +12,14 @@ pipeline {
12 12
         }
13 13
         stage('install dependencies') {
14 14
             steps {
15
-                nvm( version : '14.18.3' ){
15
+                nvm( version : '16.13.2' ){
16 16
                     sh 'npm install'
17 17
                 }
18 18
             }
19 19
         }
20 20
         stage('build') {
21 21
             steps {
22
-                nvm( version : '14.18.3' ){
22
+                nvm( version : '16.13.2' ){
23 23
                     sh 'npm run build'
24 24
                 }
25 25
             }

File diff suppressed because it is too large
+ 10296 - 18059
package-lock.json


+ 4 - 2
package.json

@@ -1,5 +1,4 @@
1 1
 {
2
-  "homepage": "http://clubdit.ditca.org/psicoadmin/",
3 2
   "name": "psicoadmin",
4 3
   "version": "0.1.0",
5 4
   "private": true,
@@ -22,10 +21,13 @@
22 21
     "react-dom": "^17.0.2",
23 22
     "react-router": "6.2.1",
24 23
     "react-router-dom": "6.2.1",
25
-    "react-scripts": "4.0.3",
24
+    "react-scripts": "^5.0.0",
26 25
     "web-vitals": "^1.0.1",
27 26
     "yup": "^0.32.11"
28 27
   },
28
+  "resolutions": {
29
+    "react-error-overlay": "6.0.9"
30
+  },
29 31
   "scripts": {
30 32
     "start": "react-scripts start",
31 33
     "build": "react-scripts build",

+ 4 - 1
src/Components/Dashboard.js

@@ -250,7 +250,10 @@ function DashboardContent() {
250 250
                     </Toolbar>
251 251
                     <Divider />
252 252
                     <List>
253
-                        <MainListItems AppBarVisible={open}  setAppBarVisible={setOpen} />
253
+                        <MainListItems 
254
+                            AppBarVisible={open}  
255
+                            setAppBarVisible={setOpen} 
256
+                        />
254 257
                     </List>
255 258
                     <Divider />
256 259
                     <List>

+ 0 - 4
src/Components/PrivateRoute.js

@@ -4,13 +4,9 @@ import useAuth from '../Auth/useAuth';
4 4
 export default function RequireAuth({ children }) {
5 5
     let auth = useAuth();
6 6
     let location = useLocation();
7
-
8
-    console.log('check if is logged in private route ')
9
-
10 7
     if (!auth.isLogged()) {
11 8
         return <Navigate to="/login" state={{ from: location }} replace />;
12 9
     }
13
-
14 10
     return children;
15 11
 }
16 12
 

+ 2 - 2
src/Components/Routes.js

@@ -1,5 +1,5 @@
1
-import React, {useEffect} from 'react'
2
-import { Routes, Route,useNavigate, Navigate } from "react-router-dom";
1
+import React from 'react'
2
+import { Routes, Route, Navigate } from "react-router-dom";
3 3
 
4 4
 import { Dashboard } from "./Dashboard";
5 5
 import { Login } from '../Pages/Login'

+ 32 - 71
src/Components/listItems.js

@@ -25,28 +25,19 @@ import SupportAgentIcon from '@mui/icons-material/SupportAgent';
25 25
 import Collapse from '@mui/material/Collapse';
26 26
 import ExpandLess from '@mui/icons-material/ExpandLess';
27 27
 import ExpandMore from '@mui/icons-material/ExpandMore';
28
-import { useNavigate } from 'react-router-dom'
29
-
30
-const SubMenuList = [5,6,7,8,9]
28
+import { useNavigate, useResolvedPath, useMatch } from 'react-router-dom'
31 29
 
32 30
 function SubMenuItem (props) {
33 31
 
34 32
     let navigate = useNavigate()
35
-
36
-    function change (event){
37
-        props.change(event, props.index)
38
-        if(props.route){
39
-            navigate(props.route)
40
-        }
41
-    } 
42
-
43
-    let isOn = props.selected === props.index
33
+    let resolved = useResolvedPath(props.route);
34
+    let match = useMatch({ path: resolved.pathname, end: true });
44 35
 
45 36
     return(
46 37
         <ListItem 
47
-            sx={{ pl: 9}}
48
-            selected={isOn}
49
-            onClick={change} 
38
+            sx={{ pl: 9,  color : '#25344f'}}
39
+            selected={match}
40
+            onClick={() => navigate(props.route)} 
50 41
             button
51 42
         >
52 43
             <ListItemText 
@@ -62,27 +53,21 @@ function SubMenuItem (props) {
62 53
     )
63 54
 }
64 55
 
65
-function Item (props) {
66
-
56
+function NavItem (props) {
57
+    
67 58
     let navigate = useNavigate()
68
-
69
-    function change (event){
70
-        console.log('change >>> ', props)
71
-        props.change(event, props.index)
72
-        navigate(props.route)
73
-    } 
74
-
75
-    let isOn = props.selected === props.index
59
+    let resolved = useResolvedPath(props.route);
60
+    let match = useMatch({ path: resolved.pathname, end: true });
76 61
 
77 62
     return(
78 63
         <ListItem
79 64
             sx={{ color : '#25344f'}}
80
-            selected={isOn}
81
-            onClick={change} 
65
+            selected={match}
66
+            onClick={() => navigate(props.route) } 
82 67
             button
83 68
         >
84 69
             <ListItemIcon>
85
-                {props.icon}
70
+                {props.icon && props.icon}
86 71
             </ListItemIcon>
87 72
             <ListItemText 
88 73
                 sx={{
@@ -100,36 +85,9 @@ function Item (props) {
100 85
 
101 86
 export const MainListItems = (props) =>  {
102 87
 
103
-    const [selectedIndex, setSelectedIndex] = React.useState(0);
104
-
105
-
106
-    const handleListItemClick = (event, index) => {
107
-        setSelectedIndex(index);
108
-    };
109 88
 
110 89
     const [open, setOpen] = React.useState(false);
111 90
 
112
-    React.useEffect( () => {
113
-
114
-        if(!props.AppBarVisible ){
115
-            return setOpen(false)
116
-        }
117
-
118
-        if( SubMenuList.includes(selectedIndex) && !open ){
119
-            if(props.AppBarVisible){
120
-                return setOpen(false)
121
-            }else{
122
-                return setOpen(true)
123
-            }
124
-        }
125
-
126
-        if( !SubMenuList.includes(selectedIndex) && !props.AppBarVisible ){
127
-            return setOpen(false)
128
-        }
129
-
130
-
131
-    }, [props, selectedIndex, open])
132
-
133 91
     const showPruebas = () => {
134 92
         if(!props.AppBarVisible){
135 93
             props.setAppBarVisible(true);
@@ -139,14 +97,17 @@ export const MainListItems = (props) =>  {
139 97
 
140 98
     return(
141 99
         <List>
100
+
142 101
             <ListSubheader inset>MENÚ</ListSubheader>
143
-            <Item icon={<HomeIcon/>} index={0} selected={selectedIndex} change={handleListItemClick} title="Inicio" route="home" />
144
-            <Item icon={<WorkIcon/>} index={1} selected={selectedIndex} change={handleListItemClick} title="Puestos" route="puestos" />
145
-            <Item icon={<VisibilityOffIcon/>} selected={selectedIndex}  change={handleListItemClick} index={2} title="Contraseñas" route="contrasenas" />
146
-            <Item icon={<PeopleAltIcon/>} selected={selectedIndex}  change={handleListItemClick} index={3} title="Expedientes" route="expedientes" />
147
-            <Item icon={<EqualizerIcon/>} selected={selectedIndex}  change={handleListItemClick} index={4} title="Resultados" route="resultados" />
148 102
 
149
-            <ListItem selected={ SubMenuList.includes(selectedIndex) } onClick={showPruebas}>
103
+            <NavItem icon={<HomeIcon/>} title="Inicio" route="home" />
104
+            <NavItem icon={<WorkIcon/>} title="Puestos" route="puestos" />
105
+            <NavItem icon={<VisibilityOffIcon/>}   index={2} title="Contraseñas" route="contrasenas" />
106
+            <NavItem icon={<PeopleAltIcon/>}  title="Expedientes" route="expedientes" />
107
+            <NavItem icon={<EqualizerIcon/>} title="Resultados" route="resultados" />
108
+
109
+            {/*<ListItem selected={false} onClick={showPruebas}>*/}
110
+            <ListItem onClick={showPruebas}>
150 111
                 <ListItemIcon>
151 112
                     <FingerprintIcon />
152 113
                 </ListItemIcon>
@@ -168,17 +129,17 @@ export const MainListItems = (props) =>  {
168 129
             <Collapse in={open} timeout="auto" unmountOnExit>
169 130
                 <List component="div" disablePadding>
170 131
 
171
-                    <SubMenuItem route="pruebas/crear" selected={selectedIndex} index={5} change={handleListItemClick} title="Crear Prueba" />
172
-                    <SubMenuItem route="pruebas/listar" change={handleListItemClick} selected={selectedIndex} index={6} title="Listado de pruebas" />
173
-                    <SubMenuItem route="pruebas/aplicar"  selected={selectedIndex} index={7} change={handleListItemClick} title="Aplicar" />
174
-                    <SubMenuItem selected={selectedIndex} index={8} change={handleListItemClick} title="Respuestas" />
175
-                    <SubMenuItem selected={selectedIndex} index={9} change={handleListItemClick} title="Calificaciones" />
132
+                    <NavItem route="pruebas/crear" title="Crear Prueba" />
133
+                    <NavItem route="pruebas/listar"  title="Listado de pruebas" />
134
+                    <NavItem route="pruebas/aplicar"  title="Aplicar" />
135
+                    <NavItem route="pruebas/respuestas" title="Respuestas" />
136
+                    <NavItem route="pruebas/calificaciones" title="Calificaciones" />
176 137
 
177 138
                 </List>
178 139
             </Collapse>
179 140
 
180
-            <Item icon={<MiscellaneousServicesIcon/>} selected={selectedIndex}  change={handleListItemClick} index={10} title="Configuraciones" route="configuraciones" />
181
-            <Item icon={<HistoryIcon/>} selected={selectedIndex}  change={handleListItemClick} index={11} title="Historial" route="historial" />
141
+            <NavItem icon={<MiscellaneousServicesIcon/>} title="Configuraciones" route="configuraciones" />
142
+            <NavItem icon={<HistoryIcon/>} title="Historial" route="historial" />
182 143
         </List>
183 144
     )
184 145
 };
@@ -186,8 +147,8 @@ export const MainListItems = (props) =>  {
186 147
 export const secondaryListItems = (
187 148
     <Nav>
188 149
         <ListSubheader inset>EXTRAS</ListSubheader>
189
-        <Item selected={false} icon={<StarIcon/>} title="Elementos" route="/work" />
190
-        <Item selected={false} icon={<OndemandVideoIcon/>} title="Tutoriales" route="/work" />
191
-        <Item selected={false} icon={<SupportAgentIcon/>} title="Asistencia Técnica" route="/work" />
150
+        <NavItem selected={false} icon={<StarIcon/>} title="Elementos" route="/work" />
151
+        <NavItem selected={false} icon={<OndemandVideoIcon/>} title="Tutoriales" route="/work" />
152
+        <NavItem selected={false} icon={<SupportAgentIcon/>} title="Asistencia Técnica" route="/work" />
192 153
     </Nav>
193 154
 );

+ 2 - 1
src/Pages/Login.jsx

@@ -47,10 +47,11 @@ export function Login() {
47 47
     };
48 48
 
49 49
     React.useEffect(() => {
50
+        console.log(auth)
50 51
         if(auth.isLogged()){
51 52
             return navigate('/dashboard/home')
52 53
         }    
53
-    }, [])
54
+    }, [auth,navigate])
54 55
 
55 56
 
56 57
     return (

+ 15 - 15
src/Pages/PruebaNueva.jsx

@@ -153,9 +153,9 @@ export function PruebaNueva() {
153 153
                                             <div className="respuesta_pregunta">
154 154
                                                 <div className="radio">
155 155
                                                         <input onChange={(event)=> console.log(event.target.value)} id="true" type="radio" name="gender" value="true" />
156
-                                                        <label for="true">Verdadero</label>
156
+                                                        <label htmlFor="true">Verdadero</label>
157 157
                                                         <input id="false" type="radio" name="gender" value="false"/>
158
-                                                        <label for="false">Falso</label>
158
+                                                        <label htmlFor="false">Falso</label>
159 159
                                                 </div>
160 160
                                             </div>
161 161
                                         </div>
@@ -166,15 +166,15 @@ export function PruebaNueva() {
166 166
                                             <div className="respuesta_pregunta">
167 167
                                                 <div className="radio">
168 168
                                                         <input id="opcion1" type="radio" name="gender" value="opcion1"/>
169
-                                                        <label for="opcion1">Opción 1</label>
169
+                                                        <label htmlFor="opcion1">Opción 1</label>
170 170
                                                         <input id="opcion2" type="radio" name="gender" value="opcion2" />
171
-                                                        <label for="opcion2">Opción 2</label>
171
+                                                        <label htmlFor="opcion2">Opción 2</label>
172 172
                                                         <input id="opcion3" type="radio" name="gender" value="opcion3"/>
173
-                                                        <label for="opcion3">Opción 3</label>
173
+                                                        <label htmlFor="opcion3">Opción 3</label>
174 174
                                                         <input id="opcion4" type="radio" name="gender" value="opcion4"/>
175
-                                                        <label for="opcion4">Opción 4</label>
175
+                                                        <label htmlFor="opcion4">Opción 4</label>
176 176
                                                         <input id="opcion5" type="radio" name="gender" value="opcion5"/>
177
-                                                        <label for="opcion5">Opción 5</label>
177
+                                                        <label htmlFor="opcion5">Opción 5</label>
178 178
                                                 </div>
179 179
                                             </div>
180 180
                                         </div>
@@ -183,7 +183,7 @@ export function PruebaNueva() {
183 183
                                                 <span>Pregunta 4</span><input type="text" name="pregunta" placeholder="Ve la siguiente imagen y encuentra la faltante" className="input_pregunta"/>
184 184
                                                 <div className="button_subir_foto_pregunta">
185 185
                                                         <div className="form-group">
186
-                                                            <label style={{ color : 'white' }} for="upload" className="btn d-inline-block btn-info">Subir imagen</label>
186
+                                                            <label style={{ color : 'white' }} htmlFor="upload" className="btn d-inline-block btn-info">Subir imagen</label>
187 187
                                                             <input type="file" name="" id="upload" />
188 188
                                                         </div>
189 189
                                                 </div>
@@ -194,17 +194,17 @@ export function PruebaNueva() {
194 194
                                             <div className="respuesta_pregunta">
195 195
                                                 <div className="button_subir_foto_pregunta">
196 196
                                                         <div className="form-group">
197
-                                                            <label style={{  color : 'white' }} for="upload" className="btn d-inline-block btn-info">Añadir respuesta</label>
197
+                                                            <label style={{  color : 'white' }} htmlFor="upload" className="btn d-inline-block btn-info">Añadir respuesta</label>
198 198
                                                             <input type="file" name="" id="upload" />
199 199
                                                         </div>
200 200
                                                 </div>
201 201
                                                     <div id="sites">
202
-                                                        <input type="radio" name="site" id="option1" value="option1" />A.<label for="option1"><img src={Respuesta1} alt="Opción 1" /></label>
203
-                                                        <input type="radio" name="site" id="option2" value="option2" />B.<label for="option2"><img src={Respuesta2} alt="Opción 2" /></label>
204
-                                                        <input type="radio" name="site" id="option3" value="option3" />C.<label for="option3"><img src={Respuesta3} alt="Opción 3" /></label>
205
-                                                        <input type="radio" name="site" id="option1" value="option1" />D.<label for="option1"><img src={Respuesta1} alt="Opción 1" /></label>
206
-                                                        <input type="radio" name="site" id="option2" value="option2" />E.<label for="option2"><img src={Respuesta2} alt="Opción 2" /></label>
207
-                                                        <input type="radio" name="site" id="option3" value="option3" />F.<label for="option3"><img src={Respuesta3} alt="Opción 3" /></label>
202
+                                                        <input type="radio" name="site" id="option1" value="option1" />A.<label htmlFor="option1"><img src={Respuesta1} alt="Opción 1" /></label>
203
+                                                        <input type="radio" name="site" id="option2" value="option2" />B.<label htmlFor="option2"><img src={Respuesta2} alt="Opción 2" /></label>
204
+                                                        <input type="radio" name="site" id="option3" value="option3" />C.<label htmlFor="option3"><img src={Respuesta3} alt="Opción 3" /></label>
205
+                                                        <input type="radio" name="site" id="option1" value="option1" />D.<label htmlFor="option1"><img src={Respuesta1} alt="Opción 1" /></label>
206
+                                                        <input type="radio" name="site" id="option2" value="option2" />E.<label htmlFor="option2"><img src={Respuesta2} alt="Opción 2" /></label>
207
+                                                        <input type="radio" name="site" id="option3" value="option3" />F.<label htmlFor="option3"><img src={Respuesta3} alt="Opción 3" /></label>
208 208
                                                     </div>
209 209
                                             </div>
210 210
                                             <div className="form-group-guardar-prueba">