Reac front end for psicometric app

RegisterForm.jsx 6.0KB

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