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
 const filter = createFilterOptions();
27
 const filter = createFilterOptions();
28
 
28
 
29
 async function getPuestoSuperior(puesto, auth) {
29
 async function getPuestoSuperior(puesto, auth) {
30
-console.log('P:',puesto)
30
+  console.log('P:', puesto)
31
   if (puesto.length < 2) return []
31
   if (puesto.length < 2) return []
32
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
32
   let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
33
   let result = await rest.get(auth.token)
33
   let result = await rest.get(auth.token)
129
   };
129
   };
130
 
130
 
131
   const handleSubmitDialog = async (event) => {
131
   const handleSubmitDialog = async (event) => {
132
-  console.log('handlesubmit',dialogValue)
132
+    console.log('handlesubmit', dialogValue)
133
     event.preventDefault();
133
     event.preventDefault();
134
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
134
     let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
135
     if (id) {
135
     if (id) {
138
         id: id,
138
         id: id,
139
       }
139
       }
140
       if (to_set.id) {
140
       if (to_set.id) {
141
+        console.log("TO SET", to_set)
141
         setDialogValue(to_set);
142
         setDialogValue(to_set);
142
-        reset({ ...getValues(),puestosuperior: to_set.id })
143
+        // reset({ ...getValues(),puestosuperior: to_set.id })
143
       }
144
       }
144
     }
145
     }
145
     handleCloseDialog();
146
     handleCloseDialog();
149
     console.log('value receivied', value)
150
     console.log('value receivied', value)
150
     let id = value?.id || 0;
151
     let id = value?.id || 0;
151
     if (id !== 0) {
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
     setDialogValueHook(value)
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
   const loading = openSugg && options.length === 0;
165
   const loading = openSugg && options.length === 0;
177
 
166
 
178
   const AutoCompleteChange = (event, newValue) => {
167
   const AutoCompleteChange = (event, newValue) => {
179
     console.log('newValue', newValue)
168
     console.log('newValue', newValue)
180
     //this should be change
169
     //this should be change
181
-    setValue('puestosuperior', newValue?.id)
170
+    // setValue('puestosuperior', newValue?.id)
182
 
171
 
183
     if (typeof newValue === 'string') {
172
     if (typeof newValue === 'string') {
184
-    console.log('if1')
173
+      console.log('if1')
185
       setTimeout(() => {
174
       setTimeout(() => {
186
         toggleOpenDialog(true);
175
         toggleOpenDialog(true);
187
         setDialogValue({
176
         setDialogValue({
190
         });
179
         });
191
       });
180
       });
192
     } else if (newValue && newValue.inputValue) {
181
     } else if (newValue && newValue.inputValue) {
193
-    console.log('if2')
182
+      console.log('if2')
194
       toggleOpenDialog(true);
183
       toggleOpenDialog(true);
195
       setDialogValue({
184
       setDialogValue({
196
         title: newValue.inputValue,
185
         title: newValue.inputValue,
197
         id: '',
186
         id: '',
198
       });
187
       });
199
     } else {
188
     } else {
200
-    console.log('if3')
189
+      console.log('if3')
201
       setDialogValue(newValue);
190
       setDialogValue(newValue);
202
     }
191
     }
203
   }
192
   }
239
   useEffect(() => {
228
   useEffect(() => {
240
 
229
 
241
     let current_id = getValues('id')
230
     let current_id = getValues('id')
242
-    // console.log({ current_id, visible })
243
 
231
 
244
     if (visible == null) return;
232
     if (visible == null) return;
245
 
233
 
246
     if (current_id !== visible) {
234
     if (current_id !== visible) {
247
-    console.log('change with use effect')
248
-
249
       let rest = new Service(`/plaza/getthis/${visible}`)
235
       let rest = new Service(`/plaza/getthis/${visible}`)
250
       rest
236
       rest
251
         .getQuery(auth.token)
237
         .getQuery(auth.token)
284
 
270
 
285
     return () => {
271
     return () => {
286
       active = false;
272
       active = false;
287
-      // reset()
288
     };
273
     };
289
 
274
 
290
-
291
-
292
   }, [visible, auth, reset, loading, dialogValue, getValues, setDialogValue])
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
   const changeTab = (_event, newValue) => setTab(newValue);
277
   const changeTab = (_event, newValue) => setTab(newValue);
329
 
278
 
354
                 margin="dense"
303
                 margin="dense"
355
                 id="name"
304
                 id="name"
356
                 value={dialogValue?.title}
305
                 value={dialogValue?.title}
357
-                onChange={(event) =>
306
+                onChange={(event) => {
307
+                  console.log('aa', event.target.value)
358
                   setDialogValue({
308
                   setDialogValue({
359
                     ...dialogValue,
309
                     ...dialogValue,
360
                     title: event.target.value,
310
                     title: event.target.value,
361
                   })
311
                   })
362
                 }
312
                 }
313
+                }
363
                 label="Puesto"
314
                 label="Puesto"
364
                 type="text"
315
                 type="text"
365
                 variant="standard"
316
                 variant="standard"
369
                 margin="dense"
320
                 margin="dense"
370
                 id="name"
321
                 id="name"
371
                 value={dialogValue?.id}
322
                 value={dialogValue?.id}
372
-                onChange={(event) =>
323
+                onChange={(event) => {
324
+                  console.log('ev', event.target.value)
373
                   setDialogValue({
325
                   setDialogValue({
374
                     ...dialogValue,
326
                     ...dialogValue,
375
                     id: event.target.value,
327
                     id: event.target.value,
376
                   })
328
                   })
377
                 }
329
                 }
330
+                }
378
                 label="Descripción"
331
                 label="Descripción"
379
                 type="text"
332
                 type="text"
380
                 variant="standard"
333
                 variant="standard"
430
                   {...register("nombrepuesto")} />
383
                   {...register("nombrepuesto")} />
431
 
384
 
432
 
385
 
433
-                <FormControl fullWidth>
386
+                {/*
387
+                  <FormControl fullWidth>
434
                   <Controller
388
                   <Controller
435
                     helperText={errors.puestosuperior?.message}
389
                     helperText={errors.puestosuperior?.message}
436
                     error={errors?.puestosuperior}
390
                     error={errors?.puestosuperior}
437
                     name="puestosuperior"
391
                     name="puestosuperior"
438
                     control={control}
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
               </Stack>
470
               </Stack>
516
 
471