Reac front end for psicometric app

one.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React from 'react'
  2. import * as Yup from 'yup';
  3. import { useState } from 'react';
  4. import { useFormik, Form, FormikProvider } from 'formik';
  5. import {
  6. Box, Button,
  7. Stack, TextField,
  8. InputLabel,MenuItem,FormControl,Select
  9. } from '@mui/material';
  10. import { niveles_educativos } from '../Rows'
  11. export function StepOne(props) {
  12. const [educativo, setEducativo] = useState('');
  13. const changeNivelEducativo = (event) => {
  14. setEducativo(event.target.value);
  15. };
  16. const CandidatoSchema = Yup.object().shape({
  17. firstName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
  18. lastName: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado Largo!').required('El apellido es requerido'),
  19. puesto: Yup.string().required('El puesto es requerido'),
  20. niveles_educativo: Yup.number().required('Selecciona un nivel educativo')
  21. });
  22. let { handleNext, handleBack } = props
  23. const formik = useFormik({
  24. initialValues: {
  25. firstName: '',
  26. lastName: '',
  27. puesto: '',
  28. niveles_educativo: 0,
  29. },
  30. onSubmit: (fields) => {
  31. console.log('SUBMIT > ',fields)
  32. handleNext()
  33. },
  34. validationSchema: CandidatoSchema,
  35. });
  36. const {errors, touched, handleSubmit, getFieldProps } = formik;
  37. return (
  38. <FormikProvider style={{ padding : 25 }} value={formik}>
  39. <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
  40. <Stack spacing={3}>
  41. <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
  42. <TextField
  43. label="Nombre"
  44. fullWidth
  45. {...getFieldProps('firstName')}
  46. error={Boolean(touched.firstName && errors.firstName)}
  47. helperText={touched.firstName && errors.firstName}
  48. />
  49. <TextField
  50. label="Apellidos"
  51. fullWidth
  52. {...getFieldProps('lastName')}
  53. error={Boolean(touched.lastName && errors.lastName)}
  54. helperText={touched.lastName && errors.lastName}
  55. />
  56. </Stack>
  57. <TextField
  58. fullWidth
  59. type="text"
  60. label="Experiencia laboral o puesto"
  61. {...getFieldProps('puesto')}
  62. error={Boolean(touched.puesto && errors.puesto)}
  63. helperText={touched.puesto && errors.puesto}
  64. />
  65. <FormControl fullWidth>
  66. <InputLabel id="demo-simple-select-label">Nivel Educativo</InputLabel>
  67. <Select
  68. labelId="demo-simple-select-label"
  69. id="demo-simple-select"
  70. value={educativo}
  71. label="Nivel Educativo"
  72. onChange={changeNivelEducativo}
  73. {...getFieldProps('niveles_educativo')}
  74. error={Boolean(touched.niveles_educativo && errors.niveles_educativo)}
  75. >
  76. {
  77. niveles_educativos.map( ( nivel, index ) => {
  78. return (
  79. <MenuItem key={nivel} value={index}>{nivel}</MenuItem>
  80. )
  81. })
  82. }
  83. </Select>
  84. </FormControl>
  85. <Box sx={{ mb: 2 }}>
  86. <div style={{ paddingTop : 15}}>
  87. <Button
  88. type="submit"
  89. className="registerBtn"
  90. variant="contained"
  91. sx={{ mt: 1, mr: 1 }}
  92. >
  93. {'Siguiente'}
  94. </Button>
  95. <Button
  96. disabled={true}
  97. onClick={handleBack}
  98. sx={{ mt: 1, mr: 1 }}
  99. >
  100. Regresar
  101. </Button>
  102. </div>
  103. </Box>
  104. </Stack>
  105. </Form>
  106. </FormikProvider>
  107. );
  108. }