Browse Source

step one validation and submit

amenpunk 3 years ago
parent
commit
0cc7e4dc41

+ 24 - 33
src/Components/Modal/PasswordModal.jsx

8
 
8
 
9
 import { StepOne } from '../Password/Steps/one'
9
 import { StepOne } from '../Password/Steps/one'
10
 
10
 
11
-const steps = [
12
-    {
13
-        label : 'Información del candidato',
14
-        operation: <StepOne/>
15
-    },
16
-    {
17
-        label : 'Seleccionar plaza',
18
-        operation: <h1>plaza</h1>
19
-    },
20
-    {
21
-        label : 'Seleccionar pruebas',
22
-        operation: <h1>preubas</h1>
23
-    },
24
-    {
25
-        label : 'Confirmar',
26
-        operation: <h1>adios</h1>
27
-    },
28
-];
29
 
11
 
30
 export function HelpModal (props) {
12
 export function HelpModal (props) {
31
 
13
 
58
     };
40
     };
59
 
41
 
60
 
42
 
43
+    const steps = [
44
+        {
45
+            label : 'Información del candidato',
46
+            operation: 
47
+                <StepOne 
48
+                    handleNext={handleNext} 
49
+                    handleBack={handleBack} 
50
+                />
51
+        },
52
+        {
53
+            label : 'Seleccionar plaza',
54
+            operation: <h1>plaza</h1>
55
+        },
56
+        {
57
+            label : 'Seleccionar pruebas',
58
+            operation: <h1>preubas</h1>
59
+        },
60
+        {
61
+            label : 'Confirmar',
62
+            operation: <h1>adios</h1>
63
+        },
64
+    ];
65
+
66
+
61
     return (
67
     return (
62
         <Modal size="lg" 
68
         <Modal size="lg" 
63
             aria-labelledby="contained-modal-title-vcenter" 
69
             aria-labelledby="contained-modal-title-vcenter" 
102
                                     {steps[activeStep].operation}
108
                                     {steps[activeStep].operation}
103
                                 </Box>
109
                                 </Box>
104
 
110
 
105
-                                <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
106
-                                    <Button
107
-                                        color="inherit"
108
-                                        disabled={activeStep === 0}
109
-                                        onClick={handleBack}
110
-                                        sx={{ mr: 1 }}
111
-                                    >
112
-                                        Anterior
113
-                                    </Button>
114
-                                    <Box sx={{ flex: '1 1 auto' }} />
115
-                                    <Button onClick={handleNext}>
116
-                                        {activeStep === steps.length - 1 ? 'Guardar' : 'Siguiente'}
117
-                                    </Button>
118
-                                </Box>
119
-
120
                             </React.Fragment>
111
                             </React.Fragment>
121
                         )}
112
                         )}
122
                 </Box>
113
                 </Box>

+ 12 - 0
src/Components/Password/Rows.js

54
         label: 'Operacion',
54
         label: 'Operacion',
55
     },
55
     },
56
 ]
56
 ]
57
+export const niveles_educativos = [
58
+    "Primaria",
59
+    "Basico",
60
+    "Diversificado",
61
+    "Tecnico",
62
+    "Pregrado / Licenciatura",
63
+    "Postgrado / Maestria",
64
+    "Doctorado",
65
+    "Diplomado",
66
+    "Certificacion",
67
+    "Cursos"
68
+]

+ 64 - 84
src/Components/Password/Steps/one.js

2
 import * as Yup from 'yup';
2
 import * as Yup from 'yup';
3
 import { useState } from 'react';
3
 import { useState } from 'react';
4
 import { useFormik, Form, FormikProvider } from 'formik';
4
 import { useFormik, Form, FormikProvider } from 'formik';
5
-import { Icon } from '@iconify/react';
6
 
5
 
7
 import {  
6
 import {  
8
     Box, Button,
7
     Box, Button,
9
-    Stack, TextField, IconButton, InputAdornment, 
8
+    Stack, TextField, 
9
+    InputLabel,MenuItem,FormControl,Select
10
 } from '@mui/material';
10
 } from '@mui/material';
11
 
11
 
12
-import eyeFill from '@iconify/icons-eva/eye-fill';
12
+import { niveles_educativos } from '../Rows'
13
-import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
14
-// import { V1, V2 } from '../../Utils/HTTP'
15
 
13
 
16
 export function StepOne(props) {
14
 export function StepOne(props) {
17
 
15
 
18
-    const steplen = 2;
16
+    const [educativo, setEducativo] = useState('');
19
-    const index = 0;
20
 
17
 
21
-    const [showPassword, setShowPassword] = useState(false);
18
+    const changeNivelEducativo = (event) => {
22
-    const [showPasswordTwo, setShowPasswordTwo] = useState(false);
19
+        setEducativo(event.target.value);
20
+    };
23
 
21
 
24
-    const RegisterSchema = Yup.object().shape({
22
+    const CandidatoSchema = Yup.object().shape({
25
-        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
23
+        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
26
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
24
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
27
-        email: Yup.string().email('El correo no es valido').required('Email es requerido'),
25
+        puesto: Yup.string().required('El puesto es requerido'),
28
-        password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
26
+        niveles_educativo: Yup.number().required('Selecciona un nivel educativo')
29
-        password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
30
     });
27
     });
31
 
28
 
32
     let {  handleNext, handleBack } = props
29
     let {  handleNext, handleBack } = props
35
         initialValues: {
32
         initialValues: {
36
             firstName: '',
33
             firstName: '',
37
             lastName: '',
34
             lastName: '',
38
-            email: '',
35
+            puesto: '',
39
-            password: '',
36
+            niveles_educativo: 0,
40
-            password_confirm: ''
41
         },
37
         },
42
         onSubmit: (fields) => {
38
         onSubmit: (fields) => {
39
+            console.log('SUBMIT > ',fields)
43
             handleNext()
40
             handleNext()
44
         },
41
         },
45
-        validationSchema: RegisterSchema,
42
+        validationSchema: CandidatoSchema,
46
     });
