two.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react'
  2. import * as Yup from 'yup';
  3. // import { useState, useEffect } from 'react';
  4. import { useFormik, Form, FormikProvider } from 'formik';
  5. import {
  6. Box, Button, Stack, Select,
  7. FormControl,MenuItem,InputLabel
  8. } from '@mui/material';
  9. export function StepTwo(props) {
  10. const PlazaScheme = Yup.object().shape({
  11. puesto_id:
  12. Yup.number()
  13. .positive('Escoge un puesto válido')
  14. .required('Escoge un puesto válido')
  15. });
  16. let { handleNext, handleBack, password, setPassword } = props
  17. const formik = useFormik({
  18. initialValues: {
  19. puesto_id: password.puesto_id
  20. },
  21. onSubmit: (fields) => {
  22. setPassword({...password, ...fields})
  23. handleNext()
  24. },
  25. validationSchema: PlazaScheme,
  26. });
  27. const [age, setAge] = React.useState('');
  28. const handleChange = (event) => {
  29. console.log("Edad -> ",event.target.value)
  30. setAge(event.target.value);
  31. };
  32. const { handleSubmit, touched, errors, getFieldProps } = formik;
  33. return (
  34. <FormikProvider style={{ padding : 25 }} value={formik}>
  35. <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
  36. <Stack spacing={2}>
  37. <FormControl fullWidth>
  38. <InputLabel id="demo-simple-select-label">Puestos</InputLabel>
  39. <Select
  40. labelId="demo-simple-select-label"
  41. id="demo-simple-select"
  42. value={age}
  43. label="Puestos"
  44. onChange={handleChange}
  45. {...getFieldProps('puesto_id')}
  46. error={Boolean(touched.puesto_id && errors.puesto_id)}
  47. >
  48. <MenuItem value={10}>Full Stack</MenuItem>
  49. <MenuItem value={20}>Web Developer</MenuItem>
  50. <MenuItem value={30}>Database Administrator</MenuItem>
  51. </Select>
  52. </FormControl>
  53. <label className="feedback_error">
  54. {touched.puesto_id && errors.puesto_id}
  55. </label>
  56. <Box sx={{ mb: 2 }}>
  57. <div style={{ paddingTop : 15}}>
  58. <Button
  59. type="submit"
  60. className="registerBtn"
  61. variant="contained"
  62. sx={{ mt: 1, mr: 1 }}
  63. >
  64. {'Siguiente'}
  65. </Button>
  66. <Button
  67. disabled={false}
  68. onClick={handleBack}
  69. sx={{ mt: 1, mr: 1 }}
  70. >
  71. Regresar
  72. </Button>
  73. </div>
  74. </Box>
  75. </Stack>
  76. </Form>
  77. </FormikProvider>
  78. );
  79. }