浏览代码

using new wave to validate my form

amenpunk 2 年之前
父节点
当前提交
a45c94e264
共有 6 个文件被更改,包括 505 次插入205 次删除
  1. 2 0
      package.json
  2. 20 5
      src/Components/Generics/loading.jsx
  3. 150 197
      src/Components/Modal/EditPlaza.js
  4. 2 3
      src/Components/Navigation/MenuMovil.jsx
  5. 8 0
      src/Pages/Puestos.jsx
  6. 323 0
      src/temp.js

+ 2 - 0
package.json

@@ -7,6 +7,7 @@
7 7
         "@date-io/date-fns": "^2.16.0",
8 8
         "@emotion/react": "^11.5.0",
9 9
         "@emotion/styled": "^11.3.0",
10
+        "@hookform/resolvers": "^2.9.10",
10 11
         "@iconify/icons-eva": "^1.1.0",
11 12
         "@iconify/react": "^3.1.3",
12 13
         "@mui/icons-material": "^5.1.0",
@@ -27,6 +28,7 @@
27 28
         "react": "^17.0.2",
28 29
         "react-bootstrap": "2.4.0",
29 30
         "react-dom": "^17.0.2",
31
+        "react-hook-form": "^7.39.4",
30 32
         "react-hot-toast": "^2.2.0",
31 33
         "react-query": "^3.34.12",
32 34
         "react-redux": "^8.0.4",

+ 20 - 5
src/Components/Generics/loading.jsx

@@ -1,6 +1,8 @@
1 1
 import React from "react";
2 2
 import '../../Css/loading.css'
3 3
 
