Browse Source

update pwd with encode functionality

amenpunk 2 years ago
parent
commit
4d0949517a

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

@@ -5,13 +5,10 @@ import {
5 5
     Button, Dialog, DialogActions, DialogContent, DialogTitle,
6 6
     FormControlLabel, Checkbox,
7 7
     TextField, Stack,
8
-    //Autocomplete
8
+    // Autocomplete
9 9
 } from '@mui/material'
10 10
 
11 11
 import toast, { Toaster } from 'react-hot-toast';
12
-
13
-
14
-
15 12
 import * as Yup from 'yup';
16 13
 
17 14
 import { useQuery } from 'react-query'
@@ -23,17 +20,6 @@ import { useFormik, Form, FormikProvider } from 'formik';
23 20
 import DateFnsUtils from '@date-io/date-fns';
24 21
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
25 22
 
26
-// function getNombrePuesto(id_plaz, puestos){
27
-//     let nombre = "";
28
-//     puestos.forEach(( p) => {
29
-//         if(p.id === id_plaz){
30
-//             nombre = p.nombrepuesto;
31
-//         }
32
-//     })
33
-//     return nombre;
34
-// }
35
-//
36
-
37 23
 export function Operation(props) {
38 24
 
39 25
     let [open, setOpen] = React.useState(false);
@@ -71,24 +57,24 @@ function ModalEdit(props) {
71 57
     }
72 58
 
73 59
     let { data: result } = useQuery('contra', getPassword);
74
-
60
+    console.log('PWD INFO ',result)
61
+    //
75 62
     // const getPuestos = async () => {
76 63
     //     let rest = new Service('/plaza/getall')
77
-    //     return rest.getQuery(token);
64
+    //     return rest.getQuery(token.current);
78 65
     // }
79 66
     //
80 67
     // let { data } = useQuery('puestos', getPuestos)
81 68
     // let puestos = data ? data.data.map(({ nombrepuesto, id }) => ({ nombrepuesto, id })) : []
82 69
 
83
-
84 70
     let initialValues = {
85 71
         id: result?.data?.id,
86 72
         pwd: result?.data?.pwd,
87 73
         deadpwd: result?.data?.deadpwd ? new Date(result?.data?.deadpwd) : now.current,
88 74
         state: result?.data?.state,
89
-        dateToActived:
90
-            result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
91
-        // plaza_id: [{ id:result?.data?.plaza_id, }]
75
+        dateToActived: result?.data.dateToActived ? new Date(result?.data?.dateToActived) : now.current,
76
+        plaza_id: result?.data?.plaza_id,
77
+        candidato_id : result?.data?.candidato_id
92 78
     }
93 79
 
94 80
     return (
@@ -98,13 +84,12 @@ function ModalEdit(props) {
98 84
             aria-labelledby="alert-dialog-title"
99 85
             aria-describedby="alert-dialog-description"
100 86
         >
101
-            <DialogTitle id="alert-dialog-title">
102
-                {pwd}
103
-            </DialogTitle>
104 87
             <DialogContent>
105 88
                 <ModalForm
89
+                    //puestos={puestos}
106 90
                     initialValues={initialValues}
107 91
                     handleOpen={handleOpen}
92
+                    token={token.current}
108 93
                 />
109 94
             </DialogContent>
110 95
         </Dialog>
@@ -113,31 +98,47 @@ function ModalEdit(props) {
113 98
 
114 99
 function ModalForm(props) {
115 100
 
116
-
117 101
     const pwdSchema = Yup.object().shape({
118 102
         id: Yup.number(),
119 103
         pwd: Yup.string().required("Escoge un nombre valido"),
120 104
         deadpwd: Yup.date().required("Escoge una fecha valida"),
121 105
         state: Yup.number(),
122 106
         dateToActived: Yup.date('Escoge una fecha valida').required("Escoge una fecha valida"),
123
-        // plaza_id: Yup.array().required("Escoge una plaza valida")
107
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
108
+        //plaza_id: Yup.array().required("Escoge una plaza valida")
124 109
     })
125 110
 
126
-
127 111
     const formik = useFormik({
128 112
         initialValues: {
129 113
             state: 1,
130 114
             pwd:"",
131 115
             deadpwd:"",
132 116
             dateToActived:"",
133
-            // plaza_id:[]
117
+            // plaza_id:[],
134 118
         },
135 119
         onSubmit: (fields) => {
136
-            console.log('campos> ', fields)
137
-            toast.success("Contraseña Actualizada")
138
-            setTimeout(()=>{
139
-                props.handleOpen(false)
140
-            },1000)
120
+
121
+            let rest = new Service('/contrasenia/create');
122
+            let { deadpwd,dateToActived,pwd } = fields
123
+            
124
+            fields['pwd'] = btoa(pwd);
125
+            fields['deadpwd'] = new Date(deadpwd).toISOString();
126
+            fields['dateToActived'] = new Date(dateToActived).toISOString();
127
+            fields['candidato_id'] = props.initialValues.candidato_id
128
+            fields['plaza_id'] = props.initialValues.plaza_id
129
+
130
+            rest.put(fields, props.token)
131
+                .then(result => {
132
+                    console.log(result)
133
+                    setTimeout(()=>{
134
+                        props.handleOpen(false)
135
+                    },700)
136
+                    toast.success("Contraseña Actualizada")
137
+                })
138
+                .catch(bad => {
139
+                    console.log('ERROR',bad)
140
+                    toast.error("Ocurrio un error")
141
+                })
141 142
         },
142 143
         validationSchema: pwdSchema,
143 144
     })
@@ -145,18 +146,28 @@ function ModalForm(props) {
145 146
     const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
146 147
 
147 148
     React.useEffect(() => {
148
-        setValues({ ...props.initialValues })
149
+        setValues({ 
150
+            ...props.initialValues,
151
+            pwd : props.initialValues.pwd ? atob( props.initialValues.pwd ) : 'loading'
152
+        })
149 153
     }, [props, setValues])
150 154
 
151 155
     return (
152 156
         <FormikProvider value={formik}>
153
-            <Form style={{ padding: 20, maxWidth: 450 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
157
+            <Form style={{ padding: 20, maxWidth: 950 }} autoComplete="off" noValidate onSubmit={handleSubmit}>
154 158
                 <Stack spacing={4}>
159
+                    <TextField
160
+                        value={btoa( values.pwd )}
161
+                        variant="filled"
162
+                        disabled
163
+                        fullWidth
164
+                        type="text"
165
+                        label="Contraseña Cifrada"
166
+                        />
155 167
 
156 168
                     <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
157 169
 
158 170
                         <TextField
159
-                            fullWidth
160 171
                             type="text"
161 172
                             label="Contraseña"
162 173
                             {...getFieldProps('pwd')}
@@ -181,7 +192,7 @@ function ModalForm(props) {
181 192
                         />
182 193
 
183 194
                     </Stack>
184
-
195
+                        
185 196
 
186 197
                     <LocalizationProvider
187 198
                         dateAdapter={DateFnsUtils}>
@@ -227,8 +238,17 @@ function ModalForm(props) {
227 238
                     </LocalizationProvider>
228 239
 
229 240
 
230
-                        {/*
241
+                    {/*
231 242
                     <Autocomplete
243
+                        {...getFieldProps('plaza_id')}
244
+                        onChange={(_a,current_list,_c,_individual,_f) => {
245
+                            console.log("CURRENT LIST : ",current_list)
246
+                            setValues({
247
+                                ...values,
248
+                                plaza_id:current_list
249
+                            })
250
+                        }}
251
+                        value={props.puestos.filter(p=> p.id=== values.plaza_id ).shift()}
232 252
                         id="combo-box-demo"
233 253
                         options={props.puestos}
234 254
                         isOptionEqualToValue={
@@ -237,13 +257,6 @@ function ModalForm(props) {
237 257
                         getOptionLabel={(option) => {
238 258
                             return option.nombrepuesto
239 259
                         }}
240
-                        onChange={(_e, newValue) => {
241
-                            console.log('CHANGE',newValue);
242
-                            setValues({
243
-                                ...values,
244
-                                plaza_id:newValue
245
-                            })
246
-                        }}
247 260
                         renderInput={(params) =>
248 261
                             <TextField
249 262
                                 {...params}

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

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

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

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

+ 1 - 1
src/Components/User.jsx

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

+ 2 - 2
src/Pages/ContrasV2.jsx

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