Преглед изворни кода

multiple users in password creation

amenpunk пре 3 година
родитељ
комит
d588be422b

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

@@ -27,11 +27,12 @@ export function HelpModal(props) {
     sendmail: true,
     nombrepuesto: null,
     nombreEmpresa: null,
-    candidatos : [{
+    candidatos : [
+      {
       'nombres': 'ming',
       'apellidos': 'mecca',
-      'mail': 'ming@gmail.com',
-    }]
+      'mail': 'ming@gmail.com', }
+    ]
   });
 
   const isStepSkipped = (step) => {
@@ -62,6 +63,7 @@ export function HelpModal(props) {
       sendmail: true,
       nombrepuesto: null,
       nombreEmpresa: null,
+      candidatos : []
     })
     setActiveStep(0);
   };
@@ -71,41 +73,41 @@ export function HelpModal(props) {
     {
       label: 'Puesto',
       operation:
-        <Puesto
-          handleNext={handleNext}
-          handleBack={handleBack}
-          password={password}
-          setPassword={setPassword}
+      <Puesto
+        handleNext={handleNext}
+        handleBack={handleBack}
+        password={password}
+        setPassword={setPassword}
         />
     },
     {
       label: 'Contraseña',
       operation:
-        <Password
-          handleNext={handleNext}
-          handleBack={handleBack}
-          password={password}
-          setPassword={setPassword}
+      <Password
+        handleNext={handleNext}
+        handleBack={handleBack}
+        password={password}
+        setPassword={setPassword}
         />
     },
     {
       label: 'Candidatos',
       operation:
-        <Candidato
-          handleNext={handleNext}
-          handleBack={handleBack}
-          password={password}
-          setPassword={setPassword}
+      <Candidato
+        handleNext={handleNext}
+        handleBack={handleBack}
+        password={password}
+        setPassword={setPassword}
         />
     },
     {
       label: 'Confirmar',
       operation:
-        <Resume
-          handleBack={handleBack}
-          password={password}
-          handleClose={handleClose}
-          handleReset={handleReset}
+      <Resume
+        handleBack={handleBack}
+        password={password}
+        handleClose={handleClose}
+        handleReset={handleReset}
         />
     },
   ];
@@ -155,14 +157,14 @@ export function HelpModal(props) {
               </Box>
             </React.Fragment>
           ) : (
-            <React.Fragment>
+              <React.Fragment>
 
-              <Box style={{ padding: 18, marginTop: 2 }}>
-                {steps[activeStep].operation}
-              </Box>
+                <Box style={{ padding: 18, marginTop: 2 }}>
+                  {steps[activeStep].operation}
+                </Box>
 
-            </React.Fragment>
-          )}
+              </React.Fragment>
+            )}
         </Box>
 
       </Modal.Body>

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

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

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

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

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

