Login.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React, { useState, useRef, } from "react";
  2. import { connect } from "react-redux";
  3. // import { actionLogin } from "../Actions";
  4. // import history from "../history";
  5. import { actionLogin, store } from "../Reduser";
  6. import { Container, FormControl, Nav, Navbar, Form, Button } from 'react-bootstrap';
  7. const LoginForm = ({ onLogin = null, isLoggedIn, mode = "Login" }) => {
  8. const [login, setLogin] = useState("");
  9. const [pass, setPass] = useState("");
  10. const [nick, setNick] = useState("");
  11. const input_ref = useRef(null);
  12. const pass_ref = useRef(null);
  13. const nick_ref = useRef(null);
  14. const btn_ref = useRef(null);
  15. return (
  16. <>
  17. <Container style={{ width: "500px" }}>
  18. <h1 className="text-center">
  19. Your accaunt
  20. </h1>
  21. <Form>
  22. <Form.Label> Login</Form.Label>
  23. <Form.Control
  24. type="login"
  25. placeholder="Enter login"
  26. ref={input_ref}
  27. readOnly={isLoggedIn}
  28. onChange={(e) => {
  29. setLogin(e.target.value);
  30. }} />
  31. <Form.Group controlId="formBasicPassword">
  32. <Form.Label> Password</Form.Label>
  33. <Form.Control
  34. type="password"
  35. placeholder="Enter password"
  36. ref={pass_ref}
  37. readOnly={isLoggedIn}
  38. onChange={(e) => {
  39. setPass(e.target.value)
  40. }
  41. } />
  42. </Form.Group>
  43. <Form.Group controlId="formBasicPassword">
  44. <Form.Label> Confirm Password</Form.Label>
  45. <Form.Control
  46. type="password"
  47. placeholder="Confirm password"
  48. ref={pass_ref}
  49. readOnly={isLoggedIn}
  50. type="password"
  51. onChange={(e) => {
  52. setPass(e.target.value);
  53. }} />
  54. </Form.Group>
  55. <Button
  56. variant="secondary"
  57. type="submit"
  58. ref={btn_ref}
  59. onClick={() => {
  60. onLogin(login, pass);
  61. console.log("кнопка лагин нажата");
  62. }}
  63. disabled={isLoggedIn || !login || !pass || (mode !== "Login" && !nick)}
  64. > {mode} </Button>
  65. </Form>
  66. </Container>
  67. {/* <input
  68. ref={pass_ref}
  69. readOnly={isLoggedIn}
  70. type="password"
  71. placeholder="Password"
  72. onChange={(e) => {
  73. setPass(e.target.value);
  74. }}
  75. ></input> */}
  76. {/* <button
  77. ref={btn_ref}
  78. onClick={() => {
  79. onLogin(login, pass);
  80. console.log("кнопка лагин нажата");
  81. }}
  82. disabled={isLoggedIn || !login || !pass || (mode !== "Login" && !nick)}
  83. >
  84. {mode}
  85. </button> */}
  86. </>
  87. );
  88. };
  89. const CLoginForm = connect((s) => ({ isLoggedIn: s.auth.login, mode: "Login" }), { onLogin: actionLogin })(LoginForm);
  90. export const Login = () => {
  91. return (
  92. <>
  93. <div>PageLogin</div>
  94. <CLoginForm />
  95. </>
  96. );
  97. };