RegisterPage.jsx 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { TextField, Typography, IconButton, InputAdornment, Grid, Button } from "@mui/material"
  2. import { Visibility, VisibilityOff } from '@mui/icons-material';
  3. import { useState } from "react"
  4. import { actionFullRegister } from "../actions/actionLogin";
  5. import { connect } from "react-redux";
  6. function RegisterPage ({onRegister}) {
  7. const [values, setValues] = useState({
  8. login: '',
  9. firstPassword: '',
  10. secondPassword: '',
  11. nickname: '',
  12. showPassword: ''
  13. })
  14. const [errorLogin, setErrorLogin] = useState(false);
  15. const [errorPass, setErrorPass] = useState(false);
  16. const handleChange = (prop) => (e) => {
  17. setValues({...values, [prop] : e.target.value})
  18. }
  19. const handleClickShowPassword = () => {
  20. setValues({
  21. ...values, showPassword : !values.showPassword
  22. })
  23. }
  24. return (
  25. <div className="RegisterPage">
  26. <form className="Form" noValidate autoComplete="off">
  27. <Typography sx={{mb: '20px'}} variant='h4'>Регистрация</Typography>
  28. <TextField
  29. error={errorLogin}
  30. sx={{width: '100%', mb: '30px'}}
  31. required
  32. label="Логин"
  33. variant="outlined"
  34. helperText="минимум 3"
  35. value={values.login}
  36. autoFocus
  37. onChange={handleChange('login')}
  38. />
  39. <TextField
  40. sx={{width: '100%', mb: '30px'}}
  41. label="Ник"
  42. variant="outlined"
  43. value={values.nickname}
  44. autoFocus
  45. onChange={handleChange('nickname')}
  46. />
  47. <TextField
  48. error={errorPass}
  49. sx={{width: '100%'}}
  50. helperText="минимум 3"
  51. required
  52. variant="outlined"
  53. label="Пароль"
  54. type={'password'}
  55. value={values.firstPassword}
  56. onChange={handleChange('firstPassword')}
  57. />
  58. <TextField
  59. error={errorPass}
  60. sx={{width: '100%'}}
  61. helperText="минимум 3"
  62. required
  63. variant="outlined"
  64. label="Повторите пароль"
  65. type={'password'}
  66. value={values.secondPassword}
  67. onChange={handleChange('secondPassword')}
  68. />
  69. <Button //проверять payload чтобы понимать зарегался пользователь или имя уже существует
  70. onClick={
  71. () => {
  72. onRegister(values.login, values.firstPassword, values.nickname);
  73. }
  74. }
  75. sx={{width: '200px', mt: '30px'}}
  76. variant="contained">
  77. Войти
  78. </Button>
  79. </form>
  80. </div>
  81. )
  82. }
  83. export default connect(null, {onRegister: actionFullRegister})(RegisterPage)