7 Commits 9c57628a31 ... e082d63bcd

Author SHA1 Message Date
  amenpunk e082d63bcd fix roles add new types 1 year ago
  amenpunk e8a4b8706a edit plz shit 1 year ago
  amenpunk 8e82fdff73 edit plz fix formik 1 year ago
  amenpunk 201d05d363 fix bug on edit plz 1 year ago
  amenpunk b9b843c7ff edit puesto superior 1 year ago
  amenpunk a8c0515e44 first aproach 1 year ago
  amenpunk f304a1f977 first approach 1 year ago

+ 24 - 20
src/Components/Modal/AgregarManual.js

95
   });
95
   });
96
 
96
 
97
   let setDialogValue = (value) => {
97
   let setDialogValue = (value) => {
98
-    if (value?.id !== undefined && isNaN(value?.id) === false) {
99
-      setValues({ ...values, puestosuperior: value?.id })
100
-    }
98
+    // console.log('setDialogValue',value)
99
+    // if (value?.id !== undefined && isNaN(value?.id) === false) {
100
+    //   console.log('first if')
101
+    setValues({ ...values, puestosuperior: value?.id })
102
+    // }
101
     setDialogValueHook(value)
103
     setDialogValueHook(value)
104
+    // console.log(values)
102
   }
105
   }
103
 
106
 
104
   const loading = openSugg && options.length === 0;
107
   const loading = openSugg && options.length === 0;
123
 
126
 
124
   }, [loading, dialogValue, auth]);
127
   }, [loading, dialogValue, auth]);
125
 
128
 
126
-
127
-
128
   const handleClose = () => false
129
   const handleClose = () => false
129
 
130
 
130
   const changeDepartamento = (event) => {
131
   const changeDepartamento = (event) => {
152
   };
153
   };
153
 
154
 
