|
@@ -27,17 +27,16 @@ const plazeSchema = Yup.object({
|
|
|
.min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
|
.min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
|
|
.max(100),
|
|
.max(100),
|
|
|
puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
|
puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
|
|
- aredepto: Yup.number().required('Escoge alguna área'),
|
|
|
|
|
- fecha: Yup.date("Ingresa una fecha válida"),
|
|
|
|
|
- notas: Yup.string("Ingresa una nota válida").min(5).max(150),
|
|
|
|
|
|
|
+ aredepto: Yup.number('El área debe ser un número').required('Escoge alguna área'),
|
|
|
|
|
+ fecha: Yup.date("Ingresa una fecha válida").required(),
|
|
|
|
|
+ notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota mayor a 5").max(150, "Ingresa una nota menor a 150 caracteres"),
|
|
|
tests: Yup.array()
|
|
tests: Yup.array()
|
|
|
}).required();
|
|
}).required();
|
|
|
|
|
|
|
|
|
|
|
|
|
function Edit(props) {
|
|
function Edit(props) {
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- reset,control,register, handleSubmit, formState: { errors } } = useForm({
|
|
|
|
|
|
|
+ const { setValue,getValues,reset,control,register, handleSubmit, formState: { errors } } = useForm({
|
|
|
resolver : yupResolver(plazeSchema),
|
|
resolver : yupResolver(plazeSchema),
|
|
|
defaultValues: {
|
|
defaultValues: {
|
|
|
nombrepuesto: 'mingtest',
|
|
nombrepuesto: 'mingtest',
|
|
@@ -45,6 +44,7 @@ function Edit(props) {
|
|
|
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,
|
|
|
|
|
+ tests : []
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -62,7 +62,8 @@ function Edit(props) {
|
|
|
const [checklist, setChecklist] = React.useState([]);
|
|
const [checklist, setChecklist] = React.useState([]);
|
|
|
|
|
|
|
|
const addPrueba = (check,id) => {
|
|
const addPrueba = (check,id) => {
|
|
|
- let { tests } = { tests : []}
|
|
|
|
|
|
|
+ let tests = getValues("tests")
|
|
|
|
|
+ console.log(tests)
|
|
|
let temp ;
|
|
let temp ;
|
|
|
if(check){
|
|
if(check){
|
|
|
temp = [...tests, {id}]
|
|
temp = [...tests, {id}]
|
|
@@ -70,7 +71,8 @@ function Edit(props) {
|
|
|
temp = tests.filter( test => test.id !== id);
|
|
temp = tests.filter( test => test.id !== id);
|
|
|
}
|
|
}
|
|
|
setChecklist(temp.map( test => test.id) )
|
|
setChecklist(temp.map( test => test.id) )
|
|
|
- // setValues({...values, tests: temp})
|
|
|
|
|
|
|
+ setValue('tests', temp)
|
|
|
|
|
+ // setValue({...values, tests: temp})
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const getCategories = async () => {
|
|
const getCategories = async () => {
|
|
@@ -101,17 +103,16 @@ function Edit(props) {
|
|
|
rest
|
|
rest
|
|
|
.getQuery(auth.token)
|
|
.getQuery(auth.token)
|
|
|
.then( response => {
|
|
.then( response => {
|
|
|
- let { areadeptoplz_id, fecha } = response.data;
|
|
|
|
|
- reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) })
|
|
|
|
|
|
|
+ console.log(response.data)
|
|
|
|
|
+ let { areadeptoplz_id, fecha, tests } = response.data;
|
|
|
|
|
+ let temp_test = tests.map( t => ({ id : t.id} ))
|
|
|
|
|
+ setChecklist(temp_test.map( t => t.id))
|
|
|
|
|
+ reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test })
|
|
|
})
|
|
})
|
|
|
.catch(console.log)
|
|
.catch(console.log)
|
|
|
},[visible])
|
|
},[visible])
|
|
|
|
|
|
|
|
- console.log("RENDER", props)
|
|
|
|
|
-
|
|
|
|
|
- const changeTab = (_event, newValue) => {
|
|
|
|
|
- setTab(newValue);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const changeTab = (_event, newValue) => setTab(newValue);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
|
|
|
|
@@ -170,6 +171,8 @@ function Edit(props) {
|
|
|
name="puestosuperior"
|
|
name="puestosuperior"
|
|
|
label="Puesto superior"
|
|
label="Puesto superior"
|
|
|
fullWidth
|
|
fullWidth
|
|
|
|
|
+ helperText={errors.puestosuperior?.message}
|
|
|
|
|
+ error={Boolean(errors?.puestosuperior)}
|
|
|
{...register("puestosuperior")} />
|
|
{...register("puestosuperior")} />
|
|
|
|
|
|
|
|
</Stack>
|
|
</Stack>
|
|
@@ -179,6 +182,8 @@ function Edit(props) {
|
|
|
<FormControl fullWidth>
|
|
<FormControl fullWidth>
|
|
|
<InputLabel>Departamento</InputLabel>
|
|
<InputLabel>Departamento</InputLabel>
|
|
|
<Controller
|
|
<Controller
|
|
|
|
|
+ helperText={errors.areadepto?.message}
|
|
|
|
|
+ error={Boolean(errors?.areadepto)}
|
|
|
name="aredepto"
|
|
name="aredepto"
|
|
|
control={control}
|
|
control={control}
|
|
|
render={ ({field}) =>
|
|
render={ ({field}) =>
|
|
@@ -204,18 +209,21 @@ function Edit(props) {
|
|
|
render={({field}) =>
|
|
render={({field}) =>
|
|
|
<DesktopDatePicker
|
|
<DesktopDatePicker
|
|
|
{...field}
|
|
{...field}
|
|
|
|
|
+ helperText={errors.fecha?.message}
|
|
|
|
|
+ error={Boolean(errors?.fecha)}
|
|
|
label="Fecha Creación"
|
|
label="Fecha Creación"
|
|
|
fullWidth
|
|
fullWidth
|
|
|
inputFormat="dd/MM/yyyy"
|
|
inputFormat="dd/MM/yyyy"
|
|
|
- renderInput={(params) => <TextField {...params} />}
|
|
|
|
|
- />
|
|
|
|
|
- } >
|
|
|
|
|
|
|
+ renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} /> }
|
|
|
|
|
+ >
|
|
|
</Controller>
|
|
</Controller>
|
|
|
</LocalizationProvider>
|
|
</LocalizationProvider>
|
|
|
</Stack>
|
|
</Stack>
|
|
|
|
|
|
|
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
|
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
|
|
|
<TextField
|
|
<TextField
|
|
|
|
|
+ helperText={errors.notas?.message}
|
|
|
|
|
+ error={Boolean(errors?.notas)}
|
|
|
name="notas"
|
|
name="notas"
|
|
|
multiline
|
|
multiline
|
|
|
rows={4}
|
|
rows={4}
|