Browse Source

assign id in user sclie

amenpunk 2 years ago
parent
commit
3536d69437
5 changed files with 71 additions and 72 deletions
  1. 50 50
      src/Pages/HomeUser.jsx
  2. 1 1
      src/Pages/Logincs.jsx
  3. 14 14
      src/Pages/Prueba.jsx
  4. 4 5
      src/Pages/Pruebas/Cleaver.jsx
  5. 2 2
      src/Slices/userSlice.js

+ 50 - 50
src/Pages/HomeUser.jsx

@@ -1,65 +1,65 @@
1 1
 import { useState, useEffect } from 'react';
2
-import { Typography, Button, Box, Paper, Divider } from '@mui/material';
2
+import { Typography, Box, Paper, Divider } from '@mui/material';
3 3
 
4
-import useAuth from '../Auth/useAuth.js'
5 4
 import { Service } from '../Utils/HTTP.js';
6
-
7 5
 import { TestCard } from '../Components/HomeUser/TestCard';
8 6
 import { useSelector } from 'react-redux';
7
+import { Link } from 'react-router-dom'
9 8
 
10 9
 export function HomeUser(){
11 10
 
12
-    const auth = useAuth();
13
-    // const token = useRef(auth.getToken());
14
-    const [tests, setTests] = useState([]);
15
-    const [password, setPasword] = useState({});
16
-    const state = useSelector( state => state.token);
11
+  const [tests, setTests] = useState([]);
12
+  const [password, setPasword] = useState({});
13
+  const token = useSelector( state => state.token.token);
14
+  const profile = useSelector( state => state.user.profile);
15
+  console.log(profile)
17 16
 
18
-    useEffect(() => {
19
-        let { email , password} = auth.getProfile();
20
-        let rest = new Service(`/plaza/contrasenia/${password}/${email}`);
21
-        rest
22
-        .get(state.token)
23
-            .then(({ data }) => {
24
-                setTests(data.tests)
25
-                delete data.tests
26
-                setPasword(data);
27
-            })
28
-            .catch(erro => {
29
-                console.error("ERR : ", erro)
30
-            })
17
+  useEffect(() => {
18
+    let { email , password} = profile
19
+    let rest = new Service(`/plaza/contrasenia/${password}/${email}`);
20
+    rest
21
+      .get(token.token)
22
+      .then(({ data }) => {
23
+        setTests(data.tests)
24
+        delete data.tests
25
+        setPasword(data);
26
+      })
27
+      .catch(erro => {
28
+        console.error("ERR : ", erro)
29
+      })
31 30
 
32
-    },[state,auth])
31
+  },[token, profile])
33 32
 
34
-    return(
35
-        <div className="content-section">
36
-            <div className="main">
37
-                <Box sx={{ width: '100%' }}>
38
-                    <Paper elevation={2} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh'}}>
39
-                        <h2>
40
-                            Bienvenido al sistemas de pruebas psicometricas.
41
-                        </h2>
42
-                        <h3>Instrucciones Generales</h3>
43
-                        <Typography>
33
+  return(
34
+    <div className="content-section">
35
+      <div className="main">
36
+        <Box sx={{ width: '100%' }}>
37
+          <Paper elevation={2} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh'}}>
38
+            <h2>
39
+              Bienvenido al sistemas de pruebas psicometricas.
40
+            </h2>
41
+            <h3>Instrucciones Generales</h3>
42
+            <Typography>
44 43
 
45
-Bienvenido, el sistema tiene como objetivo evaluar diferentes características como medir y cuantificar los procesos cognoscitivos de la mente humana. Parar resolver las pruebas que están asignadas te recomendamos busques un lugar apropiado, ya que necesitaras en promedio 2 horas libre y es importante que se tenga el 100% de tu concentración.
46
-                        </Typography>
47
-                        <Divider style={{margin : 5}}/>
48
-                        <h5>Pruebas para {password.nombrepuesto}</h5>
49
-                        <div className="test_list" style={{ marginTop :15 }}> 
50
-                            {
51
-                            tests.map( test => {
52
-                                return (
53
-                                    <TestCard key={test.id} test={test} />
54
-                                )
55
-                            })
56
-                            }
57
-                        </div>
58
-                    </Paper>
59
-                    <Button  onClick={auth.logout}>Salir</Button>
60
-                </Box>
44
+              Bienvenido, el sistema tiene como objetivo evaluar diferentes características como medir y cuantificar los procesos cognoscitivos de la mente humana. Parar resolver las pruebas que están asignadas te recomendamos busques un lugar apropiado, ya que necesitaras en promedio 2 horas libre y es importante que se tenga el 100% de tu concentración.
45
+            </Typography>
46
+            <Divider style={{margin : 5}}/>
47
+            <h5>Pruebas para {password.nombrepuesto}</h5>
48
+            <div className="test_list" style={{ marginTop :15 }}> 
49
+              {
50
+              tests.map( test => {
51
+                return (
52
+                <Link to={`/user/prueba/${test.id}`}>
53
+                  <TestCard key={test.id} test={test} />
54
+                </Link>
55
+                )
56
+              })
57
+            }
61 58
             </div>
62
-        </div>
63
-    )
59
+          </Paper>
60
+        </Box>
61
+      </div>
62
+    </div>
63
+  )
64 64
 
65 65
 }

