Browse Source

multiple users in password creation

amenpunk 2 years ago
parent
commit
d588be422b

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

27
     sendmail: true,
27
     sendmail: true,
28
     nombrepuesto: null,
28
     nombrepuesto: null,
29
     nombreEmpresa: null,
29
     nombreEmpresa: null,
30
-    candidatos : [{
30
+    candidatos : [
31
+      {
31
       'nombres': 'ming',
32
       'nombres': 'ming',
32
       'apellidos': 'mecca',
33
       'apellidos': 'mecca',
33
-      'mail': 'ming@gmail.com',
34
-    }]
34
+      'mail': 'ming@gmail.com', }
35
+    ]
35
   });
36
   });
36
 
37
 
37
   const isStepSkipped = (step) => {
38
   const isStepSkipped = (step) => {
62
       sendmail: true,
63
       sendmail: true,
63
       nombrepuesto: null,
64
       nombrepuesto: null,
64
       nombreEmpresa: null,
65
       nombreEmpresa: null,
66
+      candidatos : []
65
     })
67
     })
66
     setActiveStep(0);
68
     setActiveStep(0);
67
   };
69
   };
71
     {
73
     {
72
       label: 'Puesto',
74
       label: 'Puesto',
73
       operation:
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
       label: 'Contraseña',
84
       label: 'Contraseña',
83
       operation:
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
       label: 'Candidatos',
94
       label: 'Candidatos',
93
       operation:
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
       label: 'Confirmar',
104
       label: 'Confirmar',
103
       operation:
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
               </Box>
157
               </Box>
156
             </React.Fragment>
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
         </Box>
168
         </Box>
167
 
169
 
168
       </Modal.Body>
170
       </Modal.Body>

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

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

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

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

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

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

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

12
 
12
 
13
 
13
 
14
 export function Password(props) {
14
 export function Password(props) {
15
+    
16
+    // console.log(props.password)
15
 
17
 
16
     const [uid,setUID] = React.useState(null);
18
     const [uid,setUID] = React.useState(null);
17
 
19
 

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

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

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

2
 
2
 
3
 import { Table } from 'react-bootstrap';
3
 import { Table } from 'react-bootstrap';
4
 import {
4
 import {
5
-    Box, Button, LinearProgress,
6
-    Backdrop, CircularProgress
5
+  Box, Button, LinearProgress,
6
+  Backdrop, CircularProgress
7
 } from '@mui/material';
7
 } from '@mui/material';
8
 
8
 
9
 import toast, { Toaster } from 'react-hot-toast';
9
 import toast, { Toaster } from 'react-hot-toast';
15
 import { createTheme, ThemeProvider } from '@mui/material/styles';
15
 import { createTheme, ThemeProvider } from '@mui/material/styles';
16
 
16
 
17
 let theme = createTheme({
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
 export function Resume(props) {
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
   const fmt = React.useRef({ weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' })
37
   const fmt = React.useRef({ weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' })
36
-  const [pwdID, setPwdID] = React.useState(null);
37
   const [loading, setLoading] = React.useState(false);
38
   const [loading, setLoading] = React.useState(false);
38
 
39
 
39
   const auth = useSelector((state) => state.token)
40
   const auth = useSelector((state) => state.token)
52
 
53
 
53
   const pwdMutation = useMutation('password', savePassword);
54
   const pwdMutation = useMutation('password', savePassword);
54
   const candiMutation = useMutation('candidato', saveCandidato);
55
   const candiMutation = useMutation('candidato', saveCandidato);
56
+  console.log(candiMutation)
55
 
57
 
56
   const saveStepper = () => {
58
   const saveStepper = () => {
57
 
59
 
58
     setLoading(true);
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
     let pwdBody = {
64
     let pwdBody = {
66
       id: -1,
65
       id: -1,
67
-      pwd: btoa(pwd),
66
+      pwd: btoa(key.pwd),
68
       link: "www.psicoadmin.com",
67
       link: "www.psicoadmin.com",
69
       deadpwd: new Date(deadpwd).toISOString(),
68
       deadpwd: new Date(deadpwd).toISOString(),
70
       state: 1,
69
       state: 1,
71
       dateToActived: new Date(dateToActived).toISOString(),
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
     pwdMutation.mutate(pwdBody, {
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
             queryClient.invalidateQueries('passwords')
106
             queryClient.invalidateQueries('passwords')
96
             toast.success("Contraseña agregada exitosamente!!")
107
             toast.success("Contraseña agregada exitosamente!!")
97
             setTimeout(() => {
108
             setTimeout(() => {
98
-              console.log("OK LETS GO >> ", data,pwdID)
109
+              console.log("OK LETS GO >> ", data)
99
               setLoading(false);
110
               setLoading(false);
100
               handleClose();
111
               handleClose();
101
               handleReset();
112
               handleReset();
102
             }, 1000)
113
             }, 1000)
103
-
104
           },
114
           },
105
           onError: () => {
115
           onError: () => {
106
             toast.error("Ups!! error al crear el candidato")
116
             toast.error("Ups!! error al crear el candidato")
107
             setLoading(false);
117
             setLoading(false);
108
           }
118
           }
109
         })
119
         })
110
-
120
+*/
111
 
121
 
112
       },
122
       },
113
       onError: () => {
123
       onError: () => {
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
         {user.nombres + " " + user.apellidos} - {user.mail}
134
         {user.nombres + " " + user.apellidos} - {user.mail}
125
-      </li> 
135
+      </li>
126
     )
136
     )
127
-   }
137
+  }
128
 
138
 
129
   return (
139
   return (
130
     <React.Fragment>
140
     <React.Fragment>
138
           <thead>
148
           <thead>
139
             <tr className="table_password">
149
             <tr className="table_password">
140
               <th>{"Contraseña: "}</th>
150
               <th>{"Contraseña: "}</th>
141
-              <th>{ key.pwd } - {btoa(key.pwd)}</th>
151
+              <th>{key.pwd} - {btoa(key.pwd)}</th>
142
             </tr>
152
             </tr>
143
           </thead>
153
           </thead>
144
           <tbody>
154
           <tbody>
145
             <tr>
155
             <tr>
146
               <td className="title_td">{"Candidatos:"}</td>
156
               <td className="title_td">{"Candidatos:"}</td>
147
               <td colSpan={2}>
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
                 </ul>
160
                 </ul>
151
-                </td>
161
+              </td>
152
             </tr>
162
             </tr>
153
             <tr>
163
             <tr>
154
               <td className="title_td">{"Puesto:"}</td>
164
               <td className="title_td">{"Puesto:"}</td>

+ 0 - 7
src/Pages/ContrasV2.jsx

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