Przeglądaj źródła

add tests in puesto

amenpunk 3 lat temu
rodzic
commit
0115ae940f
1 zmienionych plików z 26 dodań i 6 usunięć
  1. 26 6
      src/Components/Modal/AgregarManual.js

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

@@ -43,6 +43,7 @@ function Manual(props) {
         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, "Ingresa una nota válida").max(150),
+        pruebas: Yup.array()
     })
 
     const [departamento, setDepartamento] = React.useState('');
@@ -72,6 +73,7 @@ function Manual(props) {
             aredepto: 1,
             fecha: date,
             notas: "",
+            pruebas:[]
         },
         onSubmit: (fields, { resetForm }) => {
 
@@ -100,8 +102,20 @@ function Manual(props) {
     const changeTab = (_event, newValue) => {
         setTab(newValue);
     };
-
-    const { errors, touched, handleSubmit, getFieldProps } = formik;
+    
+
+    const { errors, touched, handleSubmit, getFieldProps, values, setValues } = formik;
+
+    const addPrueba = (check,id) => {
+        let { pruebas } = values
+        let temp ;
+        if(check){
+            temp = [...pruebas, {id}]
+        }else{
+            temp = pruebas.filter((test) => test.id !== id);
+        }
+        setValues({...values, pruebas: temp})
+    };
 
     return (
 
@@ -109,7 +123,7 @@ function Manual(props) {
 
             <Modal.Header>
                 <button onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
-                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar plaza</h4>
+                <h4 className="modal-title" style={{ color: '#252525' }}>Agregar Puesto</h4>
             </Modal.Header>
             <Modal.Body className="modal-body">
 
@@ -118,8 +132,6 @@ function Manual(props) {
                     <Tab label="Pruebas" />
                 </Tabs>
 
-
-
                 <FormikProvider style={{ paddingTop: 25 }} value={formik}>
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
 
@@ -133,7 +145,15 @@ function Manual(props) {
                                         {
                                             tests ?
                                             tests.data.map( test => (
-                                                <FormControlLabel control={<Checkbox defaultChecked />} label={test.nombre} />
+                                                <FormControlLabel 
+                                                    key={test.id}
+                                                    control={
+                                                        <Checkbox 
+                                                            onChange={(event)=> addPrueba(event.target.checked,test.id)}
+                                                        />
+                                                    } 
+                                                    label={test.nombre} 
+                                                    />
                                             )): null
                                         }
                                     </FormGroup>