Browse Source

edit puesto superior

amenpunk 2 years ago
parent
commit
b9b843c7ff
1 changed files with 95 additions and 140 deletions
  1. 95 140
      src/Components/Modal/EditPlaza.js

+ 95 - 140
src/Components/Modal/EditPlaza.js

@@ -27,7 +27,7 @@ import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
27 27
 const filter = createFilterOptions();
28 28
 
29 29
 async function getPuestoSuperior(puesto, auth) {
30
-console.log('P:',puesto)
30
+  console.log('P:', puesto)
31 31
   if (puesto.length < 2) return []
32 32
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
33 33
   let result = await rest.get(auth.token)
@@ -129,7 +129,7 @@ function Edit(props) {
129 129
   };
130 130
 
131 131
   const handleSubmitDialog = async (event) => {
132
-  console.log('handlesubmit',dialogValue)
132
+    console.log('handlesubmit', dialogValue)
133 133
     event.preventDefault();
134 134
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
135 135
     if (id) {
@@ -138,8 +138,9 @@ function Edit(props) {
138 138
         id: id,
139 139
       }
140 140
       if (to_set.id) {
141
+        console.log("TO SET", to_set)
141 142
         setDialogValue(to_set);
142
-        reset({ ...getValues(),puestosuperior: to_set.id })
143
+        // reset({ ...getValues(),puestosuperior: to_set.id })
143 144
       }
144 145
     }
145 146
     handleCloseDialog();
@@ -149,39 +150,27 @@ function Edit(props) {
149 150
     console.log('value receivied', value)
150 151
     let id = value?.id || 0;
151 152
     if (id !== 0) {
152
-      reset({ ...getValues(),puestosuperior: id })
153
-      setValue('puestosuperior',id)
154
-      setDialogValueHook(value)
153
+      setValue('puestosuperior', id)
154
+      let temp = getValues();
155
+      // temp['puestosuperior'] = id
156
+      // temp['puestosuperior_id'] = id
157
+      console.log("TEMP", temp)
158
+      reset({ ...temp, puestosuperior: id })
159
+      // setDialogValueHook(value)
155 160
     }
161
+    console.log('SETTING:', value)
156 162
     setDialogValueHook(value)
157
-  },[setValue,reset,getValues])
158
-
159
-
160
-
161
-  // let setDialogValue = useCallback((value) => {
162
-  // console.log('value receivied', value)
163
-  //   let id = value.id || 0;
164
-  //   if (id !== 0) {
165
-  //     console.log('setiando valor', value)
166
-  //     setValue({ puestosuperior: value?.id })
167
-  //      // setDialogValueHook(value)
168
-  //   }
169
-  //   console.log("setiando valor false", value)
170
-  //   // setDialogValueHook(value)
171
-  // }, [setValue])
172
-
173
-
174
-
163
+  }, [setValue, reset, getValues])
175 164
 
176 165
   const loading = openSugg && options.length === 0;
177 166
 