4
+import { Paper, Box } from '@mui/material'
5
+
4 6
 export function Loading() {
5 7
 
6 8
   const types = [
@@ -9,12 +11,25 @@ export function Loading() {
9 11
   ];
10 12
 
11 13
   return (
12
-    <div className="loading_or_content">
13
-      <div className="snippet" data-title=".dot-pulse">
14
-        <div className="stage">
15
-          <div className={types[0]}></div>
16
-        </div>
14
+    <div className="content-section">
15
+      <div className="main">
16
+        <Box>
17
+          <Paper sx={{ mb: 2, padding: 2, }}>
18
+
19
+            <div className="content-section">
20
+              <div className="loading_or_content">
21
+                <div className="snippet" data-title=".dot-pulse">
22
+                  <div className="stage">
23
+                    <div className={types[0]}></div>
24
+                  </div>
25
+                </div>
26
+              </div>
27
+            </div>
28
+
29
+          </Paper>
30
+        </Box>
17 31
       </div>
18 32
     </div>
33
+
19 34
   )
20 35
 }

+ 150 - 197
src/Components/Modal/EditPlaza.js

@@ -1,24 +1,26 @@
1
-import React, { memo, useCallback, useMemo, useEffect } from 'react';
2
-import * as Yup from 'yup';
3
-import { useFormik, Form, FormikProvider } from 'formik';
1
+import React, { memo, useMemo, useEffect } from 'react';
4 2
 import { Modal } from 'react-bootstrap'
5
-import toast, { Toaster } from 'react-hot-toast';
3
+import { useForm, Controller } from "react-hook-form";
4
+import { yupResolver } from '@hookform/resolvers/yup';
5
+import * as Yup from 'yup';
6 6
 
7 7
 import DateFnsUtils from '@date-io/date-fns';
8 8
 import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
9 9
 import { TabPanel } from './TabPanel'
10 10
 
11 11
 import {
12
-    Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
13
-    Backdrop, CircularProgress,
14
-    Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
12
+  Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
13
+  Backdrop, CircularProgress,
14
+  Tabs,Tab,Box, Divider,FormGroup,FormControlLabel,Checkbox
15 15
 } from '@mui/material';
16 16
 
17
+import toast, { Toaster } from 'react-hot-toast';
18
+
17 19
 import { Service } from '../../Utils/HTTP';
18 20
 import { useSelector } from 'react-redux'
19 21
 import { useQuery, useMutation, useQueryClient } from 'react-query'
20 22
 
21
-const NewPlazaSchema = Yup.object().shape({
23
+const plazeSchema = Yup.object({
22 24
   id: Yup.number(),
23 25
   nombrepuesto:
24 26
   Yup.string().required('El nombre es requerido')
@@ -29,30 +31,38 @@ const NewPlazaSchema = Yup.object().shape({
29 31
   fecha: Yup.date("Ingresa una fecha válida"),
30 32
   notas: Yup.string("Ingresa una nota válida").min(5).max(150),
31 33
   tests: Yup.array()
32
-})
33
-
34
+}).required();
34 35
 
35 36
 
36 37
 function Edit(props) {
37 38
 
39
+  const {
40
+    reset,control,register, handleSubmit, formState: { errors } } = useForm({
41
+    resolver : yupResolver(plazeSchema),
42
+    defaultValues: {
43
+      nombrepuesto: 'mingtest',
44
+      puestosuperior: 77,
45
+      fecha: '01/01/2019',
46
+      notas: 'esto es un ejemplod e una nota',
47
+      aredepto : 1,
48
+    }
49
+  });
50
+
51
+  const onSubmit = data => {
52
+    console.log("SUBMIT: ",data)
53
+  }
54
+
38 55
   const now = useMemo(() => new Date(), [])
39 56
   const auth = useSelector((state) => state.token)
40
-  const queryClient = useQueryClient()
57
+  // const queryClient = useQueryClient()
41 58
   let { visible, toggle } = props
42 59
 
43
-  const [departamento, setDepartamento] = React.useState('');
44 60
   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 61
   const [tab, setTab] = React.useState(0);
52 62
   const [checklist, setChecklist] = React.useState([]);
53 63
 
54 64
   const addPrueba = (check,id) => {
55
-    let { tests } = values
65
+    let { tests } = { tests : []}
56 66
     let temp ;
57 67
     if(check){
58 68
       temp = [...tests, {id}]
@@ -60,7 +70,7 @@ function Edit(props) {
60 70
       temp = tests.filter( test => test.id !== id);
61 71
     }
62 72
     setChecklist(temp.map( test => test.id) )
63
-    setValues({...values, tests: temp})
73
+    // setValues({...values, tests: temp})
64 74
   };
65 75
 
66 76
   const getCategories = async () => {
@@ -82,62 +92,22 @@ function Edit(props) {
82 92
 
83 93
   const close = () => toggle("EDIT", {id : null});
84 94
 
85
-  const { data } = useQuery('categories', getCategories);
95
+  const { data: categories } = useQuery('categories', getCategories);
86 96
   const { data: testsCatalog } = useQuery('tests', getTest);
87 97
 
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')
108
-        },
109
-        onError:() => {
110
-          close();
111
-          setOpen(false)
112
-          toast.error("Lo sentimos ocurrió error inténtalo más tarde")
113
-        }
98
+  useEffect(() => {
99
+    if(visible == null) return;
100
+    let rest = new Service(`/plaza/getthis/${visible}`)
101
+    rest
102
+      .getQuery(auth.token)
103
+      .then( response => {
104
+        let { areadeptoplz_id, fecha } = response.data;
105
+        reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha)  })
114 106
       })
107
+      .catch(console.log)
108
+  },[visible])
115 109
 
116
-      resetForm();
117
-    },
118
-    validationSchema: NewPlazaSchema,
119
-  });
120
-
121
-  const { errors, touched, handleSubmit, getFieldProps, setValues, values } = formik;
122
-
123
-  useEffect(() => {
124
-    console.info('use effect edit', props)
125
-  },[props])
126
-
127
-  // useEffect(() => {
128
-  //   if (puesto) {
129
-  //     setValues({
130
-  //       id: puesto.id,
131
-  //       nombrepuesto: puesto.nombrepuesto,
132
-  //       puestosuperior: puesto.puestosuperior,
133
-  //       aredepto: puesto.areadeptoplz_id,
134
-  //       fecha: new Date(puesto.create_day),
135
-  //       notas: puesto.notas,
136
-  //       tests : puesto.tests
137
-  //     })
138
-  //     setChecklist(puesto.tests.map(( {id} ) => id))
139
-  //   }
140
-  // }, [puesto, now, setValues])
110
+  console.log("RENDER", props)
141 111
 