154
   const AutoCompleteChange = (event, newValue) => {
155
   const AutoCompleteChange = (event, newValue) => {
156
+    // FIX: este set es el que realmente agrega al estado
155
     setValues({ ...values, puestosuperior: newValue?.id })
157
     setValues({ ...values, puestosuperior: newValue?.id })
156
-
157
     if (typeof newValue === 'string') {
158
     if (typeof newValue === 'string') {
158
       setTimeout(() => {
159
       setTimeout(() => {
159
         toggleOpenDialog(true);
160
         toggleOpenDialog(true);
264
               </DialogContentText>
265
               </DialogContentText>
265
 
266
 
266
               <TextField
267
               <TextField
268
+                fullWidth
267
                 autoFocus
269
                 autoFocus
268
                 margin="dense"
270
                 margin="dense"
269
                 id="name"
271
                 id="name"
279
                 variant="standard"
281
                 variant="standard"
280
               />
282
               />
281
 
283
 
282
-              <TextField
283
-                margin="dense"
284
-                id="name"
285
-                value={dialogValue?.id}
286
-                onChange={(event) =>
287
-                  setDialogValue({
288
-                    ...dialogValue,
289
-                    id: event.target.value,
284
+              {/*
285
+                <TextField
286
+                  margin="dense"
287
+                  id="name"
288
+                  value={dialogValue?.id}
289
+                  onChange={(event) =>
290
+                      setDialogValue({
291
+                        ...dialogValue,
292
+                        id: event.target.value,
290
                   })
293
                   })
291
-                }
292
-                label="Descripción"
293
-                type="text"
294
-                variant="standard"
294
+                  }
295
+                  label="Descripción"
296
+                  type="text"
297
+                  variant="standard"
295
               />
298
               />
299
+              */}
296
             </DialogContent>
300
             </DialogContent>
297
             <DialogActions>
301
             <DialogActions>
298
               <Button onClick={handleCloseDialog}>Cancelar</Button>
302
               <Button onClick={handleCloseDialog}>Cancelar</Button>
366
                         if (params.inputValue !== '') {
370
                         if (params.inputValue !== '') {
367
                           filtered.push({
371
                           filtered.push({
368
                             inputValue: params.inputValue,
372
                             inputValue: params.inputValue,
369
-                            title: `Add "${params.inputValue}"`,
373
+                            title: `Agregar "${params.inputValue}"`,
370
                           });
374
                           });
371
                         }
375
                         }
372
 
376
 
387
                       selectOnFocus
391
                       selectOnFocus
388
                       clearOnBlur
392
                       clearOnBlur
389
                       handleHomeEndKeys
393
                       handleHomeEndKeys
390
-                      renderOption={(props, option) => <li {...props}>{option.title}</li>}
394
+                      renderOption={(props, option) => <li key={option.id} {...props}>{option.title}</li>}
391
                       freeSolo
395
                       freeSolo
392
                       renderInput={(params) => (
396
                       renderInput={(params) => (
393
                         <TextField
397
                         <TextField

+ 261 - 246
src/Components/Modal/EditPlaza.js

1
-import React, { memo, useEffect } from 'react';
1
+import React, { memo, useEffect, useCallback, useRef } from 'react';
2
 import { Modal } from 'react-bootstrap'
2
 import { Modal } from 'react-bootstrap'
3
-import { useForm, Controller } from "react-hook-form";
4
-import { yupResolver } from '@hookform/resolvers/yup';
5
 import * as Yup from 'yup';
3
 import * as Yup from 'yup';
4
+import { useFormik, Form, FormikProvider } from 'formik';
6
 
5
 
7
 
6
 
8
 import { TabPanel } from './TabPanel'
7
 import { TabPanel } from './TabPanel'
27
 const filter = createFilterOptions();
26
 const filter = createFilterOptions();
28
 
27
 
29
 async function getPuestoSuperior(puesto, auth) {
28
 async function getPuestoSuperior(puesto, auth) {
29
+  // console.log('P:', puesto)
30
   if (puesto.length < 2) return []
30
   if (puesto.length < 2) return []
31
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
31
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32
   let result = await rest.get(auth.token)
32
   let result = await rest.get(auth.token)
54
   return { id, nombre }
54
   return { id, nombre }
55
 }
55
 }
56
 
56
 
57
-
58
 const plazeSchema = Yup.object({
57
 const plazeSchema = Yup.object({
59
   id: Yup.number(),
58
   id: Yup.number(),
60
   nombrepuesto:
59
   nombrepuesto:
71
 
70
 
72
 function Edit(props) {
71
 function Edit(props) {
73
 
72
 
74
-  const { setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
75
-    resolver: yupResolver(plazeSchema),
76
-    defaultValues: {
77
-      nombrepuesto: 'mingtest',
78
-      puestosuperior: null,
79
-      fecha: '01/01/2019',
80
-      notas: 'esto es un ejemplod e una nota',
73
+  const [date, setDate] = React.useState(new Date());
74
+
75
+  const formik = useFormik({
76
+    initialValues: {
77
+      id: 0,
78
+      nombrepuesto: "",
79
+      puestosuperior: 0,
81
       aredepto: 1,
80
       aredepto: 1,
81
+      fecha: date,
82
+      notas: "",
82
       tests: []
83
       tests: []
83
-    }
84
+    },
85
+    onSubmit: (fields, { resetForm }) => {
86
+      console.log('submit values', fields)
87
+      saveEditPlaza(fields)
88
+    },
89
+    validationSchema: plazeSchema,
84
   });
90
   });
85
 
91
 
86
-  const onSubmit = data => {
92
+
93
+  const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
94
+
95
+  const saveEditPlaza = data => {
87
 
96
 
88
     let body = {
97
     let body = {
89
       ...data,
98
       ...data,
90
-      fecha: new Date(data.fecha).toISOString()
99
+      fecha: new Date(data.fecha).toISOString(),
91
     }
100
     }
92
 
101
 
93
     puestoMutation.mutate(body, {
102
     puestoMutation.mutate(body, {
98
         queryClient.invalidateQueries('puestos')
107
         queryClient.invalidateQueries('puestos')
99
       },
108
       },
100
       onError: () => {
109
       onError: () => {
101
-        //close();
102
-        //setOpen(false)
103
         toast.error("Lo sentimos ocurrió error inténtalo más tarde")
110
         toast.error("Lo sentimos ocurrió error inténtalo más tarde")
104
       }
111
       }
105
     })
112
     })
109
   const auth = useSelector((state) => state.token)
116
   const auth = useSelector((state) => state.token)
110
   const queryClient = useQueryClient()
117
   const queryClient = useQueryClient()
111
   let { visible, toggle } = props
118
   let { visible, toggle } = props
112
-  // const [puestoSup, setPuestoSup] = React.useState('');
113
 
119
 
114
   const [open, setOpen] = React.useState(false);
120
   const [open, setOpen] = React.useState(false);
121
+  const [departamento, setDepartamento] = React.useState('');
122
+  const puestoref = useRef(null);
115
   const [tab, setTab] = React.useState(0);
123
   const [tab, setTab] = React.useState(0);
116
   const [checklist, setChecklist] = React.useState([]);
124
   const [checklist, setChecklist] = React.useState([]);
117
   const [openSugg, setOpenSugg] = React.useState(false);
125
   const [openSugg, setOpenSugg] = React.useState(false);
128
   };
136
   };
129
 
137
 
130
   const handleSubmitDialog = async (event) => {
138
   const handleSubmitDialog = async (event) => {
139
+    // console.log('handlesubmit', dialogValue)
131
     event.preventDefault();
140
     event.preventDefault();
132
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
141
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
133
     if (id) {
142
     if (id) {
136
         id: id,
145
         id: id,
137
       }
146
       }
138
       if (to_set.id) {
147
       if (to_set.id) {
148
+        // console.log("TO SET", to_set)
139
         setDialogValue(to_set);
149
         setDialogValue(to_set);
150
+        setValues({...values, puestosuperior: to_set.id})
140
       }
151
       }
141
     }
152
     }
142
     handleCloseDialog();
153
     handleCloseDialog();
143
   };
154
   };
144
 
155
 
145
-  let setDialogValue = (value) => {
146
-    if (value?.id !== undefined && isNaN(value?.id) === false) {
147
-      // setValues({ ...values, puestosuperior: value?.id })
148
-      setValue('puestosuperior', value?.id)
156
+  let setDialogValue = useCallback((value) => {
157
+    // console.log('value receivied', value)
158
+    let id = value?.id || 0;
159
+    if (id !== 0) {
160
+      console.log('setting value', id)
161
+
149
     }
162
     }
150
     setDialogValueHook(value)
163
     setDialogValueHook(value)
151
-  }
164
+  }, [])
165
+
166
+  const changeDepartamento = (event) => {
167
+    setDepartamento(event.target.value);
168
+  };
152
 
169
 
153
   const loading = openSugg && options.length === 0;
170
   const loading = openSugg && options.length === 0;
154
 
171
 
155
   const AutoCompleteChange = (event, newValue) => {
172
   const AutoCompleteChange = (event, newValue) => {
156
-    console.log('newValue', newValue)
157
-    setValue('puestosuperior', newValue?.id)
173
+    setValues({ ...values, puestosuperior: newValue?.id })
158
 
174
 
159
     if (typeof newValue === 'string') {
175
     if (typeof newValue === 'string') {
176
+      // console.log('if1')
160
       setTimeout(() => {
177
       setTimeout(() => {
161
         toggleOpenDialog(true);
178
         toggleOpenDialog(true);
162
         setDialogValue({
179
         setDialogValue({
165
         });
182
         });
166
       });
183
       });
167
     } else if (newValue && newValue.inputValue) {
184
     } else if (newValue && newValue.inputValue) {
185
+      // console.log('if2')
168
       toggleOpenDialog(true);
186
       toggleOpenDialog(true);
169
       setDialogValue({
187
       setDialogValue({
170
         title: newValue.inputValue,
188
         title: newValue.inputValue,
171
         id: '',
189
         id: '',
172
       });
190
       });
173
     } else {
191
     } else {
192
+      // console.log('if3')
174
       setDialogValue(newValue);
193
       setDialogValue(newValue);
175
     }
194
     }
176
   }
195
   }
177
 
196
 
178
   const addPrueba = (check, id) => {
197
   const addPrueba = (check, id) => {
179
-    let tests = getValues("tests")
180
-    console.log(tests)
198
+    let { tests } = values
181
     let temp;
199
     let temp;
182
     if (check) {
200
     if (check) {
183
       temp = [...tests, { id }]
201
       temp = [...tests, { id }]
185
       temp = tests.filter(test => test.id !== id);
203
       temp = tests.filter(test => test.id !== id);
186
     }
204
     }
187
     setChecklist(temp.map(test => test.id))
205
     setChecklist(temp.map(test => test.id))
188
-    setValue('tests', temp)
206
+    // setValue('tests', temp)
207
+    setValues({ ...values, tests: temp })
189
   };
208
   };
190
 
209
 
191
   const getCategories = async () => {
210
   const getCategories = async () => {
211
 
230
 
212
   useEffect(() => {
231
   useEffect(() => {
213
 
232
 
233
+    let current_id = values.id; // getValues('id')
234
+
214
     if (visible == null) return;
235
     if (visible == null) return;
215
-    let rest = new Service(`/plaza/getthis/${visible}`)
216
-    rest
217
-      .getQuery(auth.token)
218
-      .then(response => {
219
-        let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
220
-        let temp_test = tests.map(t => ({ id: t.id }))
221
-        setChecklist(temp_test.map(t => t.id))
222
-        console.log('puesto sup', puestosuperior)
223
-
224
-        let temp_puesto = {
225
-          title: puestosuperior.nombre,
226
-          id: puestosuperior.id
227
-        }
228
-        // setDialogValue(temp_puesto)
229
-        reset({
230
-          ...response.data,
231
-          aredepto: areadeptoplz_id,
232
-          fecha: new Date(fecha),
233
-          tests: temp_test,
234
-          puestosuperior: puestosuperior.id
236
+
237
+    if (current_id !== visible) {
238
+      let rest = new Service(`/plaza/getthis/${visible}`)
239
+      rest
240
+        .getQuery(auth.token)
241
+        .then(response => {
242
+        console.log('plz to edit: ', response.data)
243
+          let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
244
+          let temp_test = tests.map(t => ({ id: t.id }))
245
+          setChecklist(temp_test.map(t => t.id))
246
+          // console.log('puesto sup', puestosuperior)
247
+          setDialogValue({
248
+            title: puestosuperior.nombre,
249
+            id: puestosuperior.id
250
+          })
251
+          setValues({
252
+            ...response.data,
253
+            aredepto: areadeptoplz_id,
254
+            fecha: new Date(fecha),
255
+            tests: temp_test,
256
+            puestosuperior: puestosuperior.id
257
+          })
258
+          // console.log("INITIAL:", getValues())
235
         })
259
         })
236
-        // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
237
-      })
238
-      .catch(e => console.log(e))
260
+        .catch(e => console.log(e))
239
 
261
 
262
+    }
240
 
263
 
241
     let active = true;
264
     let active = true;
242
     if (!loading) {
265
     if (!loading) {
254
       active = false;
277
       active = false;
255
     };
278
     };
256
 
279
 
257
-
258
-
259
-  }, [visible, auth, reset, loading, dialogValue])
280
+  }, [visible, auth, loading, dialogValue, setDialogValue,setValues,values.id])
260
 
281
 
261
   const changeTab = (_event, newValue) => setTab(newValue);
282
   const changeTab = (_event, newValue) => setTab(newValue);
262
 
283
 
287
                 margin="dense"
308
                 margin="dense"
288
                 id="name"
309
                 id="name"
289
                 value={dialogValue?.title}
310
                 value={dialogValue?.title}
290
-                onChange={(event) =>
311
+                onChange={(event) => {
312
+                  // console.log('aa', event.target.value)
291
                   setDialogValue({
313
                   setDialogValue({
292
                     ...dialogValue,
314
                     ...dialogValue,
293
                     title: event.target.value,
315
                     title: event.target.value,
294
                   })
316
                   })
295
                 }
317
                 }
318
+                }
296
                 label="Puesto"
319
                 label="Puesto"
297
                 type="text"
320
                 type="text"
298
                 variant="standard"
321
                 variant="standard"
302
                 margin="dense"
325
                 margin="dense"
303
                 id="name"
326
                 id="name"
304
                 value={dialogValue?.id}
327
                 value={dialogValue?.id}
305
-                onChange={(event) =>
328
+                onChange={(event) => {
329
+                  // console.log('ev', event.target.value)
306
                   setDialogValue({
330
                   setDialogValue({
307
                     ...dialogValue,
331
                     ...dialogValue,
308
                     id: event.target.value,
332
                     id: event.target.value,
309
                   })
333
                   })
310
                 }
334
                 }
335
+                }
311
                 label="Descripción"
336
                 label="Descripción"
312
                 type="text"
337
                 type="text"
313
                 variant="standard"
338
                 variant="standard"
320
           </form>
345
           </form>
321
         </Dialog>
346
         </Dialog>
322
 
347
 
323
-
324
-
325
-
326
-        <form onSubmit={handleSubmit(onSubmit)}>
327
-          <TabPanel value={tab} index={1}>
328
-            <Stack spacing={1}>
329
-              <Box style={{ paddingTop: 5, paddingLeft: 15 }}>
330
-                <Divider />
331
-                <h4 style={{ paddingTop: 10, paddingBottom: 10 }}>Seleciona los test a realizar</h4>
332
-                <Divider />
333
-                <FormGroup>
334
-                  {
335
-                    testsCatalog ?
336
-                      testsCatalog.data.map(test => (
337
-                        <FormControlLabel
338
-                          label={test.nombre}
339
-                          key={test.id}
340
-                          control={
341
-                            <Checkbox
342
-                              checked={checklist.includes((test.id))}
343
-                              onChange={(event) => addPrueba(event.target.checked, test.id)} />}
344
-                        />
345
-                      )) : null
346
-                  }
347
-                </FormGroup>
348
-              </Box>
349
-            </Stack>
350
-          </TabPanel>
351
-
352
-          <TabPanel value={tab} index={0} >
353
-            <Stack spacing={3}>
354
-
355
-              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
356
-
357
-                <TextField
358
-                  name="nombrepuesto"
359
-                  label="Nombre"
360
-                  fullWidth
361
-                  helperText={errors.nombrepuesto?.message}
362
-                  error={Boolean(errors?.nombrepuesto)}
363
-                  {...register("nombrepuesto")} />
364
-
365
-
366
-                <FormControl fullWidth>
367
-                  <Controller
368
-                    helperText={errors.puestosuperior?.message}
369
-                    error={errors?.puestosuperior}
370
-                    name="puestosuperior"
371
-                    control={control}
372
-                    render={({ field }) =>
373
-                      <Autocomplete
374
-                        fullWidth
375
-                        value={dialogValue}
376
-                        onChange={AutoCompleteChange}
377
-                        open={openSugg}
378
-                        onOpen={() => {
379
-                          setOpenSugg(true);
380
-                        }}
381
-                        onClose={() => {
382
-                          setOpenSugg(false);
383
-                        }}
384
-                        isOptionEqualToValue={(option, value) => option.title === value.title}
385
-                        filterOptions={(options, params) => {
386
-                          const filtered = filter(options, params);
387
-
388
-                          if (params.inputValue !== '') {
389
-                            filtered.push({
390
-                              inputValue: params.inputValue,
391
-                              title: `Add "${params.inputValue}"`,
392
-                            });
393
-                          }
394
-
395
-                          return filtered;
396
-                        }}
397
-                        id="puesto_superior_autocomplete"
398
-                        options={options}
399
-                        loading={loading}
400
-                        getOptionLabel={(option) => {
401
-                          if (typeof option === 'string') {
402
-                            return option;
403
-                          }
404
-                          if (option.inputValue) {
405
-                            return option.inputValue;
406
-                          }
407
-                          return option.title;
408
-                        }}
409
-                        selectOnFocus
410
-                        clearOnBlur
411
-                        handleHomeEndKeys
412
-                        renderOption={(props, option) => <li {...props}>{option.title}</li>}
413
-                        freeSolo
414
-                        renderInput={(params) => (
415
-                          <TextField
416
-                            {...params}
417
-                            {...register('puestosuperior')}
418
-                            error={Boolean(errors.puestosuperior)}
419
-                            label="Puesto Superior"
420
-                            InputProps={{
421
-                              ...params.InputProps,
422
-                              onChange: (event) => {
423
-                                // let title = event.target.value;
424
-                                // console.log('titulo',title)
425
-                                setOptions([]);
426
-                                setDialogValue({
427
-                                  title: event.target.value,
428
-                                  id: '',
429
-                                });
430
-                              },
431
-                              endAdornment: (
432
-                                <React.Fragment>
433
-                                  {loading ? <CircularProgress color="inherit" size={20} /> : null}
434
-                                  {params.InputProps.endAdornment}
435
-                                </React.Fragment>
436
-                              ),
437
-                            }}
348
+        <FormikProvider style={{ paddingTop: 25 }} value={formik}>
349
+          <Form onSubmit={handleSubmit}>
350
+            <TabPanel value={tab} index={1}>
351
+              <Stack spacing={1}>
352
+                <Box style={{ paddingTop: 5, paddingLeft: 15 }}>
353
+                  <Divider />
354
+                  <h4 style={{ paddingTop: 10, paddingBottom: 10 }}>Seleciona los test a realizar</h4>
355
+                  <Divider />
356
+                  <FormGroup>
357
+                    {
358
+                      testsCatalog ?
359
+                        testsCatalog.data.map(test => (
360
+                          <FormControlLabel
361
+                            label={test.nombre}
362
+                            key={test.id}
363
+                            control={
364
+                              <Checkbox
365
+                                checked={checklist.includes((test.id))}
366
+                                onChange={(event) => addPrueba(event.target.checked, test.id)} />}
438
                           />
367
                           />
439
-                        )}
440
-
441
-                      />
442
-
368
+                        )) : null
443
                     }
369
                     }
444
-                  >
445
-                  </Controller>
446
-                </FormControl>
447
-
370
+                  </FormGroup>
371
+                </Box>
448
               </Stack>
372
               </Stack>
449
-
450
-              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
451
-
452
-                <FormControl fullWidth>
453
-                  <InputLabel id="demo-simple-select-label2">Departamento</InputLabel>
454
-                  <Controller
455
-                    helperText={errors.aredepto?.message}
456
-                    error={Boolean(errors?.aredepto)}
457
-                    name="aredepto"
458
-                    control={control}
459
-                    render={({ field }) =>
460
-                      <Select {...field}>
461
-                        {
462
-                          categories ?
463
-                            categories.data.map(cate => {
464
-                              return (
465
-                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
466
-                              )
467
-                            })
468
-                            : <MenuItem value={1}>hola</MenuItem>
373
+            </TabPanel>
374
+
375
+            <TabPanel value={tab} index={0} >
376
+              <Stack spacing={3}>
377
+
378
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
379
+
380
+                  <TextField
381
+                    name="nombrepuesto"
382
+                    label="Nombre"
383
+                    fullWidth
384
+                    helperText={errors.nombrepuesto?.message}
385
+                    error={Boolean(errors?.nombrepuesto)}
386
+                    {...getFieldProps("nombrepuesto")} />
387
+
388
+
389
+                  <FormControl fullWidth>
390
+                    <Autocomplete
391
+                      fullWidth
392
+                      value={dialogValue}
393
+                      onChange={AutoCompleteChange}
394
+                      open={openSugg}
395
+                      onOpen={() => {
396
+                        setOpenSugg(true);
397
+                      }}
398
+                      onClose={() => {
399
+                        setOpenSugg(false);
400
+                      }}
401
+                      isOptionEqualToValue={(option, value) => option.title === value.title}
402
+                      filterOptions={(options, params) => {
403
+                        const filtered = filter(options, params);
404
+
405
+                        if (params.inputValue !== '') {
406
+                          filtered.push({
407
+                            inputValue: params.inputValue,
408
+                            title: `Agregar "${params.inputValue}"`,
409
+                          });
469
                         }
410
                         }
470
-                      </Select>
471
-                    }>
472
-                  </Controller>
473
-                </FormControl>
474
-
475
-                <LocalizationProvider dateAdapter={DateFnsUtils}>
476
-                  <Controller
477
-                    name="fecha"
478
-                    control={control}
479
-                    render={({ field }) =>
480
-                      <DesktopDatePicker
481
-                        {...field}
482
-                        helperText={errors.fecha?.message}
483
-                        error={Boolean(errors?.fecha)}
484
-                        label="Fecha Creación"
485
-                        fullWidth
486
-                        inputFormat="dd/MM/yyyy"
487
-                        renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} />}
488
-                  >
489
-                  </Controller>
490
-                </LocalizationProvider>
491
-              </Stack>
492
 
411
 
493
-              <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
494
-                <TextField
495
-                  helperText={errors.notas?.message}
496
-                  error={Boolean(errors?.notas)}
497
-                  name="notas"
498
-                  multiline
499
-                  rows={4}
500
-                  label="Notas"
501
-                  fullWidth
502
-                  type="text"
503
-                  {...register("notas")}
504
-                />
412
+                        return filtered;
413
+                      }}
414
+                      id="puesto_superior_autocomplete"
415
+                      options={options}
416
+                      loading={loading}
417
+                      getOptionLabel={(option) => {
418
+                        if (typeof option === 'string') {
419
+                          return option;
420
+                        }
421
+                        if (option.inputValue) {
422
+                          return option.inputValue;
423
+                        }
424
+                        return option.title;
425
+                      }}
426
+                      selectOnFocus
427
+                      // clearOnBlur
428
+                      // handleHomeEndKeys
429
+                      renderOption={(props, option) => <li key={option.id} {...props}>{option.title}</li>}
430
+                      freeSolo
431
+                      renderInput={(params) => (
432
+                        <TextField
433
+                          {...params}
434
+                          {...getFieldProps('puestosuperior')}
435
+                          error={Boolean(errors.puestosuperior)}
436
+                          label="Puesto Superior"
437
+                          InputProps={{
438
+                            ...params.InputProps,
439
+                            onChange: (event) => {
440
+                              let title = event.target.value;
441
+                              // console.log('titulo', title)
442
+                              setOptions([]);
443
+                              setDialogValue({
444
+                                title: title,
445
+                                id: '',
446
+                              });
447
+                            },
448
+                            endAdornment: (
449
+                              <React.Fragment>
450
+                                {loading ? <CircularProgress color="inherit" size={20} /> : null}
451
+                                {params.InputProps.endAdornment}
452
+                              </React.Fragment>
453
+                            ),
454
+                          }}
455
+                        />
456
+                      )}
457
+
458
+                    />
459
+                  </FormControl>
460
+
461
+                </Stack>
462
+
463
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
464
+
465
+                  <FormControl fullWidth>
466
+                    <InputLabel id="demo-simple-select-label2">Departamento</InputLabel>
467
+                    <Select
468
+                      value={departamento}
469
+                      label="Departamento"
470
+                      onChange={changeDepartamento}
471
+                      {...getFieldProps('aredepto')}
472
+                      error={Boolean(touched.aredepto && errors.aredepto)}>
473
+                      {
474
+                        categories ?
475
+                          categories.data.map(cate => {
476
+                            return (
477
+                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
478
+                            )
479
+                          })
480
+                          : <MenuItem value={1}>hola</MenuItem>
481
+                      }
482
+                    </Select>
483
+                  </FormControl>
484
+
485
+                  <LocalizationProvider dateAdapter={DateFnsUtils}>
486
+                    <DesktopDatePicker
487
+                      {...getFieldProps('fecha')}
488
+                      helperText={errors.fecha?.message}
489
+                      error={Boolean(errors?.fecha)}
490
+                      label="Fecha Creación"
491
+                      fullWidth
492
+                      value={date}
493
+                      onChange={setDate}
494
+                      inputFormat="dd/MM/yyyy"
495
+                      renderInput={ (params) => 
496
+                        <TextField 
497
+                        disabled={true}
498
+                        {...params} 
499
+                        helperText={errors.fecha?.message} 
500
+                        />
501
+                      }
502
+                    />
503
+                  </LocalizationProvider>
504
+                </Stack>
505
+
506
+                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
507
+                  <TextField
508
+                    helperText={errors.notas?.message}
509
+                    error={Boolean(errors?.notas)}
510
+                    name="notas"
511
+                    multiline
512
+                    rows={4}
513
+                    label="Notas"
514
+                    fullWidth
515
+                    type="text"
516
+                    {...getFieldProps("notas")}
517
+                  />
518
+                </Stack>
505
               </Stack>
519
               </Stack>
506
-            </Stack>
507
-          </TabPanel>
508
-
509
-          <Modal.Footer>
510
-            <Button
511
-              type="submit"
512
-              className="registerBtn"
513
-              variant="contained"
514
-              sx={{ mt: 1, mr: 1 }} >
515
-              {'Actualizar'}
516
-            </Button>
517
-          </Modal.Footer>
518
-
519
-        </form>
520
+            </TabPanel>
521
+
522
+            <Modal.Footer>
523
+              <Button
524
+                ref={puestoref}
525
+                type="submit"
526
+                className="registerBtn"
527
+                variant="contained"
528
+                sx={{ mt: 1, mr: 1 }} >
529
+                {'Actualizar'}
530
+              </Button>
531
+            </Modal.Footer>
532
+
533
+          </Form>
534
+        </FormikProvider>
520
 
535
 
521
       </Modal.Body>
536
       </Modal.Body>
522
       <Backdrop
537
       <Backdrop

+ 14 - 5
src/Components/Password/Steps/TypePwd.jsx

7
 } from '@mui/material'
7
 } from '@mui/material'
8
 import toast, { Toaster } from 'react-hot-toast';
8
 import toast, { Toaster } from 'react-hot-toast';
9
 
9
 
10
-import { Simple as Loading } from '../../Generics/loading.jsx'
10
+// import { Simple as Loading } from '../../Generics/loading.jsx'
11
 
11
 
12
 const ROLE = {
12
 const ROLE = {
13
   ADMIN: 1,
13
   ADMIN: 1,
67
 function PermisosList(props) {
67
 function PermisosList(props) {
68
 
68
 
69
   let { recursos, selectedRole, setSelectedRole } = props
69
   let { recursos, selectedRole, setSelectedRole } = props
70
+  console.log("recursos len", recursos.data.length)
71
+  if(recursos.data.length === 0) return (<></>);
70
 
72
 
71
   return (
73
   return (
72
     <FormControl className="rolelist" >
74
     <FormControl className="rolelist" >
78
       >
80
       >
79
         {
81
         {
80
 
82
 
81
-          recursos.data.length === 0 ? <Loading /> :
83
+
84
+            recursos.data &&
82
             recursos.data.map((r) => {
85
             recursos.data.map((r) => {
83
               return (
86
               return (
84
                 <FormControlLabel
87
                 <FormControlLabel
223
       return rest.getQuery(auth.token);
226
       return rest.getQuery(auth.token);
224
     }
227
     }
225
     const groupRecursos = (recursos) => {
228
     const groupRecursos = (recursos) => {
229
+      console.log("resource:",recursos)
226
       let groups = {};
230
       let groups = {};
227
       recursos.forEach((r) => {
231
       recursos.forEach((r) => {
228
         if (groups[r.grupo]) {
232
         if (groups[r.grupo]) {
231
           groups[r.grupo] = [r]
235
           groups[r.grupo] = [r]
232
         }
236
         }
233
       })
237
       })
238
+      console.log('grupos: ', groups)
234
 
239
 
235
       assignRecursos(groups)
240
       assignRecursos(groups)
236
     }
241
     }
239
       let templete = {
244
       let templete = {
240
         1: { "label": 'Puestos', data: [] },
245
         1: { "label": 'Puestos', data: [] },
241
         2: { "label": 'Varios', data: [] },
246
         2: { "label": 'Varios', data: [] },
242
-        3: { "label": 'General', data: [] }
247
+        3: { "label": 'General', data: [] },
248
+        4: { "label": 'Contraseñas', data: [] },
249
+        5: { "label": 'Reportes', data: [] }
243
       }
250
       }
244
 
251
 
245
       Object.keys(recursos_api)
252
       Object.keys(recursos_api)
246
         .forEach((k) => {
253
         .forEach((k) => {
247
-          templete[k].data = recursos_api[k];
254
+          if(templete[k]){
255
+            templete[k].data = recursos_api[k];
256
+          }
248
         })
257
         })
249
 
258
 
250
       setRecursos(templete)
259
       setRecursos(templete)
257
   }, [auth.token])
266
   }, [auth.token])
258
 
267
 
259
   return (
268
   return (
260
-    <div class="gapwdrole">
269
+    <div className="gapwdrole">
261
 
270
 
262
       <div className="typepwdlist control_flow_role">
271
       <div className="typepwdlist control_flow_role">
263
         <TipoUsuarios type={userType} setType={setUserType} />
272
         <TipoUsuarios type={userType} setType={setUserType} />