@@ -8,11 +8,10 @@ import {
 
 import { AddCircle } from '@mui/icons-material/';
 import { MailTable } from './MailTable';
-
+import toast, { Toaster } from 'react-hot-toast';
 
 export function Candidato(props) {
 
-
   const CandidatoSchema = Yup.object().shape({
     nombres:
       Yup.string()
@@ -32,13 +31,19 @@ export function Candidato(props) {
     initialValues: {
       nombres: "",
       apellidos: "",
-      sendmail: "",
+      sendmail: true,
       mail: "",
-      nombrepuesto: password.nombrepuesto ? password.nombrepuesto : password.puesto[0].nombrepuesto,
+      nombrepuesto: '',// password.nombrepuesto ? password.nombrepuesto : password.puesto[0].nombrepuesto,
       nombreEmpresa: 'test'//password.nombreEmpresa ? password.nombreEmpresa : auth.getProfile().nombre,
       // nombreEmpresa: password.nombreEmpresa ? password.nombreEmpresa : auth.getProfile().nombre,
     },
     onSubmit: () => {
+      console.log(password.candidatos)
+      if(password.candidatos.length <= 0){
+        toast.error("Seleciona almenos un destino")
+        // alert("seleciona almenos un destino")
+        return;
+      }
       //setPassword({ ...password, ...fields })
       handleNext()
     },
@@ -134,6 +139,7 @@ export function Candidato(props) {
           </Box>
 
         </Stack>
+        <Toaster position="top-right" />
       </Form>
     </FormikProvider>
   );

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

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

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

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

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

@@ -2,8 +2,8 @@ import * as React from 'react';
 
 import { Table } from 'react-bootstrap';
 import {
-    Box, Button, LinearProgress,
-    Backdrop, CircularProgress
+  Box, Button, LinearProgress,
+  Backdrop, CircularProgress
 } from '@mui/material';
 
 import toast, { Toaster } from 'react-hot-toast';
@@ -15,25 +15,26 @@ import { useSelector } from 'react-redux';
 import { createTheme, ThemeProvider } from '@mui/material/styles';
 
 let theme = createTheme({
-    status: {
-        success: '#fd4b4b'
+  status: {
+    success: '#fd4b4b'
+  },
+  palette: {
+    primary: {
+      main: '#fd4b4b',
     },
-    palette: {
-        primary: {
-            main: '#fd4b4b',
-        },
-        secondary: {
-            main: '#fd4b4b',
-        },
+    secondary: {
+      main: '#fd4b4b',
     },
+  },
 });
 
 export function Resume(props) {
 
-  let { handleBack, password: key, handleClose,handleReset } = props
+  let { handleBack, password: key, handleClose, handleReset } = props
+
+  console.log(key)
 
   const fmt = React.useRef({ weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' })
-  const [pwdID, setPwdID] = React.useState(null);
   const [loading, setLoading] = React.useState(false);
 
   const auth = useSelector((state) => state.token)
@@ -52,62 +53,71 @@ export function Resume(props) {
 
   const pwdMutation = useMutation('password', savePassword);
   const candiMutation = useMutation('candidato', saveCandidato);
+  console.log(candiMutation)
 
   const saveStepper = () => {
 
     setLoading(true);
 
-    let {
-      deadpwd, dateToActived, puesto, 
-      pwd,nombreEmpresa,nombrepuesto, candidatos
-    } = key;
+    let { deadpwd, dateToActived } = key;
 
     let pwdBody = {
       id: -1,
-      pwd: btoa(pwd),
+      pwd: btoa(key.pwd),
       link: "www.psicoadmin.com",
       deadpwd: new Date(deadpwd).toISOString(),
       state: 1,
       dateToActived: new Date(dateToActived).toISOString(),
-      plaza_id: puesto[0].id
+      plaza_id: key.puesto[0].id
     }
 
+    console.log("PWD BODY: ", pwdBody)
+
     pwdMutation.mutate(pwdBody, {
-      onSuccess: (data) => {
-
-        let { id: password_id } = data.data;
-        setPwdID(password_id);
-
-        let candidatoBody = {
-          id: -1,
-          //nombres,
-          //apellidos,
-          //sendmail: sendmail ? 1 : 0,
-          //mail,
-          idContrasenia: password_id,
-          nombrepuesto,
-          nombreEmpresa
-        }
-
-        candiMutation.mutate(candidatoBody, {
-          onSuccess: (data) => {
+      onSuccess: (result) => {
+
+        let { id: idContrasenia } = result.data;
+
+
+        let candidatos_body = key.candidatos.map((candi) => ({
+          "id": -1,
+          "nombres": candi.nombres,
+          "apellidos": candi.apellidos,
+          "mail": candi.mail,
+          "sendmail": 0,
+          "idContrasenia": idContrasenia,
+          "nombrepuesto": 'Senior Software',
+          "nombreEmpresa": 'Google'
+        }))
+
+        console.log(candidatos_body)
+
+        // setLoading(false);
+        // return;
 
+        queryClient.invalidateQueries('passwords')
+              setLoading(false);
+              handleClose();
+              handleReset();
+        /*
+
+        candiMutation.mutate(candidatos_body, {
+          onSuccess: (data) => {
             queryClient.invalidateQueries('passwords')
             toast.success("Contraseña agregada exitosamente!!")
             setTimeout(() => {
-              console.log("OK LETS GO >> ", data,pwdID)
+              console.log("OK LETS GO >> ", data)
               setLoading(false);
               handleClose();
               handleReset();
             }, 1000)
-
           },
           onError: () => {
             toast.error("Ups!! error al crear el candidato")
             setLoading(false);
           }
         })
-
+*/
 
       },
       onError: () => {
@@ -118,13 +128,13 @@ export function Resume(props) {
     })
   }
 
-  const getLi = (user) => {
-    return ( 
-      <li style={{ listStyleType: 'none'}}>
+  const getLi = (user, i) => {
+    return (
+      <li key={i} style={{ listStyleType: 'none' }}>
         {user.nombres + " " + user.apellidos} - {user.mail}
-      </li> 
+      </li>
     )
-   }
+  }
 
   return (
     <React.Fragment>
@@ -138,17 +148,17 @@ export function Resume(props) {
           <thead>
             <tr className="table_password">
               <th>{"Contraseña: "}</th>
-              <th>{ key.pwd } - {btoa(key.pwd)}</th>
+              <th>{key.pwd} - {btoa(key.pwd)}</th>
             </tr>
           </thead>
           <tbody>
             <tr>
               <td className="title_td">{"Candidatos:"}</td>
               <td colSpan={2}>
-                <ul style={{ margin:0, padding:0}}>
-                  {key.candidatos.map(u => getLi(u))}
+                <ul style={{ margin: 0, padding: 0 }}>
+                  {key.candidatos ? key.candidatos.map((u, i) => getLi(u, i)) : null}
                 </ul>
-                </td>
+              </td>
             </tr>
             <tr>
               <td className="title_td">{"Puesto:"}</td>

+ 0 - 7
src/Pages/ContrasV2.jsx

@@ -9,7 +9,6 @@ import { TableStyle, TextLabels } from '../Components/Password/TableStyle'
 import { useQuery } from 'react-query';
 import { Service } from '../Utils/HTTP.js'
 import { useSelector } from 'react-redux';
-import  { Loading } from '../Components/Generics/loading'
 
 export function Contrasv2() {
 
@@ -21,12 +20,6 @@ export function Contrasv2() {
   }
 
   const { data, status  } = useQuery('passwords', getAllPwd );
-  console.log(data,status)
-
-  if(status === 'loading'){
-    return <Loading/>
-  }
-
   const options = {
     filterType: 'checkbox',
     customToolbar: () => {