|  | @@ -21,6 +21,21 @@ import toast, { Toaster } from 'react-hot-toast';
 | 
	
		
			
			| 21 | 21 |  import { Service } from '../../Utils/HTTP';
 | 
	
		
			
			| 22 | 22 |  import { useSelector } from 'react-redux'
 | 
	
		
			
			| 23 | 23 |  import { useQuery, useMutation, useQueryClient } from 'react-query'
 | 
	
		
			
			|  | 24 | +import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
 | 
	
		
			
			|  | 25 | +const filter = createFilterOptions();
 | 
	
		
			
			|  | 26 | +
 | 
	
		
			
			|  | 27 | +async function getPuestoSuperior(puesto, auth) {
 | 
	
		
			
			|  | 28 | +  if (puesto.length < 2) 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, id: item.id }))
 | 
	
		
			
			|  | 34 | +    return result;
 | 
	
		
			
			|  | 35 | +  }
 | 
	
		
			
			|  | 36 | +  return [];
 | 
	
		
			
			|  | 37 | +}
 | 
	
		
			
			|  | 38 | +
 | 
	
		
			
			| 24 | 39 |  
 | 
	
		
			
			| 25 | 40 |  const plazeSchema = Yup.object({
 | 
	
		
			
			| 26 | 41 |    id: Yup.number(),
 | 
	
	
		
			
			|  | @@ -42,7 +57,7 @@ function Edit(props) {
 | 
	
		
			
			| 42 | 57 |      resolver: yupResolver(plazeSchema),
 | 
	
		
			
			| 43 | 58 |      defaultValues: {
 | 
	
		
			
			| 44 | 59 |        nombrepuesto: 'mingtest',
 | 
	
		
			
			| 45 |  | -      puestosuperior: 0,
 | 
	
		
			
			|  | 60 | +      puestosuperior: null,
 | 
	
		
			
			| 46 | 61 |        fecha: '01/01/2019',
 | 
	
		
			
			| 47 | 62 |        notas: 'esto es un ejemplod e una nota',
 | 
	
		
			
			| 48 | 63 |        aredepto: 1,
 | 
	
	
		
			
			|  | @@ -81,10 +96,44 @@ function Edit(props) {
 | 
	
		
			
			| 81 | 96 |    const [open, setOpen] = React.useState(false);
 | 
	
		
			
			| 82 | 97 |    const [tab, setTab] = React.useState(0);
 | 
	
		
			
			| 83 | 98 |    const [checklist, setChecklist] = React.useState([]);
 | 
	
		
			
			|  | 99 | +  const [openSugg, setOpenSugg] = React.useState(false);
 | 
	
		
			
			|  | 100 | +  const [options, setOptions] = React.useState([]);
 | 
	
		
			
			|  | 101 | +  const [openDialog, toggleOpenDialog] = React.useState(false);
 | 
	
		
			
			|  | 102 | +  const [dialogValue, setDialogValueHook] = React.useState({
 | 
	
		
			
			|  | 103 | +    title: '',
 | 
	
		
			
			|  | 104 | +    id: '',
 | 
	
		
			
			|  | 105 | +  });
 | 
	
		
			
			| 84 | 106 |  
 | 
	
		
			
			| 85 |  | -  // const changePuestoSup = (event) => {
 | 
	
		
			
			| 86 |  | -  //   setPuestoSup(event.target.value);
 | 
	
		
			
			| 87 |  | -  // };
 | 
	
		
			
			|  | 107 | +  let setDialogValue = (value) => {
 | 
	
		
			
			|  | 108 | +    // console.log('llamada', value)
 | 
	
		
			
			|  | 109 | +    // setValues({...values, puestosuperior: value?.title })
 | 
	
		
			
			|  | 110 | +    setDialogValueHook(value)
 | 
	
		
			
			|  | 111 | +  }
 | 
	
		
			
			|  | 112 | +
 | 
	
		
			
			|  | 113 | +  const loading = openSugg && options.length === 0;
 | 
	
		
			
			|  | 114 | +
 | 
	
		
			
			|  | 115 | +  const AutoCompleteChange = (event, newValue) => {
 | 
	
		
			
			|  | 116 | +    console.log('newValue', newValue)
 | 
	
		
			
			|  | 117 | +    setValue('puestosuperior', newValue?.id)
 | 
	
		
			
			|  | 118 | +
 | 
	
		
			
			|  | 119 | +    if (typeof newValue === 'string') {
 | 
	
		
			
			|  | 120 | +      setTimeout(() => {
 | 
	
		
			
			|  | 121 | +        toggleOpenDialog(true);
 | 
	
		
			
			|  | 122 | +        setDialogValue({
 | 
	
		
			
			|  | 123 | +          title: newValue,
 | 
	
		
			
			|  | 124 | +          id: '',
 | 
	
		
			
			|  | 125 | +        });
 | 
	
		
			
			|  | 126 | +      });
 | 
	
		
			
			|  | 127 | +    } else if (newValue && newValue.inputValue) {
 | 
	
		
			
			|  | 128 | +      toggleOpenDialog(true);
 | 
	
		
			
			|  | 129 | +      setDialogValue({
 | 
	
		
			
			|  | 130 | +        title: newValue.inputValue,
 | 
	
		
			
			|  | 131 | +        id: '',
 | 
	
		
			
			|  | 132 | +      });
 | 
	
		
			
			|  | 133 | +    } else {
 | 
	
		
			
			|  | 134 | +      setDialogValue(newValue);
 | 
	
		
			
			|  | 135 | +    }
 | 
	
		
			
			|  | 136 | +  }
 | 
	
		
			
			| 88 | 137 |  
 | 
	
		
			
			| 89 | 138 |    const addPrueba = (check, id) => {
 | 
	
		
			
			| 90 | 139 |      let tests = getValues("tests")
 | 
	
	
		
			
			|  | @@ -115,28 +164,53 @@ function Edit(props) {
 | 
	
		
			
			| 115 | 164 |    }
 | 
	
		
			
			| 116 | 165 |  
 | 
	
		
			
			| 117 | 166 |    const puestoMutation = useMutation(updatePuesto)
 | 
	
		
			
			| 118 |  | -
 | 
	
		
			
			| 119 | 167 |    const close = () => toggle("EDIT", { id: null });
 | 
	
		
			
			| 120 | 168 |  
 | 
	
		
			
			| 121 | 169 |    const { data: categories } = useQuery('categories', getCategories);
 | 
	
		
			
			| 122 | 170 |    const { data: testsCatalog } = useQuery('tests', getTest);
 | 
	
		
			
			| 123 | 171 |  
 | 
	
		
			
			| 124 | 172 |    useEffect(() => {
 | 
	
		
			
			|  | 173 | +
 | 
	
		
			
			| 125 | 174 |      if (visible == null) return;
 | 
	
		
			
			| 126 | 175 |      let rest = new Service(`/plaza/getthis/${visible}`)
 | 
	
		
			
			| 127 | 176 |      rest
 | 
	
		
			
			| 128 | 177 |        .getQuery(auth.token)
 | 
	
		
			
			| 129 | 178 |        .then(response => {
 | 
	
		
			
			| 130 |  | -        console.log('puesto edit: ',response.data)
 | 
	
		
			
			| 131 |  | -        let { areadeptoplz_id, fecha, tests } = response.data;
 | 
	
		
			
			|  | 179 | +        let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
 | 
	
		
			
			| 132 | 180 |          let temp_test = tests.map(t => ({ id: t.id }))
 | 
	
		
			
			| 133 | 181 |          setChecklist(temp_test.map(t => t.id))
 | 
	
		
			
			|  | 182 | +        console.log('puesto sup',puestosuperior)
 | 
	
		
			
			|  | 183 | +        reset({ 
 | 
	
		
			
			|  | 184 | +          ...response.data, 
 | 
	
		
			
			|  | 185 | +          aredepto: areadeptoplz_id, 
 | 
	
		
			
			|  | 186 | +          fecha: new Date(fecha), 
 | 
	
		
			
			|  | 187 | +          tests: temp_test, 
 | 
	
		
			
			|  | 188 | +          puestosuperior: puestosuperior.id
 | 
	
		
			
			|  | 189 | +        })
 | 
	
		
			
			|  | 190 | +        // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
 | 
	
		
			
			|  | 191 | +      })
 | 
	
		
			
			|  | 192 | +      .catch(e => console.log(e))
 | 
	
		
			
			|  | 193 | +
 | 
	
		
			
			|  | 194 | +
 | 
	
		
			
			|  | 195 | +    let active = true;
 | 
	
		
			
			|  | 196 | +    if (!loading) {
 | 
	
		
			
			|  | 197 | +      return undefined;
 | 
	
		
			
			|  | 198 | +    }
 | 
	
		
			
			|  | 199 | +
 | 
	
		
			
			|  | 200 | +    (async () => {
 | 
	
		
			
			|  | 201 | +      let puestos = await getPuestoSuperior(dialogValue.title, auth)
 | 
	
		
			
			|  | 202 | +      if (active) {
 | 
	
		
			
			|  | 203 | +        setOptions(puestos);
 | 
	
		
			
			|  | 204 | +      }
 | 
	
		
			
			|  | 205 | +    })();
 | 
	
		
			
			|  | 206 | +
 | 
	
		
			
			|  | 207 | +    return () => {
 | 
	
		
			
			|  | 208 | +      active = false;
 | 
	
		
			
			|  | 209 | +    };
 | 
	
		
			
			| 134 | 210 |  
 | 
	
		
			
			| 135 | 211 |  
 | 
	
		
			
			| 136 |  | -        reset({ ...response.data, aredepto: areadeptoplz_id, fecha: new Date(fecha), tests: temp_test })
 | 
	
		
			
			| 137 |  | -      })
 | 
	
		
			
			| 138 |  | -      .catch(console.log)
 | 
	
		
			
			| 139 |  | -  }, [visible, auth, reset])
 | 
	
		
			
			|  | 212 | +
 | 
	
		
			
			|  | 213 | +  }, [visible, auth, reset, loading, dialogValue])
 | 
	
		
			
			| 140 | 214 |  
 | 
	
		
			
			| 141 | 215 |    const changeTab = (_event, newValue) => setTab(newValue);
 | 
	
		
			
			| 142 | 216 |  
 | 
	
	
		
			
			|  | @@ -193,30 +267,118 @@ function Edit(props) {
 | 
	
		
			
			| 193 | 267 |                    error={Boolean(errors?.nombrepuesto)}
 | 
	
		
			
			| 194 | 268 |                    {...register("nombrepuesto")} />
 | 
	
		
			
			| 195 | 269 |  
 | 
	
		
			
			|  | 270 | +
 | 
	
		
			
			| 196 | 271 |                  <FormControl fullWidth>
 | 
	
		
			
			| 197 |  | -                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
 | 
	
		
			
			| 198 | 272 |                    <Controller
 | 
	
		
			
			| 199 | 273 |                      helperText={errors.puestosuperior?.message}
 | 
	
		
			
			| 200 |  | -                    error={Boolean(errors?.puestosuperior)}
 | 
	
		
			
			|  | 274 | +                    error={errors?.puestosuperior}
 | 
	
		
			
			| 201 | 275 |                      name="puestosuperior"
 | 
	
		
			
			| 202 | 276 |                      control={control}
 | 
	
		
			
			| 203 |  | -                    render={({field}) => 
 | 
	
		
			
			| 204 |  | -                      <Select {...field}>
 | 
	
		
			
			| 205 |  | -                        {
 | 
	
		
			
			| 206 |  | -                          categories ?
 | 
	
		
			
			| 207 |  | -                            categories.data.map(cate => {
 | 
	
		
			
			| 208 |  | -                              return (
 | 
	
		
			
			| 209 |  | -                                <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
 | 
	
		
			
			| 210 |  | -                              )
 | 
	
		
			
			| 211 |  | -                            })
 | 
	
		
			
			| 212 |  | -                            : <MenuItem>Null</MenuItem>
 | 
	
		
			
			| 213 |  | -                        }
 | 
	
		
			
			| 214 |  | -                      </Select>
 | 
	
		
			
			|  | 277 | +                    render={({ field }) =>
 | 
	
		
			
			|  | 278 | +                      <Autocomplete
 | 
	
		
			
			|  | 279 | +                        fullWidth
 | 
	
		
			
			|  | 280 | +                        value={dialogValue}
 | 
	
		
			
			|  | 281 | +                        onChange={AutoCompleteChange}
 | 
	
		
			
			|  | 282 | +                        open={openSugg}
 | 
	
		
			
			|  | 283 | +                        onOpen={() => {
 | 
	
		
			
			|  | 284 | +                          setOpenSugg(true);
 | 
	
		
			
			|  | 285 | +                        }}
 | 
	
		
			
			|  | 286 | +                        onClose={() => {
 | 
	
		
			
			|  | 287 | +                          setOpenSugg(false);
 | 
	
		
			
			|  | 288 | +                        }}
 | 
	
		
			
			|  | 289 | +                        isOptionEqualToValue={(option, value) => option.title === value.title}
 | 
	
		
			
			|  | 290 | +                        filterOptions={(options, params) => {
 | 
	
		
			
			|  | 291 | +                          const filtered = filter(options, params);
 | 
	
		
			
			|  | 292 | +
 | 
	
		
			
			|  | 293 | +                          if (params.inputValue !== '') {
 | 
	
		
			
			|  | 294 | +                            filtered.push({
 | 
	
		
			
			|  | 295 | +                              inputValue: params.inputValue,
 | 
	
		
			
			|  | 296 | +                              title: `Add "${params.inputValue}"`,
 | 
	
		
			
			|  | 297 | +                            });
 | 
	
		
			
			|  | 298 | +                          }
 | 
	
		
			
			|  | 299 | +
 | 
	
		
			
			|  | 300 | +                          return filtered;
 | 
	
		
			
			|  | 301 | +                        }}
 | 
	
		
			
			|  | 302 | +                        id="puesto_superior_autocomplete"
 | 
	
		
			
			|  | 303 | +                        options={options}
 | 
	
		
			
			|  | 304 | +                        loading={loading}
 | 
	
		
			
			|  | 305 | +                        getOptionLabel={(option) => {
 | 
	
		
			
			|  | 306 | +                          if (typeof option === 'string') {
 | 
	
		
			
			|  | 307 | +                            return option;
 | 
	
		
			
			|  | 308 | +                          }
 | 
	
		
			
			|  | 309 | +                          if (option.inputValue) {
 | 
	
		
			
			|  | 310 | +                            return option.inputValue;
 | 
	
		
			
			|  | 311 | +                          }
 | 
	
		
			
			|  | 312 | +                          return option.title;
 | 
	
		
			
			|  | 313 | +                        }}
 | 
	
		
			
			|  | 314 | +                        selectOnFocus
 | 
	
		
			
			|  | 315 | +                        clearOnBlur
 | 
	
		
			
			|  | 316 | +                        handleHomeEndKeys
 | 
	
		
			
			|  | 317 | +                        renderOption={(props, option) => <li {...props}>{option.title}</li>}
 | 
	
		
			
			|  | 318 | +                        freeSolo
 | 
	
		
			
			|  | 319 | +                        renderInput={(params) => (
 | 
	
		
			
			|  | 320 | +                          <TextField
 | 
	
		
			
			|  | 321 | +                            {...params}
 | 
	
		
			
			|  | 322 | +                            {...register('puestosuperior')}
 | 
	
		
			
			|  | 323 | +                            error={Boolean(errors.puestosuperior)}
 | 
	
		
			
			|  | 324 | +                            label="Puesto Superior"
 | 
	
		
			
			|  | 325 | +                            InputProps={{
 | 
	
		
			
			|  | 326 | +                              ...params.InputProps,
 | 
	
		
			
			|  | 327 | +                              onChange: (event) => {
 | 
	
		
			
			|  | 328 | +                                // let title = event.target.value;
 | 
	
		
			
			|  | 329 | +                                // console.log('titulo',title)
 | 
	
		
			
			|  | 330 | +                                setOptions([]);
 | 
	
		
			
			|  | 331 | +                                setDialogValue({
 | 
	
		
			
			|  | 332 | +                                  title: event.target.value,
 | 
	
		
			
			|  | 333 | +                                  id: '',
 | 
	
		
			
			|  | 334 | +                                });
 | 
	
		
			
			|  | 335 | +                              },
 | 
	
		
			
			|  | 336 | +                              endAdornment: (
 | 
	
		
			
			|  | 337 | +                                <React.Fragment>
 | 
	
		
			
			|  | 338 | +                                  {loading ? <CircularProgress color="inherit" size={20} /> : null}
 | 
	
		
			
			|  | 339 | +                                  {params.InputProps.endAdornment}
 | 
	
		
			
			|  | 340 | +                                </React.Fragment>
 | 
	
		
			
			|  | 341 | +                              ),
 | 
	
		
			
			|  | 342 | +                            }}
 | 
	
		
			
			|  | 343 | +                          />
 | 
	
		
			
			|  | 344 | +                        )}
 | 
	
		
			
			|  | 345 | +
 | 
	
		
			
			|  | 346 | +                      />
 | 
	
		
			
			|  | 347 | +
 | 
	
		
			
			| 215 | 348 |                      }
 | 
	
		
			
			| 216 |  | -                    >
 | 
	
		
			
			| 217 |  | -                    
 | 
	
		
			
			|  | 349 | +                  >
 | 
	
		
			
			| 218 | 350 |                    </Controller>
 | 
	
		
			
			| 219 | 351 |                  </FormControl>
 | 
	
		
			
			|  | 352 | +
 | 
	
		
			
			|  | 353 | +
 | 
	
		
			
			|  | 354 | +                {
 | 
	
		
			
			|  | 355 | +                  /* <FormControl fullWidth>
 | 
	
		
			
			|  | 356 | +                  <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
 | 
	
		
			
			|  | 357 | +                  <Controller
 | 
	
		
			
			|  | 358 | +                    helperText={errors.puestosuperior?.message}
 | 
	
		
			
			|  | 359 | +                    error={Boolean(errors?.puestosuperior)}
 | 
	
		
			
			|  | 360 | +                    name="puestosuperior"
 | 
	
		
			
			|  | 361 | +                    control={control}
 | 
	
		
			
			|  | 362 | +                  render={({field}) => 
 | 
	
		
			
			|  | 363 | +                    <Select {...field}>
 | 
	
		
			
			|  | 364 | +                      {
 | 
	
		
			
			|  | 365 | +                        categories ?
 | 
	
		
			
			|  | 366 | +                          categories.data.map(cate => {
 | 
	
		
			
			|  | 367 | +                            return (
 | 
	
		
			
			|  | 368 | +                              <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
 | 
	
		
			
			|  | 369 | +                            )
 | 
	
		
			
			|  | 370 | +                      })
 | 
	
		
			
			|  | 371 | +                      : <MenuItem>Null</MenuItem>
 | 
	
		
			
			|  | 372 | +                      }
 | 
	
		
			
			|  | 373 | +                        </Select>
 | 
	
		
			
			|  | 374 | +                    }
 | 
	
		
			
			|  | 375 | +                  >
 | 
	
		
			
			|  | 376 | +
 | 
	
		
			
			|  | 377 | +                    </Controller>
 | 
	
		
			
			|  | 378 | +                  </FormControl> */
 | 
	
		
			
			|  | 379 | +                }
 | 
	
		
			
			|  | 380 | +
 | 
	
		
			
			|  | 381 | +
 | 
	
		
			
			| 220 | 382 |                </Stack>
 | 
	
		
			
			| 221 | 383 |  
 | 
	
		
			
			| 222 | 384 |                <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
 |