浏览代码

using namespace std

amenpunk 2 年之前
父节点
当前提交
d31303dd73
共有 3 个文件被更改,包括 29 次插入20 次删除
  1. 25 17
      src/Components/Modal/EditPlaza.js
  2. 1 1
      src/Pages/Puestos.jsx
  3. 3 2
      src/temp.js

+ 25 - 17
src/Components/Modal/EditPlaza.js

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

+ 1 - 1
src/Pages/Puestos.jsx

69
   let [show, setShow] = React.useState(null);
69
   let [show, setShow] = React.useState(null);
70
 
70
 
71
   const toggle = useCallback((type, puesto) => {
71
   const toggle = useCallback((type, puesto) => {
72
-    console.log('usecall: ',puesto)
72
+   // console.log('usecall: ',puesto)
73
     // setPuesto(puesto)
73
     // setPuesto(puesto)
74
     switch (type) {
74
     switch (type) {
75
       case "VER": {
75
       case "VER": {

+ 3 - 2
src/temp.js

36
 
36
 
37
 function Edit(props) {
37
 function Edit(props) {
38
 
38
 
39
-  const { control,register, handleSubmit, watch, formState: { errors } } = useForm({
39
+  const { getValues ,control,register, handleSubmit, watch, formState: { errors } } = useForm({
40
     defaultValues: {
40
     defaultValues: {
41
       departamento: 1,
41
       departamento: 1,
42
     }
42
     }
64
   const [checklist, setChecklist] = React.useState([]);
64
   const [checklist, setChecklist] = React.useState([]);
65
 
65
 
66
   const addPrueba = (check,id) => {
66
   const addPrueba = (check,id) => {
67
-    let { tests } = { tests : []}
67
+    let { tests } = getValues("tests")
68
+    console.log(tests);
68
     let temp ;
69
     let temp ;
69
     if(check){
70
     if(check){
70
       temp = [...tests, {id}]
71
       temp = [...tests, {id}]