+ 1 - 1
src/Pages/Logincs.jsx

@@ -1,6 +1,6 @@
1 1
 import * as React from 'react';
2 2
 import toast, { Toaster } from 'react-hot-toast';
3
-import { Navigate, useNavigate } from 'react-router-dom'
3
+import { useNavigate } from 'react-router-dom'
4 4
 import jwt_decode from "jwt-decode";
5 5
 import { useDispatch , useSelector } from "react-redux";
6 6
 

+ 14 - 14
src/Pages/Prueba.jsx

@@ -1,25 +1,28 @@
1
-import React, { useMemo, useState } from 'react';
1
+import React, { useState } from 'react';
2 2
 import { Service } from '../Utils/HTTP'
3 3
 import { Box, Paper, Divider, Typography, Button } from '@mui/material'
4 4
 
5 5
 import toast, { Toaster } from 'react-hot-toast';
6 6
 import { useParams } from 'react-router-dom'
7
-import useAuth from '../Auth/useAuth.js';
8 7
 import { Cleaver } from './Pruebas/Cleaver';
9 8
 import { Header } from '../Components/Test/Cleaver/Header';
9
+import { useSelector, useDispatch } from 'react-redux';
10
+import { setRole } from '../Slices/userSlice'
10 11
 
11 12
 export function Prueba() {
12 13
 
13 14
   let { id } = useParams();
14
-  let auth = useAuth();
15
-  let token = useMemo(() => auth.getToken(), [auth])
15
+  // let token = useMemo(() => auth.getToken(), [auth])
16
+  let auth = useSelector((state) => state.token.token)
17
+  let profile = useSelector((state) => state.user)
18
+  let dispatch = useDispatch();
16 19
   let [data, setData] = useState({});
17
-  // let profile = auth.getProfile();
18
-  let [profile, setProfile] = useState(auth.getProfile)
20
+
21
+  console.log("PROFILE: ", profile)
19 22
 
20 23
   useState(() => {
21 24
     let rest = new Service(`/prueba/findid/${id}`)
22
-    rest.get(token.toString())
25
+    rest.get(auth.token)
23 26
       .then(resp => { 
24 27
           setData(resp.data)
25 28
         })
@@ -37,26 +40,23 @@ export function Prueba() {
37 40
       "score": "0",
38 41
       "mensaje": "0",
39 42
       "mensaje2": "0",
40
-      "idcontrasenia": profile.passid,
43
+      "idcontrasenia": profile.role.passid,
41 44
       "nombre": "assing CLEVAERR"
42
-
43 45
     }
44 46
 
45 47
     let rest = new Service("/prueba/asignacion");
46
-    rest.postQuery(body, token)
48
+    rest.postQuery(body, auth.token)
47 49
       .then(({ data: resp }) => {
48 50
         let { id: assingid } = resp
49 51
         toast.success("Asignación creada: ", assingid)
50
-        let new_profile = { ...profile, assingid }
51
-        auth.setProfile(new_profile)
52
-        setProfile(new_profile)
52
+        dispatch(setRole({ assingid }))
53 53
       })
54 54
       .catch(() => {
55 55
         toast.error("Error al crear la asignación")
56 56
       })
57 57
   }
58 58
 
59
-  if(profile.assingid){
59
+  if(profile.role.assingid){
60 60
     return <Cleaver/>
61 61
   }
62 62
 

+ 4 - 5
src/Pages/Pruebas/Cleaver.jsx

@@ -1,14 +1,13 @@
1
-import React, { useMemo } from 'react'
1
+import React from 'react'
2 2
 import { Service } from '../../Utils/HTTP'
3
-import useAuth from '../../Auth/useAuth.js';
4 3
 import { Question } from '../../Components/Test/Cleaver/Question.jsx'
5 4
 import { Box,Button } from '@mui/material'
6 5
 import toast, { Toaster } from 'react-hot-toast';
6
+import { useSelector } from 'react-redux';
7 7
 
8 8
 export function Cleaver() {
9 9
 
10
-  let auth = useAuth();
11
-  let token = useMemo(() => auth.getToken(), [auth])
10
+  let token = useSelector((state) => state.token.token);
12 11
 
13 12
   const [totalRespondidas, setRespondidas] = React.useState([]);
14 13
   const [totalPreguntas, setPreguntas] = React.useState([]);
@@ -27,7 +26,7 @@ export function Cleaver() {
27 26
     // TODO:
28 27
     // agregar el id correcto apartir del path
29 28
     let rest = new Service(`/prueba/findid/1`)
30
-    rest.get(token.toString())
29
+    rest.get(token.token)
31 30
       .then(({ data }) => {
32 31
         console.log(data.questions)
33 32
         setPreguntas(data.questions)

+ 2 - 2
src/Slices/userSlice.js

@@ -7,10 +7,10 @@ export const userSlice = createSlice({
7 7
   initialState,
8 8
   reducers: {
9 9
     setProfile: (state, action) => {
10
-      state.data = action.payload;
10
+      state.profile = action.payload;
11 11
     },
12 12
     setRole : (state, action ) => {
13
-      state.role = action.payload;
13
+      state.role = Object.assign({}, state.role, action.payload);
14 14
     }
15 15
   }
16 16
 })