|
@@ -21,6 +21,21 @@ import toast, { Toaster } from 'react-hot-toast';
|
|
|
import { Service } from '../../Utils/HTTP';
|
|
import { Service } from '../../Utils/HTTP';
|
|
|
import { useSelector } from 'react-redux'
|
|
import { useSelector } from 'react-redux'
|
|
|
import { useQuery, useMutation, useQueryClient } from 'react-query'
|
|
import { useQuery, useMutation, useQueryClient } from 'react-query'
|
|
|
|
|
+import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
|
|
|
|
|
+const filter = createFilterOptions();
|
|
|
|
|
+
|
|
|
|
|
+async function getPuestoSuperior(puesto, auth) {
|
|
|
|
|
+ if (puesto.length < 2) return []
|
|
|
|
|
+ let rest = new Service(`/plaza/keypuestosup?keyword=${puesto}`)
|
|
|
|
|
+ let result = await rest.get(auth.token)
|
|
|
|
|
+ // console.log(result)
|
|
|
|
|
+ if (result?.data?.length > 0) {
|
|
|
|
|
+ result = result.data.map((item) => ({ 'title': item.nombre, id: item.id }))
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ return [];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const plazeSchema = Yup.object({
|
|
const plazeSchema = Yup.object({
|
|
|
id: Yup.number(),
|
|
id: Yup.number(),
|
|
@@ -42,7 +57,7 @@ function Edit(props) {
|
|
|
resolver: yupResolver(plazeSchema),
|
|
resolver: yupResolver(plazeSchema),
|
|
|
defaultValues: {
|
|
defaultValues: {
|
|
|
nombrepuesto: 'mingtest',
|
|
nombrepuesto: 'mingtest',
|
|
|
- puestosuperior: 0,
|
|
|
|
|
|
|
+ puestosuperior: null,
|
|
|
fecha: '01/01/2019',
|
|
fecha: '01/01/2019',
|
|
|
notas: 'esto es un ejemplod e una nota',
|
|
notas: 'esto es un ejemplod e una nota',
|
|
|
aredepto: 1,
|
|
aredepto: 1,
|
|
@@ -81,10 +96,44 @@ function Edit(props) {
|
|
|
const [open, setOpen] = React.useState(false);
|
|
const [open, setOpen] = React.useState(false);
|
|
|
const [tab, setTab] = React.useState(0);
|
|
const [tab, setTab] = React.useState(0);
|
|
|
const [checklist, setChecklist] = React.useState([]);
|
|
const [checklist, setChecklist] = React.useState([]);
|
|
|
|
|
+ const [openSugg, setOpenSugg] = React.useState(false);
|
|
|
|
|
+ const [options, setOptions] = React.useState([]);
|
|
|
|
|
+ const [openDialog, toggleOpenDialog] = React.useState(false);
|
|
|
|
|
+ const [dialogValue, setDialogValueHook] = React.useState({
|
|
|
|
|
+ title: '',
|
|
|
|
|
+ id: '',
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // const changePuestoSup = (event) => {
|
|
|
|
|
- // setPuestoSup(event.target.value);
|
|
|
|
|
- // };
|
|
|
|
|
|
|
+ let setDialogValue = (value) => {
|
|
|
|
|
+ // console.log('llamada', value)
|
|
|
|
|
+ // setValues({...values, puestosuperior: value?.title })
|
|
|
|
|
+ setDialogValueHook(value)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const loading = openSugg && options.length === 0;
|
|
|
|
|
+
|
|
|
|
|
+ const AutoCompleteChange = (event, newValue) => {
|
|
|
|
|
+ console.log('newValue', newValue)
|
|
|
|
|
+ setValue('puestosuperior', newValue?.id)
|
|
|
|
|
+
|
|
|
|
|
+ if (typeof newValue === 'string') {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ toggleOpenDialog(true);
|
|
|
|
|
+ setDialogValue({
|
|
|
|
|
+ title: newValue,
|
|
|
|
|
+ id: '',
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (newValue && newValue.inputValue) {
|
|
|
|
|
+ toggleOpenDialog(true);
|
|
|
|
|
+ setDialogValue({
|
|
|
|
|
+ title: newValue.inputValue,
|
|
|
|
|
+ id: '',
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setDialogValue(newValue);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const addPrueba = (check, id) => {
|
|
const addPrueba = (check, id) => {
|
|
|
let tests = getValues("tests")
|
|
let tests = getValues("tests")
|
|
@@ -115,28 +164,53 @@ function Edit(props) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const puestoMutation = useMutation(updatePuesto)
|
|
const puestoMutation = useMutation(updatePuesto)
|
|
|
-
|
|
|
|
|
const close = () => toggle("EDIT", { id: null });
|
|
const close = () => toggle("EDIT", { id: null });
|
|
|
|
|
|
|
|
const { data: categories } = useQuery('categories', getCategories);
|
|
const { data: categories } = useQuery('categories', getCategories);
|
|
|
const { data: testsCatalog } = useQuery('tests', getTest);
|
|
const { data: testsCatalog } = useQuery('tests', getTest);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+
|
|
|
if (visible == null) return;
|
|
if (visible == null) return;
|
|
|
let rest = new Service(`/plaza/getthis/${visible}`)
|
|
let rest = new Service(`/plaza/getthis/${visible}`)
|
|
|
rest
|
|
rest
|
|
|
.getQuery(auth.token)
|
|
.getQuery(auth.token)
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
- console.log('puesto edit: ',response.data)
|
|
|
|
|
- let { areadeptoplz_id, fecha, tests } = response.data;
|
|
|
|
|
|
|
+ let { areadeptoplz_id, fecha, tests, puestosuperior } = response.data;
|
|
|
let temp_test = tests.map(t => ({ id: t.id }))
|
|
let temp_test = tests.map(t => ({ id: t.id }))
|
|
|
setChecklist(temp_test.map(t => t.id))
|
|
setChecklist(temp_test.map(t => t.id))
|
|
|
|
|
+ console.log('puesto sup',puestosuperior)
|
|
|
|
|
+ reset({
|
|
|
|
|
+ ...response.data,
|
|
|
|
|
+ aredepto: areadeptoplz_id,
|
|
|
|
|
+ fecha: new Date(fecha),
|
|
|
|
|
+ tests: temp_test,
|
|
|
|
|
+ puestosuperior: puestosuperior.id
|
|
|
|
|
+ })
|
|
|
|
|
+ // setDialogValue({ title: puestosuperior.nombre, id: puestosuperior.id })
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(e => console.log(e))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ let active = true;
|
|
|
|
|
+ if (!loading) {
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ (async () => {
|
|
|
|
|
+ let puestos = await getPuestoSuperior(dialogValue.title, auth)
|
|
|
|
|
+ if (active) {
|
|
|
|
|
+ setOptions(puestos);
|
|
|
|
|
+ }
|
|
|
|
|
+ })();
|
|
|
|
|
+
|
|
|
|
|
+ return () => {
|
|
|
|
|
+ active = false;
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
|
|
|
- reset({ ...response.data, aredepto: areadeptoplz_id, fecha: new Date(fecha), tests: temp_test })
|
|
|
|
|
- })
|
|
|
|
|
- .catch(console.log)
|
|
|
|
|
- }, [visible, auth, reset])
|
|
|
|
|
|
|
+
|
|
|
|
|
+ }, [visible, auth, reset, loading, dialogValue])
|
|
|
|
|
|
|
|
const changeTab = (_event, newValue) => setTab(newValue);
|
|
const changeTab = (_event, newValue) => setTab(newValue);
|
|
|
|
|
|
|
@@ -193,30 +267,118 @@ function Edit(props) {
|
|
|
error={Boolean(errors?.nombrepuesto)}
|
|
error={Boolean(errors?.nombrepuesto)}
|
|
|
{...register("nombrepuesto")} />
|
|
{...register("nombrepuesto")} />
|
|
|
|
|
|
|
|
|
|
+
|
|
|
<FormControl fullWidth>
|
|
<FormControl fullWidth>
|
|
|
- <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
|
|
|
|
|
<Controller
|
|
<Controller
|
|
|
helperText={errors.puestosuperior?.message}
|
|
helperText={errors.puestosuperior?.message}
|
|
|
- error={Boolean(errors?.puestosuperior)}
|
|
|
|
|
|
|
+ error={errors?.puestosuperior}
|
|
|
name="puestosuperior"
|
|
name="puestosuperior"
|
|
|
control={control}
|
|
control={control}
|
|
|
- render={({field}) =>
|
|
|
|
|
- <Select {...field}>
|
|
|
|
|
- {
|
|
|
|
|
- categories ?
|
|
|
|
|
- categories.data.map(cate => {
|
|
|
|
|
- return (
|
|
|
|
|
- <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
- : <MenuItem>Null</MenuItem>
|
|
|
|
|
- }
|
|
|
|
|
- </Select>
|
|
|
|
|
|
|
+ render={({ field }) =>
|
|
|
|
|
+ <Autocomplete
|
|
|
|
|
+ fullWidth
|
|
|
|
|
+ value={dialogValue}
|
|
|
|
|
+ onChange={AutoCompleteChange}
|
|
|
|
|
+ open={openSugg}
|
|
|
|
|
+ onOpen={() => {
|
|
|
|
|
+ setOpenSugg(true);
|
|
|
|
|
+ }}
|
|
|
|
|
+ onClose={() => {
|
|
|
|
|
+ setOpenSugg(false);
|
|
|
|
|
+ }}
|
|
|
|
|
+ isOptionEqualToValue={(option, value) => option.title === value.title}
|
|
|
|
|
+ filterOptions={(options, params) => {
|
|
|
|
|
+ const filtered = filter(options, params);
|
|
|
|
|
+
|
|
|
|
|
+ if (params.inputValue !== '') {
|
|
|
|
|
+ filtered.push({
|
|
|
|
|
+ inputValue: params.inputValue,
|
|
|
|
|
+ title: `Add "${params.inputValue}"`,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return filtered;
|
|
|
|
|
+ }}
|
|
|
|
|
+ id="puesto_superior_autocomplete"
|
|
|
|
|
+ options={options}
|
|
|
|
|
+ loading={loading}
|
|
|
|
|
+ getOptionLabel={(option) => {
|
|
|
|
|
+ if (typeof option === 'string') {
|
|
|
|
|
+ return option;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (option.inputValue) {
|
|
|
|
|
+ return option.inputValue;
|
|
|
|
|
+ }
|
|
|
|
|
+ return option.title;
|
|
|
|
|
+ }}
|
|
|
|
|
+ selectOnFocus
|
|
|
|
|
+ clearOnBlur
|
|
|
|
|
+ handleHomeEndKeys
|
|
|
|
|
+ renderOption={(props, option) => <li {...props}>{option.title}</li>}
|
|
|
|
|
+ freeSolo
|
|
|
|
|
+ renderInput={(params) => (
|
|
|
|
|
+ <TextField
|
|
|
|
|
+ {...params}
|
|
|
|
|
+ {...register('puestosuperior')}
|
|
|
|
|
+ error={Boolean(errors.puestosuperior)}
|
|
|
|
|
+ label="Puesto Superior"
|
|
|
|
|
+ InputProps={{
|
|
|
|
|
+ ...params.InputProps,
|
|
|
|
|
+ onChange: (event) => {
|
|
|
|
|
+ // let title = event.target.value;
|
|
|
|
|
+ // console.log('titulo',title)
|
|
|
|
|
+ setOptions([]);
|
|
|
|
|
+ setDialogValue({
|
|
|
|
|
+ title: event.target.value,
|
|
|
|
|
+ id: '',
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ endAdornment: (
|
|
|
|
|
+ <React.Fragment>
|
|
|
|
|
+ {loading ? <CircularProgress color="inherit" size={20} /> : null}
|
|
|
|
|
+ {params.InputProps.endAdornment}
|
|
|
|
|
+ </React.Fragment>
|
|
|
|
|
+ ),
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ )}
|
|
|
|
|
+
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- >
|
|
|
|
|
-
|
|
|
|
|
|
|
+ >
|
|
|
</Controller>
|
|
</Controller>
|
|
|
</FormControl>
|
|
</FormControl>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ /* <FormControl fullWidth>
|
|
|
|
|
+ <InputLabel id="demo-simple-select-label">Puesto Superior</InputLabel>
|
|
|
|
|
+ <Controller
|
|
|
|
|
+ helperText={errors.puestosuperior?.message}
|
|
|
|
|
+ error={Boolean(errors?.puestosuperior)}
|
|
|
|
|
+ name="puestosuperior"
|
|
|
|
|
+ control={control}
|
|
|
|
|
+ render={({field}) =>
|
|
|
|
|
+ <Select {...field}>
|
|
|
|
|
+ {
|
|
|
|
|
+ categories ?
|
|
|
|
|
+ categories.data.map(cate => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ : <MenuItem>Null</MenuItem>
|
|
|
|
|
+ }
|
|
|
|
|
+ </Select>
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+
|
|
|
|
|
+ </Controller>
|
|
|
|
|
+ </FormControl> */
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
</Stack>
|
|
</Stack>
|
|
|
|
|
|
|
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
|