LoginPage.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React 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 Alert from "react-bootstrap/Alert";
  6. import { useState, useEffect } from "react";
  7. import { store } from "../reducers/index";
  8. import { actionFullLogin } from "../actions";
  9. import { Link } from "react-router-dom";
  10. import { connect } from "react-redux";
  11. import { compose } from "redux";
  12. import { history } from "../App";
  13. const Login = ({ onLogin, token }) => {
  14. const [login, setLogin] = useState("");
  15. const [password, setPassword] = useState("");
  16. const [check, setCheck] = useState(false)
  17. // useEffect(() => {
  18. // if(token?.token) {
  19. // }
  20. // }, [token])
  21. return (
  22. <div className="formContainerLogin">
  23. <h1 className="textLogin">Login</h1>
  24. <FloatingLabel
  25. controlId="floatingInput"
  26. label="Enter Login"
  27. className="mb-3"
  28. onChange={(e) => {
  29. setLogin(e.target.value);
  30. }}
  31. >
  32. <Form.Control
  33. type="text"
  34. placeholder="text"
  35. className="form-control-editing"
  36. />
  37. </FloatingLabel>
  38. <FloatingLabel
  39. controlId="floatingPassword"
  40. label="Enter Password"
  41. onChange={(e) => {
  42. setPassword(e.target.value);
  43. }}
  44. >
  45. <Form.Control
  46. type="password"
  47. placeholder="Password"
  48. className="form-control-editing"
  49. />
  50. </FloatingLabel>
  51. <div className="d-flex loginForm">
  52. <Button
  53. variant="primary"
  54. type="submit"
  55. className="btn-setting"
  56. onClick={() => {
  57. onLogin(login, password);
  58. setTimeout(() => setCheck(true), 1500)
  59. }}
  60. disabled={!login || !password}
  61. >
  62. <b>Login</b>
  63. </Button>
  64. <div className={check ? "logErrorOn" : 'logErrorOff'}>
  65. <h5>Incorect Login or Password</h5>
  66. </div>
  67. <Link to="/registration" className="registerLink alert-link">
  68. Don't have an account? Register
  69. </Link>
  70. </div>
  71. </div>
  72. );
  73. };
  74. export const CLogin = connect((state) => ({token: state.auth}), {
  75. onLogin: actionFullLogin,
  76. })(Login);