|
@@ -70,18 +70,7 @@ const plazeSchema = Yup.object({
|
|
|
|
|
|
|
|
function Edit(props) {
|
|
function Edit(props) {
|
|
|
|
|
|
|
|
- // const { resetField, setFocus, setValue, getValues, reset, control, register, handleSubmit, formState: { errors } } = useForm({
|
|
|
|
|
- // resolver: yupResolver(plazeSchema),
|
|
|
|
|
- // defaultValues: {
|
|
|
|
|
- // id: 0,
|
|
|
|
|
- // nombrepuesto: 'mingtest',
|
|
|
|
|
- // puestosuperior: 0,
|
|
|
|
|
- // fecha: '01/01/2019',
|
|
|
|
|
- // notas: 'esto es un ejemplod e una nota',
|
|
|
|
|
- // aredepto: 1,
|
|
|
|
|
- // tests: []
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+ const [date, setDate] = React.useState(new Date());
|
|
|
|
|
|
|
|
const formik = useFormik({
|
|
const formik = useFormik({
|
|
|
initialValues: {
|
|
initialValues: {
|
|
@@ -89,7 +78,7 @@ function Edit(props) {
|
|
|
nombrepuesto: "",
|
|
nombrepuesto: "",
|
|
|
puestosuperior: 0,
|
|
puestosuperior: 0,
|
|
|
aredepto: 1,
|
|
aredepto: 1,
|
|
|
- fecha: '01/01/2019',
|
|
|
|
|
|
|
+ fecha: date,
|
|
|
notas: "",
|
|
notas: "",
|
|
|
tests: []
|
|
tests: []
|
|
|
},
|
|
},
|
|
@@ -118,8 +107,6 @@ function Edit(props) {
|
|
|
queryClient.invalidateQueries('puestos')
|
|
queryClient.invalidateQueries('puestos')
|
|
|
},
|
|
},
|
|
|
onError: () => {
|
|
onError: () => {
|
|
|
- //close();
|
|
|
|
|
- //setOpen(false)
|
|
|
|
|
toast.error("Lo sentimos ocurrió error inténtalo más tarde")
|
|
toast.error("Lo sentimos ocurrió error inténtalo más tarde")
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -149,7 +136,7 @@ function Edit(props) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleSubmitDialog = async (event) => {
|
|
const handleSubmitDialog = async (event) => {
|
|
|
- console.log('handlesubmit', dialogValue)
|
|
|
|
|
|
|
+ // console.log('handlesubmit', dialogValue)
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
|
let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
|
|
let { id, nombre } = await savePuestoSuperior(dialogValue, auth)
|
|
|
if (id) {
|
|
if (id) {
|
|
@@ -158,43 +145,22 @@ function Edit(props) {
|
|
|
id: id,
|
|
id: id,
|
|
|
}
|
|
}
|
|
|
if (to_set.id) {
|
|
if (to_set.id) {
|
|
|
- console.log("TO SET", to_set)
|
|
|
|
|
|
|
+ // console.log("TO SET", to_set)
|
|
|
setDialogValue(to_set);
|
|
setDialogValue(to_set);
|
|
|
- // reset({ ...getValues(),puestosuperior: to_set.id })
|
|
|
|
|
|
|
+ setValues({...values, puestosuperior: to_set.id})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
handleCloseDialog();
|
|
handleCloseDialog();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let setDialogValue = useCallback((value) => {
|
|
let setDialogValue = useCallback((value) => {
|
|
|
- console.log('value receivied', value)
|
|
|
|
|
|
|
+ // console.log('value receivied', value)
|
|
|
let id = value?.id || 0;
|
|
let id = value?.id || 0;
|
|
|
if (id !== 0) {
|
|
if (id !== 0) {
|
|
|
console.log('setting value', id)
|
|
console.log('setting value', id)
|
|
|
- // let temp = getValues();
|
|
|
|
|
- // temp['puestosuperior'] = id
|
|
|
|
|
- // temp['puestosuperior_id'] = id
|
|
|
|
|
- // reset({ ...temp, puestosuperior: id }, { keepDefaultValues: false, })
|
|
|
|
|
- // setDialogValueHook(value)
|
|
|
|
|
- // setValue('puestosuperior', parseInt(id))
|
|
|
|
|
- // resetField('puestosuperior')
|
|
|
|
|
- // let a = puestoref.current;
|
|
|
|
|
- // a.focus();
|
|
|
|
|
- // console.log(a)
|
|
|
|
|
- // setValue('puestosuperior', id)
|
|
|
|
|
- // reset({ ...temp, puestosuperior_id: id, puestosuperior: id }, {
|
|
|
|
|
- // keepErrors: true ,
|
|
|
|
|
- // keepDirty: true,
|
|
|
|
|
- // keepIsSubmitted: true,
|
|
|
|
|
- // keepTouched: true,
|
|
|
|
|
- // })
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- // setFocus("puestosuperior_id",{shouldSelect:true})
|
|
|
|
|
- // console.log('SETTING:', value)
|
|
|
|
|
- // console.log("final", getValues())
|
|
|
|
|
setDialogValueHook(value)
|
|
setDialogValueHook(value)
|
|
|
-
|
|
|
|
|
}, [])
|
|
}, [])
|
|
|
|
|
|
|
|
const changeDepartamento = (event) => {
|
|
const changeDepartamento = (event) => {
|
|
@@ -204,18 +170,10 @@ function Edit(props) {
|
|
|
const loading = openSugg && options.length === 0;
|
|
const loading = openSugg && options.length === 0;
|
|
|
|
|
|
|
|
const AutoCompleteChange = (event, newValue) => {
|
|
const AutoCompleteChange = (event, newValue) => {
|
|
|
- // let temp = getValues();
|
|
|
|
|
- // console.log('newValue', temp, newValue)
|
|
|
|
|
- // temp['puestosuperior'] = newValue?.id;
|
|
|
|
|
- // reset(temp)
|
|
|
|
|
- // setDialogValue(newValue);
|
|
|
|
|
- // return;
|
|
|
|
|
- //this should be change
|
|
|
|
|
- // setValue('puestosuperior', newValue?.id)
|
|
|
|
|
setValues({ ...values, puestosuperior: newValue?.id })
|
|
setValues({ ...values, puestosuperior: newValue?.id })
|
|
|
|
|
|
|
|
if (typeof newValue === 'string') {
|
|
if (typeof newValue === 'string') {
|
|
|
- console.log('if1')
|
|
|
|
|
|
|
+ // console.log('if1')
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
toggleOpenDialog(true);
|
|
toggleOpenDialog(true);
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
@@ -224,14 +182,14 @@ function Edit(props) {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
} else if (newValue && newValue.inputValue) {
|
|
} else if (newValue && newValue.inputValue) {
|
|
|
- console.log('if2')
|
|
|
|
|
|
|
+ // console.log('if2')
|
|
|
toggleOpenDialog(true);
|
|
toggleOpenDialog(true);
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
|
title: newValue.inputValue,
|
|
title: newValue.inputValue,
|
|
|
id: '',
|
|
id: '',
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- console.log('if3')
|
|
|
|
|
|
|
+ // console.log('if3')
|
|
|
setDialogValue(newValue);
|
|
setDialogValue(newValue);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -281,10 +239,11 @@ function Edit(props) {
|
|
|
rest
|
|
rest
|
|
|
.getQuery(auth.token)
|
|
.getQuery(auth.token)
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
|
|
+ console.log('plz to edit: ', response.data)
|
|
|
let { areadeptoplz_id, fecha, tests, puestosuperior } = 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)
|
|
|
|
|
|
|
+ // console.log('puesto sup', puestosuperior)
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
|
title: puestosuperior.nombre,
|
|
title: puestosuperior.nombre,
|
|
|
id: puestosuperior.id
|
|
id: puestosuperior.id
|
|
@@ -350,7 +309,7 @@ function Edit(props) {
|
|
|
id="name"
|
|
id="name"
|
|
|
value={dialogValue?.title}
|
|
value={dialogValue?.title}
|
|
|
onChange={(event) => {
|
|
onChange={(event) => {
|
|
|
- console.log('aa', event.target.value)
|
|
|
|
|
|
|
+ // console.log('aa', event.target.value)
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
|
...dialogValue,
|
|
...dialogValue,
|
|
|
title: event.target.value,
|
|
title: event.target.value,
|
|
@@ -367,7 +326,7 @@ function Edit(props) {
|
|
|
id="name"
|
|
id="name"
|
|
|
value={dialogValue?.id}
|
|
value={dialogValue?.id}
|
|
|
onChange={(event) => {
|
|
onChange={(event) => {
|
|
|
- console.log('ev', event.target.value)
|
|
|
|
|
|
|
+ // console.log('ev', event.target.value)
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
|
...dialogValue,
|
|
...dialogValue,
|
|
|
id: event.target.value,
|
|
id: event.target.value,
|
|
@@ -479,7 +438,7 @@ function Edit(props) {
|
|
|
...params.InputProps,
|
|
...params.InputProps,
|
|
|
onChange: (event) => {
|
|
onChange: (event) => {
|
|
|
let title = event.target.value;
|
|
let title = event.target.value;
|
|
|
- console.log('titulo', title)
|
|
|
|
|
|
|
+ // console.log('titulo', title)
|
|
|
setOptions([]);
|
|
setOptions([]);
|
|
|
setDialogValue({
|
|
setDialogValue({
|
|
|
title: title,
|
|
title: title,
|
|
@@ -525,12 +484,21 @@ function Edit(props) {
|
|
|
|
|
|
|
|
<LocalizationProvider dateAdapter={DateFnsUtils}>
|
|
<LocalizationProvider dateAdapter={DateFnsUtils}>
|
|
|
<DesktopDatePicker
|
|
<DesktopDatePicker
|
|
|
|
|
+ {...getFieldProps('fecha')}
|
|
|
helperText={errors.fecha?.message}
|
|
helperText={errors.fecha?.message}
|
|
|
error={Boolean(errors?.fecha)}
|
|
error={Boolean(errors?.fecha)}
|
|
|
label="Fecha Creación"
|
|
label="Fecha Creación"
|
|
|
fullWidth
|
|
fullWidth
|
|
|
|
|
+ value={date}
|
|
|
|
|
+ onChange={setDate}
|
|
|
inputFormat="dd/MM/yyyy"
|
|
inputFormat="dd/MM/yyyy"
|
|
|
- renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />}
|
|
|
|
|
|
|
+ renderInput={ (params) =>
|
|
|
|
|
+ <TextField
|
|
|
|
|
+ disabled={true}
|
|
|
|
|
+ {...params}
|
|
|
|
|
+ helperText={errors.fecha?.message}
|
|
|
|
|
+ />
|
|
|
|
|
+ }
|
|
|
/>
|
|
/>
|
|
|
</LocalizationProvider>
|
|
</LocalizationProvider>
|
|
|
</Stack>
|
|
</Stack>
|