178 167
   const AutoCompleteChange = (event, newValue) => {
179 168
     console.log('newValue', newValue)
180 169
     //this should be change
181
-    setValue('puestosuperior', newValue?.id)
170
+    // setValue('puestosuperior', newValue?.id)
182 171
 
183 172
     if (typeof newValue === 'string') {
184
-    console.log('if1')
173
+      console.log('if1')
185 174
       setTimeout(() => {
186 175
         toggleOpenDialog(true);
187 176
         setDialogValue({
@@ -190,14 +179,14 @@ function Edit(props) {
190 179
         });
191 180
       });
192 181
     } else if (newValue && newValue.inputValue) {
193
-    console.log('if2')
182
+      console.log('if2')
194 183
       toggleOpenDialog(true);
195 184
       setDialogValue({
196 185
         title: newValue.inputValue,
197 186
         id: '',
198 187
       });
199 188
     } else {
200
-    console.log('if3')
189
+      console.log('if3')
201 190
       setDialogValue(newValue);
202 191
     }
203 192
   }
@@ -239,13 +228,10 @@ function Edit(props) {
239 228
   useEffect(() => {
240 229
 
241 230
     let current_id = getValues('id')
242
-    // console.log({ current_id, visible })
243 231
 
244 232
     if (visible == null) return;
245 233
 
246 234
     if (current_id !== visible) {
247
-    console.log('change with use effect')
248
-
249 235
       let rest = new Service(`/plaza/getthis/${visible}`)
250 236
       rest
251 237
         .getQuery(auth.token)
@@ -284,46 +270,9 @@ function Edit(props) {
284 270
 
285 271
     return () => {
286 272
       active = false;
287
-      // reset()
288 273
     };
289 274
 
290
-
291
-
292 275
   }, [visible, auth, reset, loading, dialogValue, getValues, setDialogValue])
293
-  // console.log('PROPS', props)
294
-
295
-
296
-  // if (props.visible !== getValues('id') ) {
297
-  //
298
-  //   let rest = new Service(`/plaza/getthis/${visible}`)
299
-  //   rest
300
-  //     .getQuery(auth.token)
301
-  //     .then(response => {
302
-  //
303
-  //       console.log('initial  value', dialogValue)
304
-  //       let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
305
-  //       let temp_test = tests.map(t => ({ id: t.id }))
306
-  //       setChecklist(temp_test.map(t => t.id))
307
-  //       console.log('puesto sup', puestosuperior)
308
-  //       reset({
309
-  //         ...response.data,
310
-  //         aredepto: areadeptoplz_id,
311
-  //         fecha: new Date(fecha),
312
-  //         tests: temp_test,
313
-  //         puestosuperior: puestosuperior.id
314
-  //       })
315
-  //       let temp = { title: puestosuperior.nombre, id: puestosuperior.id }
316
-  //       console.log(temp)
317
-  //       if (dialogValue?.id !== temp.id) {
318
-  //         setDialogValueHook(temp)
319
-  //       }
320
-  //
321
-  //     })
322
-  //     .catch(e => console.log(e))
323
-  // }else {
324
-  //   console.log("no es visible y el puesto superior no es 0",{ visible,"p": getValues('puestosuperior')})
325
-  // }
326
-
327 276
 
328 277
   const changeTab = (_event, newValue) => setTab(newValue);
329 278
 
@@ -354,12 +303,14 @@ function Edit(props) {
354 303
                 margin="dense"
355 304
                 id="name"
356 305
                 value={dialogValue?.title}
357
-                onChange={(event) =>
306
+                onChange={(event) => {
307
+                  console.log('aa', event.target.value)
358 308
                   setDialogValue({
359 309
                     ...dialogValue,
360 310
                     title: event.target.value,
361 311
                   })
362 312
                 }
313
+                }
363 314
                 label="Puesto"
364 315
                 type="text"
365 316
                 variant="standard"
@@ -369,12 +320,14 @@ function Edit(props) {
369 320
                 margin="dense"
370 321
                 id="name"
371 322
                 value={dialogValue?.id}
372
-                onChange={(event) =>
323
+                onChange={(event) => {
324
+                  console.log('ev', event.target.value)
373 325
                   setDialogValue({
374 326
                     ...dialogValue,
375 327
                     id: event.target.value,
376 328
                   })
377 329
                 }
330
+                }
378 331
                 label="Descripción"
379 332
                 type="text"
380 333
                 variant="standard"
@@ -430,87 +383,89 @@ function Edit(props) {
430 383
                   {...register("nombrepuesto")} />
431 384
 
432 385
 
433
-                <FormControl fullWidth>
386
+                {/*
387
+                  <FormControl fullWidth>
434 388
                   <Controller
435 389
                     helperText={errors.puestosuperior?.message}
436 390
                     error={errors?.puestosuperior}
437 391
                     name="puestosuperior"
438 392
                     control={control}
439
-                    render={({ field }) =>
440
-                      <Autocomplete
441
-                        fullWidth
442
-                        value={dialogValue}
443
-                        onChange={AutoCompleteChange}
444
-                        open={openSugg}
445
-                        onOpen={() => {
446
-                          setOpenSugg(true);
447
-                        }}
448
-                        onClose={() => {
449
-                          setOpenSugg(false);
450
-                        }}
451
-                        isOptionEqualToValue={(option, value) => option.title === value.title}
452
-                        filterOptions={(options, params) => {
453
-                          const filtered = filter(options, params);
454
-
455
-                          if (params.inputValue !== '') {
456
-                            filtered.push({
457
-                              inputValue: params.inputValue,
458
-                              title: `Add "${params.inputValue}"`,
393
+                  render={({ field }) =>
394
+                    <Autocomplete
395
+                      fullWidth
396
+                      value={dialogValue}
397
+                      onChange={AutoCompleteChange}
398
+                      open={openSugg}
399
+                    onOpen={() => {
400
+                      setOpenSugg(true);
401
+                      }}
402
+                    onClose={() => {
403
+                      setOpenSugg(false);
404
+                      }}
405
+                      isOptionEqualToValue={(option, value) => option.title === value.title}
406
+                    filterOptions={(options, params) => {
407
+                      const filtered = filter(options, params);
408
+
409
+                      if (params.inputValue !== '') {
410
+                        filtered.push({
411
+                          inputValue: params.inputValue,
412
+                          title: `Agregar "${params.inputValue}"`,
413
+                        });
414
+                      }
415
+
416
+                      return filtered;
417
+                      }}
418
+                      id="puesto_superior_autocomplete"
419
+                      options={options}
420
+                      loading={loading}
421
+                    getOptionLabel={(option) => {
422
+                      if (typeof option === 'string') {
423
+                        return option;
424
+                      }
425
+                      if (option.inputValue) {
426
+                        return option.inputValue;
427
+                      }
428
+                      return option.title;
429
+                      }}
430
+                      selectOnFocus
431
+                      clearOnBlur
432
+                      handleHomeEndKeys
433
+                      renderOption={(props, option) => <li key={option.id} {...props}>{option.title}</li>}
434
+                      freeSolo
435
+                    renderInput={(params) => (
436
+                      <TextField
437
+                        {...params}
438
+                        {...register('puestosuperior')}
439
+                        error={Boolean(errors.puestosuperior)}
440
+                        label="Puesto Superior"
441
+                      InputProps={{
442
+                        ...params.InputProps,
443
+                          onChange: (event) => {
444
+                            // let title = event.target.value;
445
+                            // console.log('titulo',title)
446
+                            setOptions([]);
447
+                            setDialogValue({
448
+                              title: event.target.value,
449
+                              id: '',
459 450
                             });
460
-                          }
461
-
462
-                          return filtered;
451
+                          },
452
+                          endAdornment: (
453
+                        <React.Fragment>
454
+                        {loading ? <CircularProgress color="inherit" size={20} /> : null}
455
+                        {params.InputProps.endAdornment}
456
+                            </React.Fragment>
457
+                          ),
463 458
                         }}
464
-                        id="puesto_superior_autocomplete"
465
-                        options={options}
466
-                        loading={loading}
467
-                        getOptionLabel={(option) => {
468
-                          if (typeof option === 'string') {
469
-                            return option;
470
-                          }
471
-                          if (option.inputValue) {
472
-                            return option.inputValue;
473
-                          }
474
-                          return option.title;
475
-                        }}
476
-                        selectOnFocus
477
-                        clearOnBlur
478
-                        handleHomeEndKeys
479
-                        renderOption={(props, option) => <li {...props}>{option.title}</li>}
480
-                        freeSolo
481
-                        renderInput={(params) => (
482
-                          <TextField
483
-                            {...params}
484
-                            {...register('puestosuperior')}
485
-                            error={Boolean(errors.puestosuperior)}
486
-                            label="Puesto Superior"
487
-                            InputProps={{
488
-                              ...params.InputProps,
489
-                              onChange: (event) => {
490
-                                // let title = event.target.value;
491
-                                // console.log('titulo',title)
492
-                                setOptions([]);
493
-                                setDialogValue({
494
-                                  title: event.target.value,
495
-                                  id: '',
496
-                                });
497
-                              },
498
-                              endAdornment: (
499
-                                <React.Fragment>
500
-                                  {loading ? <CircularProgress color="inherit" size={20} /> : null}
501
-                                  {params.InputProps.endAdornment}
502
-                                </React.Fragment>
503
-                              ),
504
-                            }}
505
-                          />
506
-                        )}
459
+                      />
460
+                      )}
507 461
 
508 462
                       />
509 463
 
510 464
                     }
511
-                  >
512
-                  </Controller>
513
-                </FormControl>
465
+                    >
466
+                        </Controller>
467
+                    </FormControl>
468
+                    */}
514 469
 
515 470
               </Stack>
516 471