|
@@ -27,17 +27,16 @@ const plazeSchema = Yup.object({
|
27
|
27
|
.min(5, "El nombre del puesto debe ser mayor a 5 caracteres")
|
28
|
28
|
.max(100),
|
29
|
29
|
puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
|
30
|
|
- aredepto: Yup.number().required('Escoge alguna área'),
|
31
|
|
- fecha: Yup.date("Ingresa una fecha válida"),
|
32
|
|
- notas: Yup.string("Ingresa una nota válida").min(5).max(150),
|
|
30
|
+ aredepto: Yup.number('El área debe ser un número').required('Escoge alguna área'),
|
|
31
|
+ fecha: Yup.date("Ingresa una fecha válida").required(),
|
|
32
|
+ 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"),
|
33
|
33
|
tests: Yup.array()
|
34
|
34
|
}).required();
|
35
|
35
|
|
36
|
36
|
|
37
|
37
|
function Edit(props) {
|
38
|
38
|
|
39
|
|
- const {
|
40
|
|
- reset,control,register, handleSubmit, formState: { errors } } = useForm({
|
|
39
|
+ const { setValue,getValues,reset,control,register, handleSubmit, formState: { errors } } = useForm({
|
41
|
40
|
resolver : yupResolver(plazeSchema),
|
42
|
41
|
defaultValues: {
|
43
|
42
|
nombrepuesto: 'mingtest',
|
|
@@ -45,6 +44,7 @@ function Edit(props) {
|
45
|
44
|
fecha: '01/01/2019',
|
46
|
45
|
notas: 'esto es un ejemplod e una nota',
|
47
|
46
|
aredepto : 1,
|
|
47
|
+ tests : []
|
48
|
48
|
}
|
49
|
49
|
});
|
50
|
50
|
|
|
@@ -62,7 +62,8 @@ function Edit(props) {
|
62
|
62
|
const [checklist, setChecklist] = React.useState([]);
|
63
|
63
|
|
64
|
64
|
const addPrueba = (check,id) => {
|
65
|
|
- let { tests } = { tests : []}
|
|
65
|
+ let tests = getValues("tests")
|
|
66
|
+ console.log(tests)
|
66
|
67
|
let temp ;
|
67
|
68
|
if(check){
|
68
|
69
|
temp = [...tests, {id}]
|
|
@@ -70,7 +71,8 @@ function Edit(props) {
|
70
|
71
|
temp = tests.filter( test => test.id !== id);
|
71
|
72
|
}
|
72
|
73
|
setChecklist(temp.map( test => test.id) )
|
73
|
|
- // setValues({...values, tests: temp})
|
|
74
|
+ setValue('tests', temp)
|
|
75
|
+ // setValue({...values, tests: temp})
|
74
|
76
|
};
|
75
|
77
|
|
76
|
78
|
const getCategories = async () => {
|
|
@@ -101,17 +103,16 @@ function Edit(props) {
|
101
|
103
|
rest
|
102
|
104
|
.getQuery(auth.token)
|
103
|
105
|
.then( response => {
|
104
|
|
- let { areadeptoplz_id, fecha } = response.data;
|
105
|
|
- reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) })
|
|
106
|
+ console.log(response.data)
|
|
107
|
+ let { areadeptoplz_id, fecha, tests } = response.data;
|
|
108
|
+ let temp_test = tests.map( t => ({ id : t.id} ))
|
|
109
|
+ setChecklist(temp_test.map( t => t.id))
|
|
110
|
+ reset({...response.data, areadepto : areadeptoplz_id, fecha : new Date(fecha) , tests : temp_test })
|
106
|
111
|
})
|
107
|
112
|
.catch(console.log)
|
108
|
113
|
},[visible])
|
109
|
114
|
|
110
|
|
- console.log("RENDER", props)
|
111
|
|
-
|
112
|
|
- const changeTab = (_event, newValue) => {
|
113
|
|
- setTab(newValue);
|
114
|
|
- };
|
|
115
|
+ const changeTab = (_event, newValue) => setTab(newValue);
|
115
|
116
|
|
116
|
117
|
return (
|
117
|
118
|
|
|
@@ -170,6 +171,8 @@ function Edit(props) {
|
170
|
171
|
name="puestosuperior"
|
171
|
172
|
label="Puesto superior"
|
172
|
173
|
fullWidth
|
|
174
|
+ helperText={errors.puestosuperior?.message}
|
|
175
|
+ error={Boolean(errors?.puestosuperior)}
|
173
|
176
|
{...register("puestosuperior")} />
|
174
|
177
|
|
175
|
178
|
</Stack>
|
|
@@ -179,6 +182,8 @@ function Edit(props) {
|
179
|
182
|
<FormControl fullWidth>
|
180
|
183
|
<InputLabel>Departamento</InputLabel>
|
181
|
184
|
<Controller
|
|
185
|
+ helperText={errors.areadepto?.message}
|
|
186
|
+ error={Boolean(errors?.areadepto)}
|
182
|
187
|
name="aredepto"
|
183
|
188
|
control={control}
|
184
|
189
|
render={ ({field}) =>
|
|
@@ -204,18 +209,21 @@ function Edit(props) {
|
204
|
209
|
render={({field}) =>
|
205
|
210
|
<DesktopDatePicker
|
206
|
211
|
{...field}
|
|
212
|
+ helperText={errors.fecha?.message}
|
|
213
|
+ error={Boolean(errors?.fecha)}
|
207
|
214
|
label="Fecha Creación"
|
208
|
215
|
fullWidth
|
209
|
216
|
inputFormat="dd/MM/yyyy"
|
210
|
|
- renderInput={(params) => <TextField {...params} />}
|
211
|
|
- />
|
212
|
|
- } >
|
|
217
|
+ renderInput={(params) => <TextField {...params} helperText={errors.fecha?.message} />} /> }
|
|
218
|
+ >
|
213
|
219
|
</Controller>
|
214
|
220
|
</LocalizationProvider>
|
215
|
221
|
</Stack>
|
216
|
222
|
|
217
|
223
|
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>
|
218
|
224
|
<TextField
|
|
225
|
+ helperText={errors.notas?.message}
|
|
226
|
+ error={Boolean(errors?.notas)}
|
219
|
227
|
name="notas"
|
220
|
228
|
multiline
|
221
|
229
|
rows={4}
|