43
     });
47
 
44
 
48
     const {errors, touched, handleSubmit, getFieldProps } = formik;
45
     const {errors, touched, handleSubmit, getFieldProps } = formik;
58
                             {...getFieldProps('firstName')}
55
                             {...getFieldProps('firstName')}
59
                             error={Boolean(touched.firstName && errors.firstName)}
56
                             error={Boolean(touched.firstName && errors.firstName)}
60
                             helperText={touched.firstName && errors.firstName}
57
                             helperText={touched.firstName && errors.firstName}
61
-                        />
58
+                            />
62
 
59
 
63
                         <TextField
60
                         <TextField
64
                             label="Apellidos"
61
                             label="Apellidos"
66
                             {...getFieldProps('lastName')}
63
                             {...getFieldProps('lastName')}
67
                             error={Boolean(touched.lastName && errors.lastName)}
64
                             error={Boolean(touched.lastName && errors.lastName)}
68
                             helperText={touched.lastName && errors.lastName}
65
                             helperText={touched.lastName && errors.lastName}
69
-                        />
66
+                            />
70
                     </Stack>
67
                     </Stack>
71
 
68
 
72
                     <TextField
69
                     <TextField
73
                         fullWidth
70
                         fullWidth
74
-                        autoComplete="username"
71
+                        type="text"
75
-                        type="email"
72
+                        label="Experiencia laboral o puesto"
76
-                        label="Correo Electrónico"
73
+                        {...getFieldProps('puesto')}
77
-                        {...getFieldProps('email')}
74
+                        error={Boolean(touched.puesto && errors.puesto)}
78
-                        error={Boolean(touched.email && errors.email)}
75
+                        helperText={touched.puesto && errors.puesto}
79
-                        helperText={touched.email && errors.email}
76
+                        />
80
-                    />
81
-
82
-                    <TextField
83
-                        fullWidth
84
-                        autoComplete="current-password"
85
-                        type={showPassword ? 'text' : 'password'}
86
-                        label="Contraseña"
87
-                        {...getFieldProps('password')}
88
-                        InputProps={{
89
-                            endAdornment: (
90
-                                <InputAdornment position="end">
91
-                                    <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
92
-                                        <Icon icon={showPassword ? eyeFill : eyeOffFill} />
93
-                                    </IconButton>
94
-                                </InputAdornment>
95
-                            )
96
-                        }}
97
-                        error={Boolean(touched.password && errors.password)}
98
-                        helperText={touched.password && errors.password}
99
-                    />
100
 
77
 
101
-                    <TextField
78
+                    <FormControl fullWidth>
102
-                        fullWidth
79
+                        <InputLabel id="demo-simple-select-label">Nivel Educativo</InputLabel>
103
-                        type={showPasswordTwo ? 'text' : 'password'}
80
+                        <Select
104
-                        label="Confirma contraseña"
81
+                            labelId="demo-simple-select-label"
105
-                        {...getFieldProps('password_confirm')}
82
+                            id="demo-simple-select"
106
-                        InputProps={{
83
+                            value={educativo}
107
-                            endAdornment: (
84
+                            label="Nivel Educativo"
108
-                                <InputAdornment position="end">
85
+                            onChange={changeNivelEducativo}
109
-                                    <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
86
+                            {...getFieldProps('niveles_educativo')}
110
-                                        <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
87
+                            error={Boolean(touched.niveles_educativo && errors.niveles_educativo)}
111
-                                    </IconButton>
88
+                        >
112
-                                </InputAdornment>
89
+                            {
113
-                            )
90
+                                niveles_educativos.map( ( nivel, index ) => {
114
-                        }}
91
+                                return (
115
-                        error={Boolean(touched.password_confirm && errors.password_confirm)}
92
+                                    <MenuItem key={nivel} value={index}>{nivel}</MenuItem>
116
-                        helperText={touched.password_confirm && errors.password_confirm}
93
+                                )
117
-                    />
94
+                            })
118
-
95
+                        }
119
-
96
+                        </Select>
120
-                  <Box sx={{ mb: 2 }}>
97
+                    </FormControl>
121
-                    <div style={{ paddingTop  : 15}}>
98
+
122
-                      <Button
99
+
123
-                        type="submit"
100
+                    <Box sx={{ mb: 2 }}>
124
-                        className="registerBtn" 
101
+                        <div style={{ paddingTop  : 15}}>
125
-                        variant="contained"
102
+                            <Button
126
-                        sx={{ mt: 1, mr: 1 }}
103
+                                type="submit"
127
-                      >
104
+                                className="registerBtn" 
128
-                        {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
105
+                                variant="contained"
129
-                      </Button>
106
+                                sx={{ mt: 1, mr: 1 }}
130
-                      <Button
107
+                            >
131
-                        disabled={true}
108
+                                {'Siguiente'}
132
-                        onClick={handleBack}
109
+                            </Button>
133
-                        sx={{ mt: 1, mr: 1 }}
110
+                            <Button
134
-                      >
111
+                                disabled={true}
135
-                        Regresar
112
+                                onClick={handleBack}
136
-                      </Button>
113
+                                sx={{ mt: 1, mr: 1 }}
137
-                    </div>
114
+                            >
138
-                  </Box>
115
+                                Regresar
116
+                            </Button>
117
+                        </div>
118
+                    </Box>
139
 
119
 
140
                 </Stack>
120
                 </Stack>
141
             </Form>
121
             </Form>