LoginPage.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { useState } from 'react';
  2. import { Link } from 'react-router-dom';
  3. import '../App.css';
  4. import {history} from '../history'
  5. import store from '../store';
  6. import actionChatList from '../store/reducers/chat-reducer'
  7. export const LoginPage = ({ onLogin, outLogin }) => {
  8. const [login, setLogin] = useState("");
  9. const [password, setPassword] = useState("");
  10. const Authorization = () => {
  11. if(localStorage.authToken){
  12. history.push('/chat')
  13. }
  14. onLogin(login, password);
  15. setLogin('');
  16. setPassword('');
  17. };
  18. const OutAuthorization = () => {
  19. outLogin();
  20. }
  21. return (
  22. <div className="formBlock">
  23. <h1>Вход</h1>
  24. <div className="mb-3">
  25. <label htmlFor="exampleInputEmail1" className="form-label">Enter Login</label>
  26. <input
  27. type="text"
  28. value={login}
  29. onChange={(e) => setLogin(e.target.value)}
  30. className="form-control"
  31. id="exampleInputEmail1"
  32. aria-describedby="emailHelp" />
  33. </div>
  34. <div className="mb-3">
  35. <label htmlFor="exampleInputPassword1" className="form-label">Enter Password</label>
  36. <input
  37. type="password"
  38. value={password}
  39. onChange={(e) => setPassword(e.target.value)}
  40. className="form-control"
  41. id="exampleInputPassword1" />
  42. </div>
  43. <div className="mb-3">
  44. <button type="submit" className="btn btn-primary" onClick={Authorization}>Войти</button>
  45. </div>
  46. {/* <button onClick={OutAuthorization}>Log Out</button> */}
  47. <Link to="/registration">Зарегистрироваться</Link>
  48. </div>
  49. );
  50. };