RegPage.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React, { Component, useState } from "react";
  2. import FloatingLabel from "react-bootstrap/FloatingLabel";
  3. import Form from "react-bootstrap/Form";
  4. import Button from "react-bootstrap/Button";
  5. import { Link } from "react-router-dom";
  6. import PasswordChecklist from "react-password-checklist";
  7. import { store } from "../reducers";
  8. import { actionFullRegister } from "../actions";
  9. import { connect } from "react-redux";
  10. import { passValidator } from "../helpers/passValidator";
  11. const Registration = ({ onReg }) => {
  12. const [login, setLogin] = useState("");
  13. const [nick, setNick] = useState("");
  14. const [password, setPassword] = useState("");
  15. const [passwordAgain, setPasswordAgain] = useState("");
  16. return (
  17. <div className="formContainer">
  18. <h1 className="textLogin">Registration</h1>
  19. <FloatingLabel
  20. controlId="floatingInput"
  21. label="Enter Login"
  22. onChange={(e) => setLogin(e.target.value)}
  23. className="mb-3"
  24. >
  25. <Form.Control
  26. type="text"
  27. placeholder="text"
  28. className="form-control-editing"
  29. value={login}
  30. />
  31. </FloatingLabel>
  32. <PasswordChecklist
  33. rules={["minLength"]}
  34. minLength={5}
  35. value={login}
  36. valueAgain={passwordAgain}
  37. onChange={(isValid) => {}}
  38. className="validator"
  39. messages={{
  40. minLength: "Login has more than 5 characters.",
  41. }}
  42. />
  43. <FloatingLabel
  44. controlId="floatingInput"
  45. label="Enter Nick"
  46. onChange={(e) => setNick(e.target.value)}
  47. className="mb-3"
  48. >
  49. <Form.Control
  50. type="text"
  51. placeholder="text"
  52. className="form-control-editing"
  53. value={nick}
  54. />
  55. </FloatingLabel>
  56. <PasswordChecklist
  57. rules={["minLength"]}
  58. minLength={5}
  59. value={nick}
  60. valueAgain={passwordAgain}
  61. onChange={(isValid) => {}}
  62. className="validator"
  63. messages={{
  64. minLength: "Login has more than 5 characters.",
  65. }}
  66. />
  67. <FloatingLabel controlId="floatingPassword" label="Enter Password">
  68. <Form.Control
  69. type="password"
  70. onChange={(e) => setPassword(e.target.value)}
  71. placeholder="Password:"
  72. className="form-control-editing fix"
  73. />
  74. </FloatingLabel>
  75. <FloatingLabel controlId="floatingPassword" label="Repeat Password">
  76. <Form.Control
  77. type="password"
  78. onChange={(e) => setPasswordAgain(e.target.value)}
  79. placeholder="Password Again"
  80. className="form-control-editing fix"
  81. />
  82. </FloatingLabel>
  83. <PasswordChecklist
  84. rules={["minLength", "number", "capital", "match"]}
  85. minLength={8}
  86. value={password}
  87. valueAgain={passwordAgain}
  88. onChange={(isValid) => {}}
  89. className="validator"
  90. />
  91. <div className="d-flex loginForm">
  92. <Button
  93. variant="primary"
  94. type="submit"
  95. className="btn-setting"
  96. onClick={() => {
  97. onReg(login, password, nick);
  98. }}
  99. disabled={
  100. login.length >= "5" && nick.length >= "5"
  101. ? !passValidator(password, passwordAgain)
  102. : true
  103. }
  104. >
  105. <b>Register</b>
  106. </Button>
  107. <Link to="/login" className="registerLink alert-link">
  108. Have an account? Login
  109. </Link>
  110. </div>
  111. </div>
  112. );
  113. };
  114. export const CRegistration = connect(null, { onReg: actionFullRegister })(
  115. Registration
  116. );