Explorar o código

update pwd with encode functionality

amenpunk %!s(int64=3) %!d(string=hai) anos
pai
achega
4d0949517a

+ 58 - 45
src/Components/Password/Operation.jsx

@@ -5,13 +5,10 @@ import {
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
     FormControlLabel, Checkbox,
     TextField, Stack,
-    //Autocomplete
+    // Autocomplete
 } from '@mui/material'
 
 import toast, { Toaster } from 'react-hot-toast';
-
-
-
 import * as Yup from 'yup';
 
 import { useQuery } from 'react-query'
@@ -23,17 +20,6 @@ import { useFormik, Form, FormikProvider } from 'formik';
 import DateFnsUtils from '@date-io/date-fns';
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
 
-// function getNombrePuesto(id_plaz, puestos){
-//     let nombre = "";
-//     puestos.forEach(( p) => {
-//         if(p.id === id_plaz){
-//             nombre = p.nombrepuesto;
-//         }
-//     })
-//     return nombre;
-// }
-//
-
 export function Operation(props) {
 
     let [open, setOpen] = React.useState(false);
@@ -71,24 +57,24 @@ function ModalEdit(props) {
     }
 
     let { data: result } = useQuery('contra', getPassword);
-
+    console.log('PWD INFO ',result)
+    //
     // const getPuestos = async () => {
     //     let rest = new Service('/plaza/getall')
-    //     return rest.getQuery(token);
+    //     return rest.getQuery(token.current);
     // }
     //
     // let { data } = useQuery('puestos', getPuestos)
     // let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
 
-
     let initialValues = {
         id: result?.data?.id,
         pwd: result?.data?.pwd,
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
         state: result?.data?.state,
-        dateToActived:
-            result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
-        // plaza_id: [{ id:result?.data?.plaza_id, }]
+        dateToActived: result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
+        plaza_id: result?.data?.plaza_id,
+        candidato_id : result?.data?.candidato_id
     }
 
     return (
@@ -98,13 +84,12 @@ function ModalEdit(props) {
             aria-labelledby="alert-dialog-title"
             aria-describedby="alert-dialog-description"
         >
-            <DialogTitle id="alert-dialog-title">
-                {pwd}
-            </DialogTitle>
             <DialogContent>
                 <ModalForm
+                    //puestos={puestos}
                     initialValues={initialValues}
                     handleOpen={handleOpen}
+                    token={token.current}
                 />
             </DialogContent>
         </Dialog>
@@ -113,31 +98,47 @@ function ModalEdit(props) {
 
 function ModalForm(props) {
 
-
     const pwdSchema = Yup.object().shape({
         id: Yup.number(),
         pwd: Yup.string().required("Escoge un nombre valido"),
         deadpwd: Yup.date().required("Escoge una fecha valida"),
         state: Yup.number(),
         dateToActived: Yup.date('Escoge una fecha valida').required("Escoge una fecha valida"),
-        // plaza_id: Yup.array().required("Escoge una plaza valida")
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
     })
 
-
     const formik = useFormik({
         initialValues: {
             state: 1,
             pwd:"",
             deadpwd:"",
             dateToActived:"",
-            // plaza_id:[]
+            // plaza_id:[],
         },
         onSubmit: (fields) => {
-            console.log('campos> ', fields)
-            toast.success("Contraseña Actualizada")
-            setTimeout(()=>{
-                props.handleOpen(false)
-            },1000)
+
+            let rest = new Service('/contrasenia/create');
+            let { deadpwd,dateToActived,pwd } = fields
+            
+            fields['pwd'] = btoa(pwd);
+            fields['deadpwd'] = new Date(deadpwd).toISOString();
+            fields['dateToActived'] = new Date(dateToActived).toISOString();
+            fields['candidato_id'] = props.initialValues.candidato_id
+            fields['plaza_id'] = props.initialValues.plaza_id
+
+            rest.put(fields, props.token)
+                .then(result => {
+                    console.log(result)
+                    setTimeout(()=>{
+                        props.handleOpen(false)
+                    },700)
+                    toast.success("Contraseña Actualizada")
+                })
+                .catch(bad => {
+                    console.log('ERROR',bad)
+                    toast.error("Ocurrio un error")
+                })
         },
         validationSchema: pwdSchema,
     })
@@ -145,18 +146,28 @@ function ModalForm(props) {
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
 
     React.useEffect(() => {
-        setValues({ ...props.initialValues })
+        setValues({ 
+            ...props.initialValues,
+            pwd : props.initialValues.pwd ? atob( props.initialValues.pwd ) : 'loading'
+        })
     }, [props, setValues])
 
     return (
         <FormikProvider value={formik}>
-            <Form style={{ padding: 20, maxWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
+            <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
                 <Stack spacing={4}>
+                    <TextField
+                        value={btoa( values.pwd )}
+                        variant="filled"
+                        disabled
+                        fullWidth
+                        type="text"
+                        label="Contraseña Cifrada"
+                        />
 
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
 
                         <TextField
-                            fullWidth
                             type="text"
                             label="Contraseña"
                             {...getFieldProps('pwd')}
@@ -181,7 +192,7 @@ function ModalForm(props) {
                         />
 
                     </Stack>
-
+                        
 
                     <LocalizationProvider
                         dateAdapter={DateFnsUtils}>
@@ -227,8 +238,17 @@ function ModalForm(props) {
                     </LocalizationProvider>
 
 
-                        {/*
+                    {/*
                     <Autocomplete
+                        {...getFieldProps('plaza_id')}
+                        onChange={(_a,current_list,_c,_individual,_f) => {
+                            console.log("CURRENT LIST : ",current_list)
+                            setValues({
+                                ...values,
+                                plaza_id:current_list
+                            })
+                        }}
+                        value={props.puestos.filter(p=> p.id=== values.plaza_id ).shift()}
                         id="combo-box-demo"
                         options={props.puestos}
                         isOptionEqualToValue={
@@ -237,13 +257,6 @@ function ModalForm(props) {
                         getOptionLabel={(option) => {
                             return option.nombrepuesto
                         }}
-                        onChange={(_e, newValue) => {
-                            console.log('CHANGE',newValue);
-                            setValues({
-                                ...values,
-                                plaza_id:newValue
-                            })
-                        }}
                         renderInput={(params) =>
                             <TextField
                                 {...params}

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

@@ -31,7 +31,7 @@ export const Encabezados = [
         disablePadding: true,
         label: 'Operación',
         options: {
-            filter: true,
+            filter: false,
             sort: false,
         }
     },
@@ -54,7 +54,7 @@ export function Build(pwds) {
     return pwds.map(password => {
         let { candidato: user, plaza_id, pwd } = password
         return {
-            pass: atob( pwd ),
+            pass: pwd ? atob(pwd): '',
             name: user.nombre,
             apell: user.apellidos,
             mail: user.mail,

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

@@ -76,6 +76,7 @@ export function Password(props) {
                         fullWidth
                         type="text"
                         label="Identificador Codificado"
+                        variant="filled"
                         />
 
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>

+ 1 - 1
src/Components/User.jsx

@@ -87,7 +87,7 @@ export function User(props) {
                         <MenuIcon />
                     </IconButton>
                     <Typography variant="h6" noWrap component="div">
-                        Responsive drawer
+                        Pruebas Psicometricas
                     </Typography>
                 </Toolbar>
             </AppBar>

+ 2 - 2
src/Pages/ContrasV2.jsx

@@ -20,7 +20,7 @@ export function Contrasv2() {
         return await rest.getQuery(token.current)
     }
 
-    const { data  } = useQuery('passwords', getAllPwd );
+    const { data, status  } = useQuery('passwords', getAllPwd );
 
     const options = {
         filterType: 'checkbox',
@@ -42,7 +42,7 @@ export function Contrasv2() {
                             <MUIDataTable
                                 sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
                                 title={"Contraseñas"}
-                                data={Build(data ? data.data : [])}
+                                data={Build( status ==='success' ? data.data : [])}
                                 columns={Encabezados}
                                 options={options}
                             />