Browse Source

multiple users in password creation

amenpunk 2 years ago
parent
commit
d588be422b

+ 31 - 29
src/Components/Modal/PasswordModal.jsx

@@ -27,11 +27,12 @@ export function HelpModal(props) {
27 27
     sendmail: true,
28 28
     nombrepuesto: null,
29 29
     nombreEmpresa: null,
30
-    candidatos : [{
30
+    candidatos : [
31
+      {
31 32
       'nombres': 'ming',
32 33
       'apellidos': 'mecca',
33
-      'mail': 'ming@gmail.com',
34
-    }]
34
+      'mail': 'ming@gmail.com', }
35
+    ]
35 36
   });
36 37
 
37 38
   const isStepSkipped = (step) => {
@@ -62,6 +63,7 @@ export function HelpModal(props) {
62 63
       sendmail: true,
63 64
       nombrepuesto: null,
64 65
       nombreEmpresa: null,
66
+      candidatos : []
65 67
     })
66 68
     setActiveStep(0);
67 69
   };
@@ -71,41 +73,41 @@ export function HelpModal(props) {
71 73
     {
72 74
       label: 'Puesto',
73 75
       operation:
74
-        <Puesto
75
-          handleNext={handleNext}
76
-          handleBack={handleBack}
77
-          password={password}
78
-          setPassword={setPassword}
76
+      <Puesto
77
+        handleNext={handleNext}
78
+        handleBack={handleBack}
79
+        password={password}
80
+        setPassword={setPassword}
79 81
         />
80 82
     },
81 83
     {
82 84
       label: 'Contraseña',
83 85
       operation:
84
-        <Password
85
-          handleNext={handleNext}
86
-          handleBack={handleBack}
87
-          password={password}
88
-          setPassword={setPassword}
86
+      <Password
87
+        handleNext={handleNext}
88
+        handleBack={handleBack}
89
+        password={password}
90
+        setPassword={setPassword}
89 91
         />
90 92
     },
91 93
     {
92 94
       label: 'Candidatos',
93 95
       operation:
94
-        <Candidato
95
-          handleNext={handleNext}
96
-          handleBack={handleBack}
97
-          password={password}
98
-          setPassword={setPassword}
96
+      <Candidato
97
+        handleNext={handleNext}
98
+        handleBack={handleBack}
99
+        password={password}
100
+        setPassword={setPassword}
99 101
         />
100 102
     },
101 103
     {
102 104
       label: 'Confirmar',
103 105
       operation:
104
-        <Resume
105
-          handleBack={handleBack}
106
-          password={password}
107
-          handleClose={handleClose}
108
-          handleReset={handleReset}
106
+      <Resume
107
+        handleBack={handleBack}
108
+        password={password}
109
+        handleClose={handleClose}
110
+        handleReset={handleReset}
109 111
         />
110 112
     },
111 113
   ];
@@ -155,14 +157,14 @@ export function HelpModal(props) {
155 157
               </Box>
156 158
             </React.Fragment>
157 159
           ) : (
158
-            <React.Fragment>
160
+              <React.Fragment>
159 161
 
160
-              <Box style={{ padding: 18, marginTop: 2 }}>
161
-                {steps[activeStep].operation}
162
-              </Box>
162
+                <Box style={{ padding: 18, marginTop: 2 }}>
163
+                  {steps[activeStep].operation}
164
+                </Box>
163 165
 
164
-            </React.Fragment>
165
-          )}
166
+              </React.Fragment>
167
+            )}
166 168
         </Box>
167 169
 
168 170
       </Modal.Body>

+ 2 - 2
src/Components/Password/Rows.js

