瀏覽代碼

add tests in puesto

amenpunk 3 年之前
父節點
當前提交
0115ae940f
共有 1 個文件被更改,包括 26 次插入6 次删除
  1. 26 6
      src/Components/Modal/AgregarManual.js

+ 26 - 6
src/Components/Modal/AgregarManual.js

43
         aredepto: Yup.number().required('Escoge alguna área'),
43
         aredepto: Yup.number().required('Escoge alguna área'),
44
         fecha: Yup.date("Ingresa una fecha válida"),
44
         fecha: Yup.date("Ingresa una fecha válida"),
45
         notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
45
         notas: Yup.string("Ingresa una nota válida").min(5, "Ingresa una nota válida").max(150),
46
+        pruebas: Yup.array()
46
     })
47
     })
47
 
48
 
48
     const [departamento, setDepartamento] = React.useState('');
49
     const [departamento, setDepartamento] = React.useState('');
72
             aredepto: 1,
73
             aredepto: 1,
73
             fecha: date,
74
             fecha: date,
74
             notas: "",
75
             notas: "",
76
+            pruebas:[]
75
         },
77
         },
76
         onSubmit: (fields, { resetForm }) => {
78
         onSubmit: (fields, { resetForm }) => {
77
 
79
 
100
     const changeTab = (_event, newValue) => {
102
     const changeTab = (_event, newValue) => {
101
         setTab(newValue);
103
         setTab(newValue);
102
     };
104
     };
103
-
104
-    const { errors, touched, handleSubmit, getFieldProps } = formik;
105
+    
106
+
107
+    const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
108
+
109
+    const addPrueba = (check,id) => {
110
+        let { pruebas } = values
111
+        let temp ;
112
+        if(check){
113
+            temp = [...pruebas, {id}]
114
+        }else{
115
+            temp = pruebas.filter((test) => test.id !== id);
116
+        }
117
+        setValues({...values, pruebas: temp})
118
+    };
105
 
119
 
106
     return (
120
     return (
107
 
121
 
109
 
123
 
110
             <Modal.Header>
124
             <Modal.Header>
111
                 <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
125
                 <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
112
-                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar plaza</h4>
126
+                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
113
             </Modal.Header>
127
             </Modal.Header>
114
             <Modal.Body className="modal-body">
128
             <Modal.Body className="modal-body">
115
 
129
 
118
                     <Tab label="Pruebas" />
132
                     <Tab label="Pruebas" />
119
                 </Tabs>
133
                 </Tabs>
120
 
134
 
121
-
122
-
123
                 <FormikProvider style={{ paddingTop: 25 }} value={formik}>
135
                 <FormikProvider style={{ paddingTop: 25 }} value={formik}>
124
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
136
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
125
 
137
 
133
                                         {
145
                                         {
134
                                             tests ?
146
                                             tests ?
135
                                             tests.data.map( test => (
147
                                             tests.data.map( test => (
136
-                                                <FormControlLabel control={<Checkbox defaultChecked />} label={test.nombre} />
148
+                                                <FormControlLabel 
149
+                                                    key={test.id}
150
+                                                    control={
151
+                                                        <Checkbox 
152
+                                                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
153
+                                                        />
154
+                                                    } 
155
+                                                    label={test.nombre} 
156
+                                                    />
137
                                             )): null
157
                                             )): null
138
                                         }
158
                                         }
139
                                     </FormGroup>
159
                                     </FormGroup>