Reac front end for psicometric app

Company.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React from 'react'
  2. import * as Yup from 'yup';
  3. import { useFormik, Form, FormikProvider } from 'formik';
  4. import {
  5. Box, Button,
  6. Stack, TextField,
  7. } from '@mui/material';
  8. export function Company(props) {
  9. const RegisterSchema = Yup.object().shape({
  10. nombrecpmercial: Yup.string().min(2, 'Demasiado corto!').max(50, 'Demasiado largo!').required('El nombre es requerido'),
  11. telefono: Yup.number().min(10000000, 'El telefono es requerido').max(99999999, 'El telefono debe ser valido').required('El telefono es requerido'),
  12. decription: Yup.string().min(5, 'Ingresa una descripcion valida').required('Ingresa una descripcion valida'),
  13. });
  14. let { client, setClient, handleNext, handleBack } = props
  15. const formik = useFormik({
  16. initialValues: {
  17. nombrecpmercial: client?.empresa?.nombrecpmercial,
  18. telefono: client?.empresa?.telefono,
  19. decription: client?.empresa?.decription
  20. },
  21. onSubmit: (fields) => {
  22. setClient({
  23. ...client,
  24. empresa : fields
  25. })
  26. handleNext()
  27. },
  28. validationSchema: RegisterSchema,
  29. });
  30. const { errors, touched, handleSubmit, getFieldProps } = formik;
  31. return (
  32. <FormikProvider style={{ padding: 15 }} value={formik}>
  33. <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
  34. <Stack spacing={3}>
  35. <Stack direction={{ xs: 'column', sm: 'row' }} spacing={2}>
  36. <TextField
  37. label="Nombre Comercial"
  38. fullWidth
  39. {...getFieldProps('nombrecpmercial')}
  40. error={Boolean(touched.nombrecpmercial && errors.nombrecpmercial)}
  41. helperText={touched.nombrecpmercial && errors.nombrecpmercial}
  42. />
  43. <TextField
  44. label="Telefono"
  45. fullWidth
  46. {...getFieldProps('telefono')}
  47. error={Boolean(touched.telefono && errors.telefono)}
  48. helperText={touched.telefono && errors.telefono}
  49. />
  50. </Stack>
  51. <TextField
  52. label="Descripcion"
  53. fullWidth
  54. autoComplete="Descripcion"
  55. {...getFieldProps('decription')}
  56. error={Boolean(touched.decription && errors.decription)}
  57. helperText={touched.decription && errors.decription}
  58. />
  59. <Box sx={{ mb: 2 }}>
  60. <div style={{ paddingTop: 15 }}>
  61. <Button
  62. name="submit_second_step"
  63. type="submit"
  64. className="registerBtn"
  65. variant="contained"
  66. sx={{ mt: 1, mr: 1 }}
  67. >
  68. {'Siguiente'}
  69. </Button>
  70. <Button
  71. onClick={handleBack}
  72. sx={{ mt: 1, mr: 1 }}
  73. >
  74. Regresar
  75. </Button>
  76. </div>
  77. </Box>
  78. </Stack>
  79. </Form>
  80. </FormikProvider>
  81. );
  82. }