@@ -46,9 +46,9 @@ export const niveles_educativos = [
46 46
 
47 47
 export function Build(pwds) {
48 48
   return pwds.map(password => {
49
-    let { pwd, deadpwd, dateToActived, plaza_id } = password
49
+    let { pwd, plaza_id } = password
50 50
     return {
51
-      name: pwd,
51
+      name: atob( pwd ),
52 52
       activacion: new Date().toUTCString(),//dateToActived, 
53 53
       dead: new Date().toUTCString(), //deadpwd,
54 54
       op: <Operation plz={plaza_id} pwd={pwd} />

+ 2 - 2
src/Components/Password/Steps/MailTable.jsx

@@ -25,7 +25,7 @@ export function MailTable(props) {
25 25
           </TableRow>
26 26
         </TableHead>
27 27
         <TableBody>
28
-          {users.map((row,i) => (
28
+          {users ? users.map((row,i) => (
29 29
             <TableRow key={i} sx={{ '&:last-child td, &:last-child th': { border: 0 } }} >
30 30
               <TableCell component="th" scope="row">
31 31
                 {row.mail}
@@ -36,7 +36,7 @@ export function MailTable(props) {
36 36
                 <DisabledByDefault onClick={() => remove(row.mail)} color="primary"/>
37 37
               </TableCell>
38 38
             </TableRow>
39
-          ))}
39
+          ) ) :  null }
40 40
         </TableBody>
41 41
       </Table>
42 42
     </TableContainer>

+ 10 - 4
src/Components/Password/Steps/candidato.jsx

@@ -8,11 +8,10 @@ import {
8 8
 
9 9
 import { AddCircle } from '@mui/icons-material/';
10 10
 import { MailTable } from './MailTable';
11
-
11
+import toast, { Toaster } from 'react-hot-toast';
12 12
 
13 13
 export function Candidato(props) {
14 14
 
15
-
16 15
   const CandidatoSchema = Yup.object().shape({
17 16
     nombres:
18 17
       Yup.string()
@@ -32,13 +31,19 @@ export function Candidato(props) {
32 31
     initialValues: {
33 32
       nombres: "",
34 33
       apellidos: "",
35
-      sendmail: "",
34
+      sendmail: true,
36 35
       mail: "",
37
-      nombrepuesto: password.nombrepuesto ? password.nombrepuesto : password.puesto[0].nombrepuesto,
36
+      nombrepuesto: '',// password.nombrepuesto ? password.nombrepuesto : password.puesto[0].nombrepuesto,
38 37
       nombreEmpresa: 'test'//password.nombreEmpresa ? password.nombreEmpresa : auth.getProfile().nombre,
39 38
       // nombreEmpresa: password.nombreEmpresa ? password.nombreEmpresa : auth.getProfile().nombre,
40 39
     },
41 40
     onSubmit: () => {
41
+      console.log(password.candidatos)
42
+      if(password.candidatos.length <= 0){
43
+        toast.error("Seleciona almenos un destino")
44
+        // alert("seleciona almenos un destino")
45
+        return;
46
+      }
42 47
       //setPassword({ ...password, ...fields })
43 48
       handleNext()
44 49
     },
@@ -134,6 +139,7 @@ export function Candidato(props) {
134 139
           </Box>
135 140
 
136 141
         </Stack>
142
+        <Toaster position="top-right" />
137 143
       </Form>
138 144
     </FormikProvider>
139 145
   );

+ 2 - 0
src/Components/Password/Steps/password.jsx

@@ -12,6 +12,8 @@ import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
12 12
 
13 13
 
14 14
 export function Password(props) {
15
+    
16
+    // console.log(props.password)
15 17
 
16 18
     const [uid,setUID] = React.useState(null);
17 19
 

+ 2 - 2
src/Components/Password/Steps/puesto.js

@@ -15,7 +15,6 @@ import {
15 15
 
16 16
 import { useQuery } from 'react-query';
17 17
 import { Service } from '../../../Utils/HTTP.js'
18
-// import useAuth from '../../../Auth/useAuth'
19 18
 import { useSelector } from 'react-redux'
20 19
 
21 20
 const delete_icon = <CheckBoxOutlineBlankIcon fontSize="small" />;
@@ -24,8 +23,9 @@ const checkedIcon = <CheckBoxIcon fontSize="small" />;
24 23
 
25 24
 export function Puesto(props) {
26 25
 
26
+  // console.log(props.password)
27
+
27 28
   const auth = useSelector((state) => state.token);
28
-  // const token = auth.getToken();
29 29
 
30 30
   const PlazaScheme = Yup.object().shape({
31 31
     puesto: 

+ 59 - 49
src/Components/Password/Steps/resume.jsx

@@ -2,8 +2,8 @@ import * as React from 'react';
2 2
 
3 3
 import { Table } from 'react-bootstrap';
4 4
 import {
5
-    Box, Button, LinearProgress,
6
-    Backdrop, CircularProgress
5
+  Box, Button, LinearProgress,
6
+  Backdrop, CircularProgress
7 7
 } from '@mui/material';
8 8
 
9 9
 import toast, { Toaster } from 'react-hot-toast';
@@ -15,25 +15,26 @@ import { useSelector } from 'react-redux';
15 15
 import { createTheme, ThemeProvider } from '@mui/material/styles';
16 16
 
17 17
 let theme = createTheme({
18
-    status: {
19
-        success: '#fd4b4b'
18
+  status: {
19
+    success: '#fd4b4b'
20
+  },
21
+  palette: {
22
+    primary: {
23
+      main: '#fd4b4b',
20 24
     },
21
-    palette: {
22
-        primary: {
23
-            main: '#fd4b4b',
24
-        },
25
-        secondary: {
26
-            main: '#fd4b4b',
27
-        },
25
+    secondary: {
26
+      main: '#fd4b4b',
28 27
     },
28
+  },
29 29
 });
30 30
 
31 31
 export function Resume(props) {
32 32
 
33
-  let { handleBack, password: key, handleClose,handleReset } = props
33
+  let { handleBack, password: key, handleClose, handleReset } = props
34
+
35
+  console.log(key)
34 36
 
35 37
   const fmt = React.useRef({ weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' })
36
-  const [pwdID, setPwdID] = React.useState(null);
37 38
   const [loading, setLoading] = React.useState(false);
38 39
 
39 40
   const auth = useSelector((state) => state.token)
@@ -52,62 +53,71 @@ export function Resume(props) {
52 53
 
53 54
   const pwdMutation = useMutation('password', savePassword);
54 55
   const candiMutation = useMutation('candidato', saveCandidato);
56
+  console.log(candiMutation)
55 57
 
56 58
   const saveStepper = () => {
57 59
 
58 60
     setLoading(true);
59 61
 
60
-    let {
61
-      deadpwd, dateToActived, puesto, 
62
-      pwd,nombreEmpresa,nombrepuesto, candidatos
63
-    } = key;
62
+    let { deadpwd, dateToActived } = key;
64 63
 
65 64
     let pwdBody = {
66 65
       id: -1,
67
-      pwd: btoa(pwd),
66
+      pwd: btoa(key.pwd),
68 67
       link: "www.psicoadmin.com",
69 68
       deadpwd: new Date(deadpwd).toISOString(),
70 69
       state: 1,
71 70
       dateToActived: new Date(dateToActived).toISOString(),
72
-      plaza_id: puesto[0].id
71
+      plaza_id: key.puesto[0].id
73 72
     }
74 73
 
74
+    console.log("PWD BODY: ", pwdBody)
75
+
75 76
     pwdMutation.mutate(pwdBody, {
76
-      onSuccess: (data) => {
77
-
78
-        let { id: password_id } = data.data;
79
-        setPwdID(password_id);
80
-
81
-        let candidatoBody = {
82
-          id: -1,
83
-          //nombres,
84
-          //apellidos,
85
-          //sendmail: sendmail ? 1 : 0,
86
-          //mail,
87
-          idContrasenia: password_id,
88
-          nombrepuesto,
89
-          nombreEmpresa
90
-        }
91
-
92
-        candiMutation.mutate(candidatoBody, {
93
-          onSuccess: (data) => {
77
+      onSuccess: (result) => {
78
+
79
+        let { id: idContrasenia } = result.data;
80
+
81
+
82
+        let candidatos_body = key.candidatos.map((candi) => ({
83
+          "id": -1,
84
+          "nombres": candi.nombres,
85
+          "apellidos": candi.apellidos,
86
+          "mail": candi.mail,
87
+          "sendmail": 0,
88
+          "idContrasenia": idContrasenia,
89
+          "nombrepuesto": 'Senior Software',
90
+          "nombreEmpresa": 'Google'
91
+        }))
92
+
93
+        console.log(candidatos_body)
94
+
95
+        // setLoading(false);
96
+        // return;
94 97
 
98
+        queryClient.invalidateQueries('passwords')
99
+              setLoading(false);
100
+              handleClose();
101
+              handleReset();
102
+        /*
103
+
104
+        candiMutation.mutate(candidatos_body, {
105
+          onSuccess: (data) => {
95 106
             queryClient.invalidateQueries('passwords')
96 107
             toast.success("Contraseña agregada exitosamente!!")
97 108
             setTimeout(() => {
98
-              console.log("OK LETS GO >> ", data,pwdID)
109
+              console.log("OK LETS GO >> ", data)
99 110
               setLoading(false);
100 111
               handleClose();
101 112
               handleReset();
102 113
             }, 1000)
103
-
104 114
           },
105 115
           onError: () => {
106 116
             toast.error("Ups!! error al crear el candidato")
107 117
             setLoading(false);
108 118
           }
109 119
         })
110
-
120
+*/
111 121
 
112 122
       },
113 123
       onError: () => {
@@ -118,13 +128,13 @@ export function Resume(props) {
118 128
     })
119 129
   }
120 130
 
121
-  const getLi = (user) => {
122
-    return ( 
123
-      <li style={{ listStyleType: 'none'}}>
131
+  const getLi = (user, i) => {
132
+    return (
133
+      <li key={i} style={{ listStyleType: 'none' }}>
124 134
         {user.nombres + " " + user.apellidos} - {user.mail}
125
-      </li> 
135
+      </li>
126 136
     )
127
-   }
137
+  }
128 138
 
129 139
   return (
130 140
     <React.Fragment>
@@ -138,17 +148,17 @@ export function Resume(props) {
138 148
           <thead>
139 149
             <tr className="table_password">
140 150
               <th>{"Contraseña: "}</th>
141
-              <th>{ key.pwd } - {btoa(key.pwd)}</th>
151
+              <th>{key.pwd} - {btoa(key.pwd)}</th>
142 152
             </tr>
143 153
           </thead>
144 154
           <tbody>
145 155
             <tr>
146 156
               <td className="title_td">{"Candidatos:"}</td>
147 157
               <td colSpan={2}>
148
-                <ul style={{ margin:0, padding:0}}>
149
-                  {key.candidatos.map(u => getLi(u))}
158
+                <ul style={{ margin: 0, padding: 0 }}>
159
+                  {key.candidatos ? key.candidatos.map((u, i) => getLi(u, i)) : null}
150 160
                 </ul>
151
-                </td>
161
+              </td>
152 162
             </tr>
153 163
             <tr>
154 164
               <td className="title_td">{"Puesto:"}</td>

+ 0 - 7
src/Pages/ContrasV2.jsx

@@ -9,7 +9,6 @@ import { TableStyle, TextLabels } from '../Components/Password/TableStyle'
9 9
 import { useQuery } from 'react-query';
10 10
 import { Service } from '../Utils/HTTP.js'
11 11
 import { useSelector } from 'react-redux';
12
-import  { Loading } from '../Components/Generics/loading'
13 12
 
14 13
 export function Contrasv2() {
15 14
 
@@ -21,12 +20,6 @@ export function Contrasv2() {
21 20
   }
22 21
 
23 22
   const { data, status  } = useQuery('passwords', getAllPwd );
24
-  console.log(data,status)
25
-
26
-  if(status === 'loading'){
27
-    return <Loading/>
28
-  }
29
-
30 23
   const options = {
31 24
     filterType: 'checkbox',
32 25
     customToolbar: () => {