Browse Source

pre save new puesto superior

amenpunk 1 year ago
parent
commit
06a41cd137
1 changed files with 29 additions and 53 deletions
  1. 29 53
      src/Components/Modal/AgregarManual.js

+ 29 - 53
src/Components/Modal/AgregarManual.js

24
 
24
 
25
 const filter = createFilterOptions();
25
 const filter = createFilterOptions();
26
 
26
 
27
-  async function getPuestoSuperior  (puesto, auth) {
28
-    if (puesto.length < 3) return []
29
-    let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30
-    let result = await rest.get(auth.token)
31
-    console.log(result)
32
-    if (result?.data?.length > 0) {
33
-      result = result.data.map((item) => ({ 'title': item.nombre, year: item.id }))
34
-      return result;
35
-    }
36
-    return [];
27
+async function getPuestoSuperior(puesto, auth) {
28
+  if (puesto.length < 3) return []
29
+  let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
30
+  let result = await rest.get(auth.token)
31
+  // console.log(result)
32
+  if (result?.data?.length > 0) {
33
+    result = result.data.map((item) => ({ 'title': item.nombre, year: item.id }))
34
+    return result;
37
   }
35
   }
36
+  return [];
37
+}
38
 
38
 
39
 
39
 
40
 function Manual(props) {
40
 function Manual(props) {
70
   const [date, setDate] = React.useState(new Date());
70
   const [date, setDate] = React.useState(new Date());
71
   const [tab, setTab] = React.useState(0);
71
   const [tab, setTab] = React.useState(0);
72
   const [checklist, setChecklist] = React.useState([]);
72
   const [checklist, setChecklist] = React.useState([]);
73
-  const [valueDialog, setValueDialog] = React.useState();
74
   const [openDialog, toggleOpenDialog] = React.useState(false);
73
   const [openDialog, toggleOpenDialog] = React.useState(false);
75
   const [openSugg, setOpenSugg] = React.useState(false);
74
   const [openSugg, setOpenSugg] = React.useState(false);
76
   const [options, setOptions] = React.useState([]);
75
   const [options, setOptions] = React.useState([]);
77
-  const [dialogValue, setDialogValue] = React.useState({
76
+  const [dialogValue, setDialogValueHook] = React.useState({
78
     title: '',
77
     title: '',
79
     year: '',
78
     year: '',
80
   });
79
   });
81
 
80
 
81
+  let setDialogValue = (value) => {
82
+    console.log('llamada', value)
83
+    // setValues({...values, puestosuperior: value?.title })
84
+    setDialogValueHook(value)
85
+  }
86
+
82
   const loading = openSugg && options.length === 0;
87
   const loading = openSugg && options.length === 0;
83
 
88
 
84
   React.useEffect(() => {
89
   React.useEffect(() => {
85
 
90
 
86
-    console.log('dialogValue', dialogValue)
87
     let active = true;
91
     let active = true;
88
-    console.log('loading', loading)
89
     if (!loading) {
92
     if (!loading) {
90
       return undefined;
93
       return undefined;
91
     }
94
     }
92
 
95
 
93
     (async () => {
96
     (async () => {
94
       let puestos = await getPuestoSuperior(dialogValue.title, auth)
97
       let puestos = await getPuestoSuperior(dialogValue.title, auth)
95
-      console.log('puestos', puestos)
96
-
97
       if (active) {
98
       if (active) {
98
         setOptions(puestos);
99
         setOptions(puestos);
99
       }
100
       }
124
 
125
 
125
   const handleSubmitDialog = (event) => {
126
   const handleSubmitDialog = (event) => {
126
     event.preventDefault();
127
     event.preventDefault();
127
-    setValueDialog({
128
+    setDialogValue({
128
       title: dialogValue.title,
129
       title: dialogValue.title,
129
       year: parseInt(dialogValue.year, 10),
130
       year: parseInt(dialogValue.year, 10),
130
     });
131
     });
133
 
134
 
134
   const AutoCompleteChange = (event, newValue) => {
135
   const AutoCompleteChange = (event, newValue) => {
135
     console.log('newValue', newValue)
136
     console.log('newValue', newValue)
137
+    // TODO : formik logic to validate autocomplete
138
+
136
     if (typeof newValue === 'string') {
139
     if (typeof newValue === 'string') {
137
-      // timeout to avoid instant validation of the dialog's form.
138
       setTimeout(() => {
140
       setTimeout(() => {
139
         toggleOpenDialog(true);
141
         toggleOpenDialog(true);
140
         setDialogValue({
142
         setDialogValue({
149
         year: '',
151
         year: '',
150
       });
152
       });
151
     } else {
153
     } else {
152
-      setValueDialog(newValue);
154
+      setDialogValue(newValue);
153
     }
155
     }
154
   }
156
   }
155
 
157
 
159
   }
161
   }
160
 
162
 
161
   const puestoMutation = useMutation(agregarPuesto)
163
   const puestoMutation = useMutation(agregarPuesto)
162
-
163
   let { visible, onClose } = props
164
   let { visible, onClose } = props
164
 
165
 
165
   const formik = useFormik({
166
   const formik = useFormik({
166
     initialValues: {
167
     initialValues: {
167
       nombrepuesto: "",
168
       nombrepuesto: "",
168
-      puestosuperior: "The Godfather",
169
+      puestosuperior: "",
169
       aredepto: 1,
170
       aredepto: 1,
170
       fecha: date,
171
       fecha: date,
171
       notas: "",
172
       notas: "",
178
         setTab(1)
179
         setTab(1)
179
         return
180
         return
180
       }
181
       }
181
-
182
       setOpen(true)
182
       setOpen(true)
183
       fields['fecha'] = new Date(fields.fecha).toISOString();
183
       fields['fecha'] = new Date(fields.fecha).toISOString();
184
       fields['areadeptoplz_id'] = 1;
184
       fields['areadeptoplz_id'] = 1;
185
       fields['id'] = -1;
185
       fields['id'] = -1;
186
-
187
       puestoMutation.mutate(fields, {
186
       puestoMutation.mutate(fields, {
188
         onSuccess: () => {
187
         onSuccess: () => {
189
           setOpen(false)
188
           setOpen(false)
201
     validationSchema: NewPlazaSchema,
200
     validationSchema: NewPlazaSchema,
202
   });
201
   });
203
 
202
 
204
-  const changeTab = (_event, newValue) => {
205
-    setTab(newValue);
206
-  };
203
+  const changeTab = (_event, newValue) => setTab(newValue);
207
 
204
 
208
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
205
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
206
+  // console.log({ values })
209
 
207
 
210
   const addPrueba = (check, id) => {
208
   const addPrueba = (check, id) => {
211
     let { tests } = values
209
     let { tests } = values
252
                 autoFocus
250
                 autoFocus
253
                 margin="dense"
251
                 margin="dense"
254
                 id="name"
252
                 id="name"
255
-                value={dialogValue.title}
253
+                value={dialogValue?.title}
256
                 onChange={(event) =>
254
                 onChange={(event) =>
257
                   setDialogValue({
255
                   setDialogValue({
258
                     ...dialogValue,
256
                     ...dialogValue,
267
               <TextField
265
               <TextField
268
                 margin="dense"
266
                 margin="dense"
269
                 id="name"
267
                 id="name"
270
-                value={dialogValue.year}
268
+                value={dialogValue?.year}
271
                 onChange={(event) =>
269
                 onChange={(event) =>
272
                   setDialogValue({
270
                   setDialogValue({
273
                     ...dialogValue,
271
                     ...dialogValue,
333
 
331
 
334
                   <FormControl fullWidth>
332
                   <FormControl fullWidth>
335
 
333
 
336
-                    {/*
337
-                    <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
338
-                      <Select
339
-                        labelId="demo-simple-select-label"
340
-                        value={puestoSup}
341
-                        label="Puesto Superior"
342
-                        onChange={changePuestoSup}
343
-                        {...getFieldProps('puestosuperior')}
344
-                        error={Boolean(touched.puestosuperior && errors.puestosuperior)} >
345
-                        {
346
-                          data ?
347
-                            data.data.map(cate => {
348
-                              return (
349
-                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
350
-                              )
351
-                            })
352
-                            : <MenuItem>Null</MenuItem>
353
-                        }
354
-                      </Select>
355
-*/}
356
-
357
                     <Autocomplete
334
                     <Autocomplete
358
                       fullWidth
335
                       fullWidth
359
-                      value={valueDialog}
336
+                      value={dialogValue}
360
                       onChange={AutoCompleteChange}
337
                       onChange={AutoCompleteChange}
361
                       open={openSugg}
338
                       open={openSugg}
362
                       onOpen={() => {
339
                       onOpen={() => {
404
                           InputProps={{
381
                           InputProps={{
405
                             ...params.InputProps,
382
                             ...params.InputProps,
406
                             onChange: (event) => {
383
                             onChange: (event) => {
407
-                              let title = event.target.value;
408
-                              console.log(title)
384
+                              // let title = event.target.value;
385
+                              // console.log('titulo',title)
409
                               setOptions([]);
386
                               setOptions([]);
410
                               setDialogValue({
387
                               setDialogValue({
411
                                 title: event.target.value,
388
                                 title: event.target.value,
424
 
401
 
425
                     />
402
                     />
426
 
403
 
427
-
428
                   </FormControl>
404
                   </FormControl>
429
 
405
 
430
                 </Stack>
406
                 </Stack>