Browse Source

password api migration

amenpunk 2 years ago
parent
commit
62e3e202ac

+ 269 - 270
src/Components/Modal/AgregarManual.js

@@ -15,283 +15,282 @@ import {
15 15
 
16 16
 import { Service } from '../../Utils/HTTP';
17 17
 import { useQuery, useMutation, useQueryClient } from 'react-query';
18
-import useAuth from '../../Auth/useAuth';
19 18
 import { TabPanel } from './TabPanel'
19
+import { useSelector } from 'react-redux';
20 20
 
21 21
 function Manual(props) {
22 22
 
23
-    const auth = useAuth();
24
-    const token = auth.getToken();
25
-
26
-    const getCategories = async () => {
27
-        let rest = new Service("/categoria/getAll")
28
-        return await rest.getQuery(token)
29
-    }
23
+  const auth = useSelector((state) => state.token)
24
+
25
+  const getCategories = async () => {
26
+    let rest = new Service("/categoria/getAll")
27
+    return await rest.getQuery(auth.token)
28
+  }
29
+
30
+  const getTest = async () => {
31
+    let rest = new Service("/tests/getAll")
32
+    return await rest.getQuery(auth.token)
33
+  }
34
+
35
+  const { data } = useQuery('categories', getCategories);
36
+  const { data: testsCatalog } = useQuery('tests', getTest);
37
+  const queryClient = useQueryClient();
38
+
39
+  const NewPlazaSchema = Yup.object().shape({
40
+    nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
41
+    puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
42
+    aredepto: Yup.number().required('Escoge alguna área'),
43
+    fecha: Yup.date("Ingresa una fecha válida"),
44
+    notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
45
+    tests: Yup.array()
46
+  })
47
+
48
+  const [departamento, setDepartamento] = React.useState('');
49
+  const [puestoSup, setPuestoSup] = React.useState('');
50
+  const [open, setOpen] = React.useState(false);
51
+  const [date, setDate] = React.useState(new Date());
52
+  const [tab, setTab] = React.useState(0);
53
+  const [checklist, setChecklist] = React.useState([]);
54
+
55
+  const handleClose = () => false
56
+
57
+  const changeDepartamento = (event) => {
58
+    setDepartamento(event.target.value);
59
+  };
60
+
61
+  const changePuestoSup = (event) => {
62
+    setPuestoSup(event.target.value);
63
+  };
64
+
65
+  const agregarPuesto = async (puesto) => {
66
+    let rest = new Service('/plaza/save');
67
+    return await rest.postQuery(puesto, auth.token);
68
+  }
69
+
70
+  const puestoMutation = useMutation(agregarPuesto)
71
+
72
+  let { visible, onClose } = props
73
+
74
+  const formik = useFormik({
75
+    initialValues: {
76
+      nombrepuesto: "",
77
+      puestosuperior: "",
78
+      aredepto: 1,
79
+      fecha: date,
80
+      notas: "",
81
+      tests:[]
82
+    },
83
+    onSubmit: (fields, { resetForm }) => {
84
+
85
+      setOpen(true)
86
+      fields['fecha'] = new Date(fields.fecha).toISOString();
87
+      fields['areadeptoplz_id'] = 1;
88
+      fields['id'] = -1;
89
+
90
+      puestoMutation.mutate(fields, {
91
+        onSuccess: () => {
92
+          setOpen(false)
93
+          resetForm();
94
+          onClose();
95
+          queryClient.invalidateQueries('puestos')
96
+          toast.success("Puesto Agregado")
97
+        },
98
+        onError: () => {
99
+          setOpen(false)
100
+          toast.error("Ups!! Ocurrio un error, inténtalo más tarde")
101
+        }
102
+      })
103
+    },
104
+    validationSchema: NewPlazaSchema,
105
+  });
30 106
 
31
-    const getTest = async () => {
32
-        let rest = new Service("/tests/getAll")
33
-        return await rest.getQuery(token)
34
-    }
107
+  const changeTab = (_event, newValue) => {
108
+    setTab(newValue);
109
+  };
35 110
 
36
-    const { data } = useQuery('categories', getCategories);
37
-    const { data: testsCatalog } = useQuery('tests', getTest);
38
-    const queryClient = useQueryClient();
39
-
40
-    const NewPlazaSchema = Yup.object().shape({
41
-        nombrepuesto: Yup.string().required('El nombre es requerido').min(5, "El nombre del  puesto debe ser mayor a 5 caracteres").max(100),
42
-        puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
43
-        aredepto: Yup.number().required('Escoge alguna área'),
44
-        fecha: Yup.date("Ingresa una fecha válida"),
45
-        notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
46
-        tests: Yup.array()
47
-    })
48
-
49
-    const [departamento, setDepartamento] = React.useState('');
50
-    const [puestoSup, setPuestoSup] = React.useState('');
51
-    const [open, setOpen] = React.useState(false);
52
-    const [date, setDate] = React.useState(new Date());
53
-    const [tab, setTab] = React.useState(0);
54
-    const [checklist, setChecklist] = React.useState([]);
55
-
56
-    const handleClose = () => false
57
-
58
-    const changeDepartamento = (event) => {
59
-        setDepartamento(event.target.value);
60
-    };
61
-    
62
-    const changePuestoSup = (event) => {
63
-        setPuestoSup(event.target.value);
64
-    };
65
-
66
-    const agregarPuesto = async (puesto) => {
67
-        let rest = new Service('/plaza/save');
68
-        return await rest.postQuery(puesto, token);
69
-    }
70 111
 
71
-    const puestoMutation = useMutation(agregarPuesto)
112
+  const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
72 113
 
73
-    let { visible, onClose } = props
74
-
75
-    const formik = useFormik({
76
-        initialValues: {
77
-            nombrepuesto: "",
78
-            puestosuperior: "",
79
-            aredepto: 1,
80
-            fecha: date,
81
-            notas: "",
82
-            tests:[]
83
-        },
84
-        onSubmit: (fields, { resetForm }) => {
85
-
86
-            setOpen(true)
87
-            fields['fecha'] = new Date(fields.fecha).toISOString();
88
-            fields['areadeptoplz_id'] = 1;
89
-            fields['id'] = -1;
90
-
91
-            puestoMutation.mutate(fields, {
92
-                onSuccess: () => {
93
-                    setOpen(false)
94
-                    resetForm();
95
-                    onClose();
96
-                    queryClient.invalidateQueries('puestos')
97
-                    toast.success("Puesto Agregado")
98
-                },
99
-                onError: () => {
100
-                    setOpen(false)
101
-                    toast.error("Ups!! Ocurrio un error, inténtalo más tarde")
102
-                }
103
-            })
104
-        },
105
-        validationSchema: NewPlazaSchema,
106
-    });
107
-
108
-    const changeTab = (_event, newValue) => {
109
-        setTab(newValue);
110
-    };
111
-    
112
-
113
-    const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
114
-
115
-    const addPrueba = (check,id) => {
116
-        let { tests } = values
117
-        let temp ;
118
-        if(check){
119
-            temp = [...tests, {id}]
120
-        }else{
121
-            temp = tests.filter( test => test.id !== id);
122
-        }
123
-        setChecklist(  temp.map( test => test.id) )
124
-        setValues({...values, tests: temp})
125
-    };
126
-
127
-    return (
128
-
129
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
130
-
131
-            <Modal.Header>
132
-                <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
133
-                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
134
-            </Modal.Header>
135
-            <Modal.Body className="modal-body">
136
-
137
-                <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
138
-                    <Tab label="Información" />
139
-                    <Tab label="Pruebas" />
140
-                </Tabs>
141
-
142
-                <FormikProvider style={{ paddingTop: 25 }} value={formik}>
143
-                    <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
144
-
145
-                        <TabPanel value={tab} index={1}>
146
-                            <Stack spacing={1}>
147
-                                <Box style={{ paddingTop :5, paddingLeft :15 }}>
148
-                                    <Divider/>
149
-                                        <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
150
-                                    <Divider/>
151
-                                    <FormGroup>
152
-                                        {
153
-                                            testsCatalog ?
154
-                                            testsCatalog.data.map( test => (
155
-                                                <FormControlLabel 
156
-                                                    key={test.id}
157
-                                                    control={
158
-                                                        <Checkbox 
159
-                                                            checked={checklist.includes((test.id))}
160
-                                                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
161
-                                                        />
162
-                                                    } 
163
-                                                    label={test.nombre} 
164
-                                                    />
165
-                                            )): null
166
-                                        }
167
-                                    </FormGroup>
168
-                                </Box>
169
-                            </Stack>
170
-                        </TabPanel>
171
-
172
-                        <TabPanel value={tab} index={0}>
173
-
174
-                            <Stack spacing={3}>
175
-
176
-
177
-                                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
178
-                                    <TextField
179
-                                        label="Nombre"
180
-                                        fullWidth
181
-                                        {...getFieldProps('nombrepuesto')}
182
-                                        error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
183
-                                        helperText={touched.nombrepuesto && errors.nombrepuesto}
184
-                                    />
185
-
186
-                                    <FormControl fullWidth>
187
-                                        <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
188
-                                        <Select
189
-                                            labelId="demo-simple-select-label"
190
-                                            value={puestoSup}
191
-                                            label="Puesto Superior"
192
-                                            onChange={changePuestoSup}
193
-                                            {...getFieldProps('puestosuperior')}
194
-                                            helperText={touched.puestosuperior && errors.puestosuperior}
195
-                                            error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
196
-                                            {
197
-                                                data ?
198
-                                                    data.data.map(cate => {
199
-                                                        return (
200
-                                                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
201
-                                                        )
202
-                                                    })
203
-                                                    : <MenuItem>Null</MenuItem>
204
-                                            }
205
-                                        </Select>
206
-                                    </FormControl>
207
-
208
-                                </Stack>
209
-
210
-                                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
211
-
212
-                                    <FormControl fullWidth>
213
-                                        <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
214
-                                        <Select
215
-                                            labelId="demo-simple-select-label"
216
-                                            value={departamento}
217
-                                            label="Departamento"
218
-                                            onChange={changeDepartamento}
219
-                                            {...getFieldProps('aredepto')}
220
-                                            error={Boolean(touched.aredepto && errors.aredepto)} >
221
-                                            {
222
-                                                data ?
223
-                                                    data.data.map(cate => {
224
-                                                        return (
225
-                                                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
226
-                                                        )
227
-                                                    })
228
-                                                    : <MenuItem>Null</MenuItem>
229
-                                            }
230
-                                        </Select>
231
-                                    </FormControl>
232
-
233
-
234
-                                    <LocalizationProvider
235
-                                        dateAdapter={DateFnsUtils}>
236
-                                        <DesktopDatePicker
237
-                                            label="Fecha Creación"
238
-                                            fullWidth
239
-                                            inputFormat="dd/MM/yyyy"
240
-                                            {...getFieldProps('fecha')}
241
-                                            value={date}
242
-                                            onChange={setDate}
243
-                                            renderInput={(params) =>
244
-                                                <TextField
245
-                                                    disabled={true}
246
-                                                    label="Fecha Creación"
247
-                                                    fullWidth
248
-                                                    {...params}
249
-                                                />}
250
-                                        />
251
-                                    </LocalizationProvider>
252
-
253
-                                </Stack>
254
-
255
-                                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
256
-                                    <TextField
257
-                                        id="filled-multiline-static"
258
-                                        multiline
259
-                                        rows={4}
260
-                                        variant="filled"
261
-                                        label="Notas"
262
-                                        fullWidth
263
-                                        type="text"
264
-                                        {...getFieldProps('notas')}
265
-                                        error={Boolean(touched.notas && errors.notas)}
266
-                                        helperText={touched.notas && errors.notas}
267
-                                    />
268
-                                </Stack>
269
-                            </Stack>
270
-
271
-                        </TabPanel>
272
-
273
-
274
-                        <Modal.Footer>
275
-                            <Button
276
-                                type="submit"
277
-                                className="registerBtn"
278
-                                variant="contained"
279
-                                sx={{ mt: 1, mr: 1 }} >
280
-                                {'Guardar'}
281
-                            </Button>
282
-                        </Modal.Footer>
283
-
284
-                    </Form>
285
-                </FormikProvider>
286
-            </Modal.Body>
287
-            <Backdrop
288
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
289
-                open={open}
290
-                onClick={handleClose} >
291
-                <CircularProgress color="inherit" />
292
-            </Backdrop>
293
-            <Toaster position="top-right" />
294
-        </Modal>
295
-    )
114
+  const addPrueba = (check,id) => {
115
+    let { tests } = values
116
+    let temp ;
117
+    if(check){
118
+      temp = [...tests, {id}]
119
+    }else{
120
+      temp = tests.filter( test => test.id !== id);
121
+    }
122
+    setChecklist(  temp.map( test => test.id) )
123
+    setValues({...values, tests: temp})
124
+  };
125
+
126
+  return (
127
+
128
+    <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
129
+
130
+      <Modal.Header>
131
+        <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
132
+        <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
133
+      </Modal.Header>
134
+      <Modal.Body className="modal-body">
135
+
136
+        <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
137
+          <Tab label="Información" />
138
+          <Tab label="Pruebas" />
139
+        </Tabs>
140
+
141
+        <FormikProvider style={{ paddingTop: 25 }} value={formik}>
142
+          <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
143
+
144
+            <TabPanel value={tab} index={1}>
145
+              <Stack spacing={1}>
146
+                <Box style={{ paddingTop :5, paddingLeft :15 }}>
147
+                  <Divider/>
148
+                  <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
149
+                  <Divider/>
150
+                  <FormGroup>
151
+                    {
152
+                    testsCatalog ?
153
+                      testsCatalog.data.map( test => (
154
+                        <FormControlLabel 
155
+                          key={test.id}
156
+                          control={
157
+                          <Checkbox 
158
+                            checked={checklist.includes((test.id))}
159
+                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
160
+                            />
161
+                        } 
162
+                          label={test.nombre} 
163
+                          />
164
+                      )): null
165
+                  }
166
+                  </FormGroup>
167
+                </Box>
168
+              </Stack>
169
+            </TabPanel>
170
+
171
+            <TabPanel value={tab} index={0}>
172
+
173
+              <Stack spacing={3}>
174
+
175
+
176
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
177
+                  <TextField
178
+                    label="Nombre"
179
+                    fullWidth
180
+                    {...getFieldProps('nombrepuesto')}
181
+                    error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
182
+                    helperText={touched.nombrepuesto && errors.nombrepuesto}
183
+                    />
184
+
185
+                  <FormControl fullWidth>
186
+                    <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
187
+                    <Select
188
+                      labelId="demo-simple-select-label"
189
+                      value={puestoSup}
190
+                      label="Puesto Superior"
191
+                      onChange={changePuestoSup}
192
+                      {...getFieldProps('puestosuperior')}
193
+                      helperText={touched.puestosuperior && errors.puestosuperior}
194
+                      error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
195
+                      {
196
+                      data ?
197
+                        data.data.map(cate => {
198
+                          return (
199
+                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
200
+)
201
+                        })
202
+                        : <MenuItem>Null</MenuItem>
203
+                    }
204
+                    </Select>
205
+                  </FormControl>
206
+
207
+                </Stack>
208
+
209
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
210
+
211
+                  <FormControl fullWidth>
212
+                    <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
213
+                    <Select
214
+                      labelId="demo-simple-select-label"
215
+                      value={departamento}
216
+                      label="Departamento"
217
+                      onChange={changeDepartamento}
218
+                      {...getFieldProps('aredepto')}
219
+                      error={Boolean(touched.aredepto && errors.aredepto)} >
220
+                      {
221
+                      data ?
222
+                        data.data.map(cate => {
223
+                          return (
224
+                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
225
+                          )
226
+                        })
227
+                        : <MenuItem>Null</MenuItem>
228
+                    }
229
+                    </Select>
230
+                  </FormControl>
231
+
232
+
233
+                  <LocalizationProvider
234
+                    dateAdapter={DateFnsUtils}>
235
+                    <DesktopDatePicker
236
+                      label="Fecha Creación"
237
+                      fullWidth
238
+                      inputFormat="dd/MM/yyyy"
239
+                      {...getFieldProps('fecha')}
240
+                      value={date}
241
+                      onChange={setDate}
242
+                      renderInput={(params) =>
243
+                        <TextField
244
+                          disabled={true}
245
+                          label="Fecha Creación"
246
+                          fullWidth
247
+                          {...params}
248
+                          />}
249
+                      />
250
+                  </LocalizationProvider>
251
+
252
+                </Stack>
253
+
254
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={4}>
255
+                  <TextField
256
+                    id="filled-multiline-static"
257
+                    multiline
258
+                    rows={4}
259
+                    variant="filled"
260
+                    label="Notas"
261
+                    fullWidth
262
+                    type="text"
263
+                    {...getFieldProps('notas')}
264
+                    error={Boolean(touched.notas && errors.notas)}
265
+                    helperText={touched.notas && errors.notas}
266
+                    />
267
+                </Stack>
268
+              </Stack>
269
+
270
+            </TabPanel>
271
+
272
+
273
+            <Modal.Footer>
274
+              <Button
275
+                type="submit"
276
+                className="registerBtn"
277
+                variant="contained"
278
+                sx={{ mt: 1, mr: 1 }} >
279
+                {'Guardar'}
280
+              </Button>
281
+            </Modal.Footer>
282
+
283
+          </Form>
284
+        </FormikProvider>
285
+      </Modal.Body>
286
+      <Backdrop
287
+        sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
288
+        open={open}
289
+        onClick={handleClose} >
290
+        <CircularProgress color="inherit" />
291
+      </Backdrop>
292
+      <Toaster position="top-right" />
293
+    </Modal>
294
+  )
296 295
 }
297 296
 export default memo(Manual);

+ 256 - 257
src/Components/Modal/EditPlaza.js

@@ -15,7 +15,7 @@ import {
15 15
 } from '@mui/material';
16 16
 
17 17
 import { Service } from '../../Utils/HTTP';
18
-import useAuth from '../../Auth/useAuth';
18
+import { useSelector } from 'react-redux'
19 19
 import { useQuery, useMutation, useQueryClient } from 'react-query'
20 20
 
21 21
 const NewPlazaSchema = Yup.object().shape({
@@ -35,265 +35,264 @@ const NewPlazaSchema = Yup.object().shape({
35 35
 
36 36
 function Edit(props) {
37 37
 
38
-    const now = useMemo(() => new Date(), [])
39
-    const auth = useAuth();
40
-    const token = auth.getToken();
41
-    const queryClient = useQueryClient()
42
-    let { visible, toggle, puesto } = props
43
-
44
-    const [departamento, setDepartamento] = React.useState('');
45
-    const [open, setOpen] = React.useState(false);
46
-
47
-    const changeDepartamento = useCallback((event) => {
48
-        setDepartamento(event.target.value);
49
-    }, []);
50
-
51
-    const [date, setDate] = React.useState(now);
52
-    const [tab, setTab] = React.useState(0);
53
-    const [checklist, setChecklist] = React.useState([]);
54
-
55
-    const addPrueba = (check,id) => {
56
-        let { tests } = values
57
-        let temp ;
58
-        if(check){
59
-            temp = [...tests, {id}]
60
-        }else{
61
-            temp = tests.filter( test => test.id !== id);
62
-        }
63
-        setChecklist(temp.map( test => test.id) )
64
-        setValues({...values, tests: temp})
65
-    };
66
-
67
-    const getCategories = async () => {
68
-        let rest = new Service("/categoria/getAll")
69
-        return await rest.getQuery(token)
70
-    }
71
-
72
-    const updatePuesto = async (fields) => {
73
-        let rest = new Service('/plaza/edit');
74
-        return rest.putQuery(fields, token)
75
-    }
76
-    
77
-    const getTest = async () => {
78
-        let rest = new Service("/tests/getAll")
79
-        return await rest.getQuery(token)
38
+  const now = useMemo(() => new Date(), [])
39
+  const auth = useSelector((state) => state.token)
40
+  const queryClient = useQueryClient()
41
+  let { visible, toggle, puesto } = props
42
+
43
+  const [departamento, setDepartamento] = React.useState('');
44
+  const [open, setOpen] = React.useState(false);
45
+
46
+  const changeDepartamento = useCallback((event) => {
47
+    setDepartamento(event.target.value);
48
+  }, []);
49
+
50
+  const [date, setDate] = React.useState(now);
51
+  const [tab, setTab] = React.useState(0);
52
+  const [checklist, setChecklist] = React.useState([]);
53
+
54
+  const addPrueba = (check,id) => {
55
+    let { tests } = values
56
+    let temp ;
57
+    if(check){
58
+      temp = [...tests, {id}]
59
+    }else{
60
+      temp = tests.filter( test => test.id !== id);
80 61
     }
81
-
82
-    const puestoMutation = useMutation(updatePuesto)
83
-
84
-    const close = () => toggle("EDIT");
85
-
86
-    const { data } = useQuery('categories', getCategories);
87
-    const { data: testsCatalog } = useQuery('tests', getTest);
88
-
89
-    const formik = useFormik({
90
-        initialValues: {
91
-            id: 1,
92
-            nombrepuesto: "",
93
-            puestosuperior: 1,
94
-            aredepto: 1,
95
-            fecha: now,
96
-            notas: "",
97
-            tests : []
62
+    setChecklist(temp.map( test => test.id) )
63
+    setValues({...values, tests: temp})
64
+  };
65
+
66
+  const getCategories = async () => {
67
+    let rest = new Service("/categoria/getAll")
68
+    return await rest.getQuery(auth.token)
69
+  }
70
+
71
+  const updatePuesto = async (fields) => {
72
+    let rest = new Service('/plaza/edit');
73
+    return rest.putQuery(fields, auth.token)
74
+  }
75
+
76
+  const getTest = async () => {
77
+    let rest = new Service("/tests/getAll")
78
+    return await rest.getQuery(auth.token)
79
+  }
80
+
81
+  const puestoMutation = useMutation(updatePuesto)
82
+
83
+  const close = () => toggle("EDIT");
84
+
85
+  const { data } = useQuery('categories', getCategories);
86
+  const { data: testsCatalog } = useQuery('tests', getTest);
87
+
88
+  const formik = useFormik({
89
+    initialValues: {
90
+      id: 1,
91
+      nombrepuesto: "",
92
+      puestosuperior: 1,
93
+      aredepto: 1,
94
+      fecha: now,
95
+      notas: "",
96
+      tests : []
97
+    },
98
+    onSubmit: (fields, { resetForm }) => {
99
+      setOpen(true);
100
+      fields['fecha'] = new Date(fields.fecha).toISOString();
101
+
102
+      puestoMutation.mutate(fields, {
103
+        onSuccess: () => {
104
+          close();
105
+          setOpen(false)
106
+          toast.success("Puesto Actualizado!!")
107
+          queryClient.invalidateQueries('puestos')
98 108
         },
99
-        onSubmit: (fields, { resetForm }) => {
100
-            setOpen(true);
101
-            fields['fecha'] = new Date(fields.fecha).toISOString();
102
-
103
-            puestoMutation.mutate(fields, {
104
-                onSuccess: () => {
105
-                    close();
106
-                    setOpen(false)
107
-                    toast.success("Puesto Actualizado!!")
108
-                    queryClient.invalidateQueries('puestos')
109
-                },
110
-                onError:() => {
111
-                    close();
112
-                    setOpen(false)
113
-                    toast.error("Lo sentimos ocurrió error inténtalo más tarde")
114
-                }
115
-            })
116
-
117
-            resetForm();
118
-        },
119
-        validationSchema: NewPlazaSchema,
120
-    });
121
-
122
-    const { errors, touched, handleSubmit, getFieldProps, setValues, values } = formik;
123
-
124
-    useEffect(() => {
125
-        if (puesto) {
126
-            setValues({
127
-                id: puesto.id,
128
-                nombrepuesto: puesto.nombrepuesto,
129
-                puestosuperior: puesto.puestosuperior,
130
-                aredepto: puesto.areadeptoplz_id,
131
-                fecha: new Date(puesto.create_day),
132
-                notas: puesto.notas,
133
-                tests : puesto.tests
134
-            })
135
-            setChecklist(puesto.tests.map(( {id} ) => id))
109
+        onError:() => {
110
+          close();
111
+          setOpen(false)
112
+          toast.error("Lo sentimos ocurrió error inténtalo más tarde")
136 113
         }
137
-    }, [puesto, now, setValues])
138
-
139
-    const changeTab = (_event, newValue) => {
140
-        setTab(newValue);
141
-    };
142
-
143
-    return (
144
-
145
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
146
-            <Modal.Header>
147
-                <button onClick={close} type="button" className="close" data-dismiss="modal">&times;</button>
148
-                <h4 className="modal-title" style={{ color: '#252525' }}>Editar puesto</h4>
149
-            </Modal.Header>
150
-            <Modal.Body className="modal-body">
151
-
152
-                <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
153
-                    <Tab label="Información" />
154
-                    <Tab label="Pruebas" />
155
-                </Tabs>
156
-
157
-                <FormikProvider style={{ padding: 25 }} value={formik}>
158
-                    <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
159
-
160
-
161
-                        <TabPanel value={tab} index={1}>
162
-                            <Stack spacing={1}>
163
-                                <Box style={{ paddingTop :5, paddingLeft :15 }}>
164
-                                    <Divider/>
165
-                                        <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
166
-                                    <Divider/>
167
-                                    <FormGroup>
168
-                                        {
169
-                                            testsCatalog ?
170
-                                            testsCatalog.data.map( test => (
171
-                                                <FormControlLabel 
172
-                                                    key={test.id}
173
-                                                    control={
174
-                                                        <Checkbox 
175
-                                                            checked={checklist.includes((test.id))}
176
-                                                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
177
-                                                        />
178
-                                                    } 
179
-                                                    label={test.nombre} 
180
-                                                    />
181
-                                            )): null
182
-                                        }
183
-                                    </FormGroup>
184
-                                </Box>
185
-                            </Stack>
186
-                        </TabPanel>
187
-
188
-
189
-                        <TabPanel value={tab} index={0} >
190
-                        <Stack spacing={3}>
191
-
192
-                            <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
193
-
194
-                                <TextField
195
-                                    label="Nombre"
196
-                                    fullWidth
197
-                                    {...getFieldProps('nombrepuesto')}
198
-                                    error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
199
-                                    helperText={touched.nombrepuesto && errors.nombrepuesto}
200
-                                />
201
-
202
-                                <TextField
203
-                                    label="Puesto Superior"
204
-                                    fullWidth
205
-                                    {...getFieldProps('puestosuperior')}
206
-                                    error={Boolean(touched.puestosuperior && errors.puestosuperior)}
207
-                                    helperText={touched.puestosuperior && errors.puestosuperior}
208
-                                />
209
-
210
-                            </Stack>
211
-                            <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
212
-                                <FormControl fullWidth>
213
-                                    <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
214
-                                    <Select
215
-                                        labelId="demo-simple-select-label"
216
-                                        value={departamento}
217
-                                        label="Departamento"
218
-                                        onChange={changeDepartamento}
219
-                                        {...getFieldProps('aredepto')}
220
-                                        error={Boolean(touched.aredepto && errors.aredepto)} >
221
-                                        {
222
-                                            data ?
223
-                                                data.data.map(cate => {
224
-                                                    return (
225
-                                                        <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
226
-                                                    )
227
-                                                })
228
-                                                : <MenuItem>Null</MenuItem>
229
-                                        }
230
-                                    </Select>
231
-                                </FormControl>
232
-
233
-
234
-                                <LocalizationProvider
235
-                                    dateAdapter={DateFnsUtils}>
236
-                                    <DesktopDatePicker
237
-                                        label="Fecha Creación"
238
-                                        fullWidth
239
-                                        inputFormat="dd/MM/yyyy"
240
-                                        {...getFieldProps('fecha')}
241
-                                        xd
242
-                                        value={date}
243
-                                        onChange={setDate}
244
-                                        renderInput={(params) =>
245
-                                            <TextField
246
-                                                disabled={true}
247
-                                                label="Fecha Creación"
248
-                                                fullWidth
249
-                                                {...params}
250
-                                            />}
251
-                                    />
252
-                                </LocalizationProvider>
253
-
254
-                            </Stack>
255
-
256
-                            <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
257
-                                <TextField
258
-                                    id="filled-multiline-static"
259
-                                    multiline
260
-                                    rows={4}
261
-                                    variant="filled"
262
-                                    label="Notas"
263
-                                    fullWidth
264
-                                    type="text"
265
-                                    {...getFieldProps('notas')}
266
-                                    error={Boolean(touched.notas && errors.notas)}
267
-                                    helperText={touched.notas && errors.notas}
268
-                                />
269
-                            </Stack>
270
-                        </Stack>
271
-                        </TabPanel>
272
-
273
-
274
-                        <Modal.Footer>
275
-                            <Button
276
-                                type="submit"
277
-                                className="registerBtn"
278
-                                variant="contained"
279
-                                sx={{ mt: 1, mr: 1 }} >
280
-                                {'Actualizar'}
281
-                            </Button>
282
-                        </Modal.Footer>
283
-
284
-                    </Form>
285
-                </FormikProvider>
286
-            </Modal.Body>
287
-            <Backdrop
288
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
289
-                open={open}
290
-                onClick={() => console.log('backdrop')} >
291
-                <CircularProgress color="inherit" />
292
-            </Backdrop>
293
-            <Toaster position="top-right" />
294
-
295
-        </Modal>
296
-    )
114
+      })
115
+
116
+      resetForm();
117
+    },
118
+    validationSchema: NewPlazaSchema,
119
+  });
120
+
121
+  const { errors, touched, handleSubmit, getFieldProps, setValues, values } = formik;
122
+
123
+  useEffect(() => {
124
+    if (puesto) {
125
+      setValues({
126
+        id: puesto.id,
127
+        nombrepuesto: puesto.nombrepuesto,
128
+        puestosuperior: puesto.puestosuperior,
129
+        aredepto: puesto.areadeptoplz_id,
130
+        fecha: new Date(puesto.create_day),
131
+        notas: puesto.notas,
132
+        tests : puesto.tests
133
+      })
134
+      setChecklist(puesto.tests.map(( {id} ) => id))
135
+    }
136
+  }, [puesto, now, setValues])
137
+
138
+  const changeTab = (_event, newValue) => {
139
+    setTab(newValue);
140
+  };
141
+
142
+  return (
143
+
144
+    <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
145
+      <Modal.Header>
146
+        <button onClick={close} type="button" className="close" data-dismiss="modal">&times;</button>
147
+        <h4 className="modal-title" style={{ color: '#252525' }}>Editar puesto</h4>
148
+      </Modal.Header>
149
+      <Modal.Body className="modal-body">
150
+
151
+        <Tabs value={tab} onChange={changeTab} aria-label="basic tabs example">
152
+          <Tab label="Información" />
153
+          <Tab label="Pruebas" />
154
+        </Tabs>
155
+
156
+        <FormikProvider style={{ padding: 25 }} value={formik}>
157
+          <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
158
+
159
+
160
+            <TabPanel value={tab} index={1}>
161
+              <Stack spacing={1}>
162
+<Box style={{ paddingTop :5, paddingLeft :15 }}>
163
+                  <Divider/>
164
+                  <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
165
+                  <Divider/>
166
+                  <FormGroup>
167
+                    {
168
+                    testsCatalog ?
169
+                      testsCatalog.data.map( test => (
170
+                        <FormControlLabel 
171
+                          key={test.id}
172
+                          control={
173
+                          <Checkbox 
174
+                            checked={checklist.includes((test.id))}
175
+                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
176
+                            />
177
+                        } 
178
+                          label={test.nombre} 
179
+                          />
180
+                      )): null
181
+                  }
182
+                  </FormGroup>
183
+                </Box>
184
+              </Stack>
185
+            </TabPanel>
186
+
187
+
188
+            <TabPanel value={tab} index={0} >
189
+              <Stack spacing={3}>
190
+
191
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
192
+
193
+                  <TextField
194
+                    label="Nombre"
195
+                    fullWidth
196
+                    {...getFieldProps('nombrepuesto')}
197
+                    error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
198
+                    helperText={touched.nombrepuesto && errors.nombrepuesto}
199
+                    />
200
+
201
+                  <TextField
202
+                    label="Puesto Superior"
203
+                    fullWidth
204
+                    {...getFieldProps('puestosuperior')}
205
+                    error={Boolean(touched.puestosuperior && errors.puestosuperior)}
206
+                    helperText={touched.puestosuperior && errors.puestosuperior}
207
+                    />
208
+
209
+                </Stack>
210
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
211
+                  <FormControl fullWidth>
212
+                    <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
213
+                    <Select
214
+                      labelId="demo-simple-select-label"
215
+                      value={departamento}
216
+                      label="Departamento"
217
+                      onChange={changeDepartamento}
218
+                      {...getFieldProps('aredepto')}
219
+                      error={Boolean(touched.aredepto && errors.aredepto)} >
220
+                      {
221
+                      data ?
222
+                        data.data.map(cate => {
223
+                          return (
224
+                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
225
+                          )
226
+                        })
227
+                        : <MenuItem>Null</MenuItem>
228
+                    }
229
+                    </Select>
230
+                  </FormControl>
231
+
232
+
233
+                  <LocalizationProvider
234
+                    dateAdapter={DateFnsUtils}>
235
+                    <DesktopDatePicker
236
+                      label="Fecha Creación"
237
+                      fullWidth
238
+                      inputFormat="dd/MM/yyyy"
239
+                      {...getFieldProps('fecha')}
240
+                      xd
241
+                      value={date}
242
+                      onChange={setDate}
243
+                      renderInput={(params) =>
244
+                        <TextField
245
+                          disabled={true}
246
+                          label="Fecha Creación"
247
+                          fullWidth
248
+                          {...params}
249
+                          />}
250
+                      />
251
+                  </LocalizationProvider>
252
+
253
+                </Stack>
254
+
255
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
256
+                  <TextField
257
+                    id="filled-multiline-static"
258
+                    multiline
259
+                    rows={4}
260
+                    variant="filled"
261
+                    label="Notas"
262
+                    fullWidth
263
+                    type="text"
264
+                    {...getFieldProps('notas')}
265
+                    error={Boolean(touched.notas && errors.notas)}
266
+                    helperText={touched.notas && errors.notas}
267
+                    />
268
+                </Stack>
269
+              </Stack>
270
+            </TabPanel>
271
+
272
+
273
+            <Modal.Footer>
274
+              <Button
275
+                type="submit"
276
+                className="registerBtn"
277
+                variant="contained"
278
+                sx={{ mt: 1, mr: 1 }} >
279
+                {'Actualizar'}
280
+              </Button>
281
+            </Modal.Footer>
282
+
283
+          </Form>
284
+        </FormikProvider>
285
+      </Modal.Body>
286
+      <Backdrop
287
+        sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
288
+        open={open}
289
+        onClick={() => console.log('backdrop')} >
290
+        <CircularProgress color="inherit" />
291
+      </Backdrop>
292
+      <Toaster position="top-right" />
293
+
294
+    </Modal>
295
+  )
297 296
 }
298 297
 
299 298
 

+ 8 - 15
src/Components/Password/Rows.js

@@ -2,28 +2,22 @@ import { Operation } from './Operation'
2 2
 
3 3
 export const Encabezados = [
4 4
     {
5
-        name: 'pass',
6
-        numeric: false,
7
-        disablePadding: true,
8
-        label: 'Contraseña',
9
-    },
10
-    {
11 5
         name: 'name',
12 6
         numeric: false,
13 7
         disablePadding: true,
14 8
         label: 'Nombre',
15 9
     },
16 10
     {
17
-        name: 'apell',
11
+        name: 'activacion',
18 12
         numeric: false,
19 13
         disablePadding: true,
20
-        label: 'Apellido',
14
+        label: 'Fecha Activación',
21 15
     },
22 16
     {
23
-        name: 'mail',
17
+        name: 'dead',
24 18
         numeric: false,
25 19
         disablePadding: true,
26
-        label: 'Correo',
20
+        label: 'Fecha vencimiento',
27 21
     },
28 22
     {
29 23
         name: 'op',
@@ -52,12 +46,11 @@ export const niveles_educativos = [
52 46
 
53 47
 export function Build(pwds) {
54 48
     return pwds.map(password => {
55
-        let { candidato: user, plaza_id, pwd } = password
49
+        let {pwd , deadpwd, dateToActived, plaza_id} = password
56 50
         return {
57
-            pass: pwd ? atob(pwd): '',
58
-            name: user.nombre,
59
-            apell: user.apellidos,
60
-            mail: user.mail,
51
+            name:pwd, //user.nombre,
52
+            activacion:dateToActived, //user.apellidos,
53
+            daed: deadpwd,//,user.mail,
61 54
             op: <Operation plz={plaza_id} pwd={pwd} />
62 55
         }
63 56
     })

+ 45 - 41
src/Pages/ContrasV2.jsx

@@ -8,49 +8,53 @@ import { TableStyle, TextLabels } from '../Components/Password/TableStyle'
8 8
 
9 9
 import { useQuery } from 'react-query';
10 10
 import { Service } from '../Utils/HTTP.js'
11
-import useAuth from '../Auth/useAuth'
11
+import { useSelector } from 'react-redux';
12 12
 
13 13
 export function Contrasv2() {
14 14
 
15
-    const auth = useAuth();
16
-    const token = React.useRef(auth.getToken())
17
-
18
-    const getAllPwd = async () => {
19
-        let rest = new Service('/contrasenia/getallbyidUsr');
20
-        return await rest.getQuery(token.current)
21
-    }
22
-
23
-    const { data, status  } = useQuery('passwords', getAllPwd );
24
-
25
-    const options = {
26
-        filterType: 'checkbox',
27
-        customToolbar: () => {
28
-            return (
29
-                <CustomToolbar />
30
-            );
31
-        },
32
-        textLabels: TextLabels
33
-    };
34
-
35
-
36
-    return (
37
-        <div className="content-section">
38
-            <div className="main">
39
-                <Box sx={{ width: '100%' }}>
40
-                    <Paper elevation={0} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
41
-                        <ThemeProvider theme={TableStyle}>
42
-                            <MUIDataTable
43
-                                sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
44
-                                title={"Contraseñas"}
45
-                                data={Build( status ==='success' ? data.data : [])}
46
-                                columns={Encabezados}
47
-                                options={options}
48
-                            />
49
-                        </ThemeProvider>
50
-                    </Paper>
51
-                </Box>
52
-            </div>
53
-        </div>
54
-    );
15
+  const auth = useSelector((state) => state.token)
16
+
17
+  const getAllPwd = async () => {
18
+    let rest = new Service('/contrasenia/getallbyidUsr');
19
+    return await rest.getQuery(auth.token)
20
+  }
21
+
22
+  const { data, status  } = useQuery('passwords', getAllPwd );
23
+  console.log(data,status)
24
+
25
+  if(status === 'loading'){
26
+    return <h1>loading...</h1>
27
+  }
28
+
29
+  const options = {
30
+    filterType: 'checkbox',
31
+    customToolbar: () => {
32
+      return (
33
+        <CustomToolbar />
34
+      );
35
+    },
36
+    textLabels: TextLabels
37
+  };
38
+
39
+
40
+  return (
41
+    <div className="content-section">
42
+      <div className="main">
43
+        <Box sx={{ width: '100%' }}>
44
+          <Paper elevation={0} sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh', boxShadow: 'none !important' }}>
45
+            <ThemeProvider theme={TableStyle}>
46
+              <MUIDataTable
47
+                sx={{ '& MuiPaper': { elevation: 0, boxShadow: 'none', color: "red" } }}
48
+                title={"Contraseñas"}
49
+                data={Build( status ==='success' ? data.data : [])}
50
+                columns={Encabezados}
51
+                options={options}
52
+                />
53
+            </ThemeProvider>
54
+          </Paper>
55
+        </Box>
56
+      </div>
57
+    </div>
58
+  );
55 59
 
56 60
 }