142 112
   const changeTab = (_event, newValue) => {
143 113
     setTab(newValue);
@@ -157,135 +127,119 @@ function Edit(props) {
157 127
           <Tab label="Pruebas" />
158 128
         </Tabs>
159 129
 
160
-        <FormikProvider style={{ padding: 25 }} value={formik}>
161
-          <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
162
-
163
-
164
-            <TabPanel value={tab} index={1}>
165
-              <Stack spacing={1}>
166
-<Box style={{ paddingTop :5, paddingLeft :15 }}>
167
-                  <Divider/>
168
-                  <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
169
-                  <Divider/>
170
-                  <FormGroup>
171
-                    {
172
-                    testsCatalog ?
173
-                      testsCatalog.data.map( test => (
174
-                        <FormControlLabel 
175
-                          key={test.id}
176
-                          control={
177
-                          <Checkbox 
178
-                            checked={checklist.includes((test.id))}
179
-                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
180
-                            />
181
-                        } 
182
-                          label={test.nombre} 
183
-                          />
184
-                      )): null
185
-                  }
186
-                  </FormGroup>
187
-                </Box>
130
+        <form onSubmit={handleSubmit(onSubmit)}>
131
+          <TabPanel value={tab} index={1}>
132
+            <Stack spacing={1}>
133
+              <Box style={{ paddingTop :5, paddingLeft :15 }}>
134
+                <Divider/>
135
+                <h4 style={{paddingTop :10, paddingBottom:10}}>Seleciona los test a realizar</h4>
136
+                <Divider/>
137
+                <FormGroup>
138
+                  {
139
+                  testsCatalog ?
140
+                    testsCatalog.data.map( test => (
141
+                      <FormControlLabel 
142
+                        label={test.nombre} 
143
+                        key={test.id}
144
+                        control={
145
+                        <Checkbox 
146
+                          checked={checklist.includes((test.id))}
147
+                          onChange={(event)=> addPrueba(event.target.checked,test.id)} /> } 
148
+                        />
149
+                    )): null
150
+                }
151
+                </FormGroup>
152
+              </Box>
153
+            </Stack>
154
+          </TabPanel>
155
+
156
+          <TabPanel value={tab} index={0} >
157
+            <Stack spacing={3}>
158
+
159
+              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
160
+
161
+                <TextField
162
+                  name="nombrepuesto"
163
+                  label="Nombre"
164
+                  fullWidth
165
+                  helperText={errors.nombrepuesto?.message}
166
+                  error={Boolean(errors?.nombrepuesto)}
167
+                  {...register("nombrepuesto")} />
168
+
169
+                <TextField
170
+                  name="puestosuperior"
171
+                  label="Puesto superior"
172
+                  fullWidth
173
+                  {...register("puestosuperior")} />
174
+
188 175
               </Stack>
189
-            </TabPanel>
190
-
191
-
192
-            <TabPanel value={tab} index={0} >
193
-              <Stack spacing={3}>
194
-
195
-                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
196
-
197
-                  <TextField
198
-                    label="Nombre"
199
-                    fullWidth
200
-                    {...getFieldProps('nombrepuesto')}
201
-                    error={Boolean(touched.nombrepuesto && errors.nombrepuesto)}
202
-                    helperText={touched.nombrepuesto && errors.nombrepuesto}
203
-                    />
204
-
205
-                  <TextField
206
-                    label="Puesto Superior"
207
-                    fullWidth
208
-                    {...getFieldProps('puestosuperior')}
209
-                    error={Boolean(touched.puestosuperior && errors.puestosuperior)}
210
-                    helperText={touched.puestosuperior && errors.puestosuperior}
211
-                    />
212
-
213
-                </Stack>
214
-                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
215
-                  <FormControl fullWidth>
216
-                    <InputLabel id="demo-simple-select-label">Departamento</InputLabel>
217
-                    <Select
218
-                      labelId="demo-simple-select-label"
219
-                      value={departamento}
220
-                      label="Departamento"
221
-                      onChange={changeDepartamento}
222
-                      {...getFieldProps('aredepto')}
223
-                      error={Boolean(touched.aredepto && errors.aredepto)} >
224
-                      {
225
-                      data ?
226
-                        data.data.map(cate => {
227
-                          return (
228
-                            <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
229
-                          )
230
-                        })
231
-                        : <MenuItem>Null</MenuItem>
232
-                    }
233
-                    </Select>
234
-                  </FormControl>
235
-
236
-
237
-                  <LocalizationProvider
238
-                    dateAdapter={DateFnsUtils}>
239
-                    <DesktopDatePicker
240
-                      label="Fecha Creación"
241
-                      fullWidth
242
-                      inputFormat="dd/MM/yyyy"
243
-                      {...getFieldProps('fecha')}
244
-                      xd
245
-                      value={date}
246
-                      onChange={setDate}
247
-                      renderInput={(params) =>
248
-                        <TextField
249
-                          disabled={true}
250
-                          label="Fecha Creación"
251
-                          fullWidth
252
-                          {...params}
253
-                          />}
254
-                      />
255
-                  </LocalizationProvider>
256
-
257
-                </Stack>
258
-
259
-                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
260
-                  <TextField
261
-                    id="filled-multiline-static"
262
-                    multiline
263
-                    rows={4}
264
-                    variant="filled"
265
-                    label="Notas"
266
-                    fullWidth
267
-                    type="text"
268
-                    {...getFieldProps('notas')}
269
-                    error={Boolean(touched.notas && errors.notas)}
270
-                    helperText={touched.notas && errors.notas}
271
-                    />
272
-                </Stack>
176
+
177
+              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
178
+
179
+                <FormControl fullWidth>
180
+                  <InputLabel>Departamento</InputLabel>
181
+                  <Controller
182
+                    name="aredepto"
183
+                    control={control}
184
+                    render={ ({field}) =>
185
+                      <Select {...field}>
186
+                        {
187
+                        categories ?
188
+                          categories.data.map(cate => {
189
+                            return (
190
+                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
191
+                            )
192
+                          })
193
+                          : <MenuItem value={1}>hola</MenuItem>
194
+                      }
195
+                      </Select>
196
+                  }>
197
+                  </Controller>
198
+                </FormControl>
199
+
200
+                <LocalizationProvider dateAdapter={DateFnsUtils}>
201
+                  <Controller
202
+                    name="fecha"
203
+                    control={control}
204
+                    render={({field}) => 
205
+                      <DesktopDatePicker
206
+                        {...field}
207
+                        label="Fecha Creación"
208
+                        fullWidth
209
+                        inputFormat="dd/MM/yyyy"
210
+                        renderInput={(params) => <TextField {...params} />}
211
+                        />
212
+                  } >
213
+                  </Controller>
214
+                </LocalizationProvider>
273 215
               </Stack>
274
-            </TabPanel>
275 216
 
217
+              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
218
+                <TextField
219
+                  name="notas"
220
+                  multiline
221
+                  rows={4}
222
+                  label="Notas"
223
+                  fullWidth
224
+                  type="text"
225
+                  {...register("notas")}
226
+                  />
227
+              </Stack>
228
+            </Stack>
229
+          </TabPanel>
276 230
 
277
-            <Modal.Footer>
278
-              <Button
279
-                type="submit"
280
-                className="registerBtn"
281
-                variant="contained"
282
-                sx={{ mt: 1, mr: 1 }} >
283
-                {'Actualizar'}
284
-              </Button>
285
-            </Modal.Footer>
231
+          <Modal.Footer>
232
+            <Button
233
+              type="submit"
234
+              className="registerBtn"
235
+              variant="contained"
236
+              sx={{ mt: 1, mr: 1 }} >
237
+              {'Actualizar'}
238
+            </Button>
239
+          </Modal.Footer>
240
+
241
+        </form>
286 242
 
287
-          </Form>
288
-        </FormikProvider>
289 243
       </Modal.Body>
290 244
       <Backdrop
291 245
         sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
@@ -299,5 +253,4 @@ function Edit(props) {
299 253
   )
300 254
 }
301 255
 
302
-
303 256
 export default memo(Edit);

+ 2 - 3
src/Components/Navigation/MenuMovil.jsx

@@ -9,15 +9,14 @@ import {
9 9
     SwipeableDrawer
10 10
 } from '@mui/material/'
11 11
 
12
-import { useSelector } from 'react-redux';
12
+// import { useSelector } from 'react-redux';
13 13
 
14 14
 // import useAuth from '../../Auth/useAuth'
15 15
 
16 16
 export function MenuMovil(props) {
17 17
 
18 18
   let { anchor, control } = props;
19
-  const auth = useSelector((state) => state.token)
20
-  console.log(auth.token)
19
+  // const auth = useSelector((state) => state.token)
21 20
 
22 21
   return (
23 22
     <React.Fragment >

+ 8 - 0
src/Pages/Puestos.jsx

@@ -88,6 +88,13 @@ export function Puestos() {
88 88
     }
89 89
   }, [edit, del, show])
90 90
 
91
+  if(isLoading){
92
+    return(
93
+      <Loading/>
94
+    )
95
+  }
96
+
97
+  /*
91 98
   if (isLoading) {
92 99
     return (
93 100
       <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
@@ -107,6 +114,7 @@ export function Puestos() {
107 114
       </Paper>
108 115
     )
109 116
   }
117
+    */
110 118
 
111 119
   const total_items = Divide(result.data).length
112 120
 

+ 323 - 0
src/temp.js

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