Просмотр исходного кода

step one validation and submit

amenpunk 4 лет назад
Родитель
Сommit
0cc7e4dc41

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

@@ -8,24 +8,6 @@ import {
 
 import { StepOne } from '../Password/Steps/one'
 
-const steps = [
-    {
-        label : 'Información del candidato',
-        operation: <StepOne/>
-    },
-    {
-        label : 'Seleccionar plaza',
-        operation: <h1>plaza</h1>
-    },
-    {
-        label : 'Seleccionar pruebas',
-        operation: <h1>preubas</h1>
-    },
-    {
-        label : 'Confirmar',
-        operation: <h1>adios</h1>
-    },
-];
 
 export function HelpModal (props) {
 
@@ -58,6 +40,30 @@ export function HelpModal (props) {
     };
 
 
+    const steps = [
+        {
+            label : 'Información del candidato',
+            operation: 
+                <StepOne 
+                    handleNext={handleNext} 
+                    handleBack={handleBack} 
+                />
+        },
+        {
+            label : 'Seleccionar plaza',
+            operation: <h1>plaza</h1>
+        },
+        {
+            label : 'Seleccionar pruebas',
+            operation: <h1>preubas</h1>
+        },
+        {
+            label : 'Confirmar',
+            operation: <h1>adios</h1>
+        },
+    ];
+
+
     return (
         <Modal size="lg" 
             aria-labelledby="contained-modal-title-vcenter" 
@@ -102,21 +108,6 @@ export function HelpModal (props) {
                                     {steps[activeStep].operation}
                                 </Box>
 
-                                <Box sx={{ display: 'flex', flexDirection: 'row', pt: 2 }}>
-                                    <Button
-                                        color="inherit"
-                                        disabled={activeStep === 0}
-                                        onClick={handleBack}
-                                        sx={{ mr: 1 }}
-                                    >
-                                        Anterior
-                                    </Button>
-                                    <Box sx={{ flex: '1 1 auto' }} />
-                                    <Button onClick={handleNext}>
-                                        {activeStep === steps.length - 1 ? 'Guardar' : 'Siguiente'}
-                                    </Button>
-                                </Box>
-
                             </React.Fragment>
                         )}
                 </Box>

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

@@ -54,3 +54,15 @@ export const encabezados = [
         label: 'Operacion',
     },
 ]
+export const niveles_educativos = [
+    "Primaria",
+    "Basico",
+    "Diversificado",
+    "Tecnico",
+    "Pregrado / Licenciatura",
+    "Postgrado / Maestria",
+    "Doctorado",
+    "Diplomado",
+    "Certificacion",
+    "Cursos"
+]

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

@@ -2,31 +2,28 @@ import React from 'react'
 import * as Yup from 'yup';
 import { useState } from 'react';
 import { useFormik, Form, FormikProvider } from 'formik';
-import { Icon } from '@iconify/react';
 
 import {  
     Box, Button,
-    Stack, TextField, IconButton, InputAdornment, 
+    Stack, TextField, 
+    InputLabel,MenuItem,FormControl,Select
 } from '@mui/material';
 
-import eyeFill from '@iconify/icons-eva/eye-fill';
-import eyeOffFill from '@iconify/icons-eva/eye-off-fill';
-// import { V1, V2 } from '../../Utils/HTTP'
+import { niveles_educativos } from '../Rows'
 
 export function StepOne(props) {
 
-    const steplen = 2;
-    const index = 0;
+    const [educativo, setEducativo] = useState('');
 
-    const [showPassword, setShowPassword] = useState(false);
-    const [showPasswordTwo, setShowPasswordTwo] = useState(false);
+    const changeNivelEducativo = (event) => {
+        setEducativo(event.target.value);
+    };
 
-    const RegisterSchema = Yup.object().shape({
-        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('Tu nombre es requerido'),
+    const CandidatoSchema = Yup.object().shape({
+        firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
         lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
-        email: Yup.string().email('El correo no es valido').required('Email es requerido'),
-        password: Yup.string().min(5, 'La contraseña debe contener mínimo 5 caracteres').required('la contraseña es requerida'),
-        password_confirm: Yup.string().required('Las contraseñas no coincidien').oneOf([Yup.ref('password'), null], 'Las contraseñas no coincidien')
+        puesto: Yup.string().required('El puesto es requerido'),
+        niveles_educativo: Yup.number().required('Selecciona un nivel educativo')
     });
 
     let {  handleNext, handleBack } = props
@@ -35,14 +32,14 @@ export function StepOne(props) {
         initialValues: {
             firstName: '',
             lastName: '',
-            email: '',
-            password: '',
-            password_confirm: ''
+            puesto: '',
+            niveles_educativo: 0,
         },
         onSubmit: (fields) => {
+            console.log('SUBMIT > ',fields)
             handleNext()
         },
-        validationSchema: RegisterSchema,
+        validationSchema: CandidatoSchema,
     });
 
     const {errors, touched, handleSubmit, getFieldProps } = formik;
@@ -58,7 +55,7 @@ export function StepOne(props) {
                             {...getFieldProps('firstName')}
                             error={Boolean(touched.firstName && errors.firstName)}
                             helperText={touched.firstName && errors.firstName}
-                        />
+                            />
 
                         <TextField
                             label="Apellidos"
@@ -66,76 +63,59 @@ export function StepOne(props) {
                             {...getFieldProps('lastName')}
                             error={Boolean(touched.lastName && errors.lastName)}
                             helperText={touched.lastName && errors.lastName}
-                        />
+                            />
                     </Stack>
 
                     <TextField
                         fullWidth
-                        autoComplete="username"
-                        type="email"
-                        label="Correo Electrónico"
-                        {...getFieldProps('email')}
-                        error={Boolean(touched.email && errors.email)}
-                        helperText={touched.email && errors.email}
-                    />
-
-                    <TextField
-                        fullWidth
-                        autoComplete="current-password"
-                        type={showPassword ? 'text' : 'password'}
-                        label="Contraseña"
-                        {...getFieldProps('password')}
-                        InputProps={{
-                            endAdornment: (
-                                <InputAdornment position="end">
-                                    <IconButton edge="end" onClick={() => setShowPassword((prev) => !prev)}>
-                                        <Icon icon={showPassword ? eyeFill : eyeOffFill} />
-                                    </IconButton>
-                                </InputAdornment>
-                            )
-                        }}
-                        error={Boolean(touched.password && errors.password)}
-                        helperText={touched.password && errors.password}
-                    />
+                        type="text"
+                        label="Experiencia laboral o puesto"
+                        {...getFieldProps('puesto')}
+                        error={Boolean(touched.puesto && errors.puesto)}
+                        helperText={touched.puesto && errors.puesto}
+                        />
 
-                    <TextField
-                        fullWidth
-                        type={showPasswordTwo ? 'text' : 'password'}
-                        label="Confirma contraseña"
-                        {...getFieldProps('password_confirm')}
-                        InputProps={{
-                            endAdornment: (
-                                <InputAdornment position="end">
-                                    <IconButton edge="end" onClick={() => setShowPasswordTwo((prev) => !prev)}>
-                                        <Icon icon={showPasswordTwo ? eyeFill : eyeOffFill} />
-                                    </IconButton>
-                                </InputAdornment>
-                            )
-                        }}
-                        error={Boolean(touched.password_confirm && errors.password_confirm)}
-                        helperText={touched.password_confirm && errors.password_confirm}
-                    />
-
-
-                  <Box sx={{ mb: 2 }}>
-                    <div style={{ paddingTop  : 15}}>
-                      <Button
-                        type="submit"
-                        className="registerBtn" 
-                        variant="contained"
-                        sx={{ mt: 1, mr: 1 }}
-                      >
-                        {index === steplen - 1 ? 'Registrarme' : 'Siguiente'}
-                      </Button>
-                      <Button
-                        disabled={true}
-                        onClick={handleBack}
-                        sx={{ mt: 1, mr: 1 }}
-                      >
-                        Regresar
-                      </Button>
-                    </div>
-                  </Box>
+                    <FormControl fullWidth>
+                        <InputLabel id="demo-simple-select-label">Nivel Educativo</InputLabel>
+                        <Select
+                            labelId="demo-simple-select-label"
+                            id="demo-simple-select"
+                            value={educativo}
+                            label="Nivel Educativo"
+                            onChange={changeNivelEducativo}
+                            {...getFieldProps('niveles_educativo')}
+                            error={Boolean(touched.niveles_educativo && errors.niveles_educativo)}
+                        >
+                            {
+                                niveles_educativos.map( ( nivel, index ) => {
+                                return (
+                                    <MenuItem key={nivel} value={index}>{nivel}</MenuItem>
+                                )
+                            })
+                        }
+                        </Select>
+                    </FormControl>
+
+
+                    <Box sx={{ mb: 2 }}>
+                        <div style={{ paddingTop  : 15}}>
+                            <Button
+                                type="submit"
+                                className="registerBtn" 
+                                variant="contained"
+                                sx={{ mt: 1, mr: 1 }}
+                            >
+                                {'Siguiente'}
+                            </Button>
+                            <Button
+                                disabled={true}
+                                onClick={handleBack}
+                                sx={{ mt: 1, mr: 1 }}
+                            >
+                                Regresar
+                            </Button>
+                        </div>
+                    </Box>
 
                 </Stack>
             </Form>