Bläddra i källkod

pre save new puesto superior

amenpunk 1 år sedan
förälder
incheckning
06a41cd137
1 ändrade filer med 29 tillägg och 53 borttagningar
  1. 29 53
      src/Components/Modal/AgregarManual.js

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

@@ -24,17 +24,17 @@ import { useSelector } from 'react-redux';
24 24
 
25 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 40
 function Manual(props) {
@@ -70,30 +70,31 @@ function Manual(props) {
70 70
   const [date, setDate] = React.useState(new Date());
71 71
   const [tab, setTab] = React.useState(0);
72 72
   const [checklist, setChecklist] = React.useState([]);
73
-  const [valueDialog, setValueDialog] = React.useState();
74 73
   const [openDialog, toggleOpenDialog] = React.useState(false);
75 74
   const [openSugg, setOpenSugg] = React.useState(false);
76 75
   const [options, setOptions] = React.useState([]);
77
-  const [dialogValue, setDialogValue] = React.useState({
76
+  const [dialogValue, setDialogValueHook] = React.useState({
78 77
     title: '',
79 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 87
   const loading = openSugg && options.length === 0;
83 88
 
84 89
   React.useEffect(() => {
85 90
 
86
-    console.log('dialogValue', dialogValue)
87 91
     let active = true;
88
-    console.log('loading', loading)
89 92
     if (!loading) {
90 93
       return undefined;
91 94
     }
92 95
 
93 96
     (async () => {
94 97
       let puestos = await getPuestoSuperior(dialogValue.title, auth)
95
-      console.log('puestos', puestos)
96
-
97 98
       if (active) {
98 99
         setOptions(puestos);
99 100
       }
@@ -124,7 +125,7 @@ function Manual(props) {
124 125
 
125 126
   const handleSubmitDialog = (event) => {
126 127
     event.preventDefault();
127
-    setValueDialog({
128
+    setDialogValue({
128 129
       title: dialogValue.title,
129 130
       year: parseInt(dialogValue.year, 10),
130 131
     });
@@ -133,8 +134,9 @@ function Manual(props) {
133 134
 
134 135
   const AutoCompleteChange = (event, newValue) => {
135 136
     console.log('newValue', newValue)
137
+    // TODO : formik logic to validate autocomplete
138
+
136 139
     if (typeof newValue === 'string') {
137
-      // timeout to avoid instant validation of the dialog's form.
138 140
       setTimeout(() => {
139 141
         toggleOpenDialog(true);
140 142
         setDialogValue({
@@ -149,7 +151,7 @@ function Manual(props) {
149 151
         year: '',
150 152
       });
151 153
     } else {
152
-      setValueDialog(newValue);
154
+      setDialogValue(newValue);
153 155
     }
154 156
   }
155 157
 
@@ -159,13 +161,12 @@ function Manual(props) {
159 161
   }
160 162
 
161 163
   const puestoMutation = useMutation(agregarPuesto)
162
-
163 164
   let { visible, onClose } = props
164 165
 
165 166
   const formik = useFormik({
166 167
     initialValues: {
167 168
       nombrepuesto: "",
168
-      puestosuperior: "The Godfather",
169
+      puestosuperior: "",
169 170
       aredepto: 1,
170 171
       fecha: date,
171 172
       notas: "",
@@ -178,12 +179,10 @@ function Manual(props) {
178 179
         setTab(1)
179 180
         return
180 181
       }
181
-
182 182
       setOpen(true)
183 183
       fields['fecha'] = new Date(fields.fecha).toISOString();
184 184
       fields['areadeptoplz_id'] = 1;
185 185
       fields['id'] = -1;
186
-
187 186
       puestoMutation.mutate(fields, {
188 187
         onSuccess: () => {
189 188
           setOpen(false)
@@ -201,11 +200,10 @@ function Manual(props) {
201 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 205
   const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
206
+  // console.log({ values })
209 207
 
210 208
   const addPrueba = (check, id) => {
211 209
     let { tests } = values
@@ -252,7 +250,7 @@ function Manual(props) {
252 250
                 autoFocus
253 251
                 margin="dense"
254 252
                 id="name"
255
-                value={dialogValue.title}
253
+                value={dialogValue?.title}
256 254
                 onChange={(event) =>
257 255
                   setDialogValue({
258 256
                     ...dialogValue,
@@ -267,7 +265,7 @@ function Manual(props) {
267 265
               <TextField
268 266
                 margin="dense"
269 267
                 id="name"
270
-                value={dialogValue.year}
268
+                value={dialogValue?.year}
271 269
                 onChange={(event) =>
272 270
                   setDialogValue({
273 271
                     ...dialogValue,
@@ -333,30 +331,9 @@ function Manual(props) {
333 331
 
334 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 334
                     <Autocomplete
358 335
                       fullWidth
359
-                      value={valueDialog}
336
+                      value={dialogValue}
360 337
                       onChange={AutoCompleteChange}
361 338
                       open={openSugg}
362 339
                       onOpen={() => {
@@ -404,8 +381,8 @@ function Manual(props) {
404 381
                           InputProps={{
405 382
                             ...params.InputProps,
406 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 386
                               setOptions([]);
410 387
                               setDialogValue({
411 388
                                 title: event.target.value,
@@ -424,7 +401,6 @@ function Manual(props) {
424 401
 
425 402
                     />
426 403
 
427
-
428 404
                   </FormControl>
429 405
 
430 406
                 </Stack>