App.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import {connect} from 'react-redux';
  3. import {Switch} from "react-router-dom";
  4. import {getDoctors} from "./actions/actions";
  5. import {getServices, getCategories} from "./actions/services";
  6. import {getUser} from "./actions/auth"
  7. import Loader from "./components/hooks/loader";
  8. import Header from "./components/header/index";
  9. import Footer from "./components/Footer";
  10. import {route} from './utils/formFields'
  11. import { PrivateRoute } from "./privateRouter";
  12. export class App extends React.Component {
  13. componentDidMount() {
  14. this.props.getDoctors();
  15. this.props.getServices();
  16. console.log(this.props.app)
  17. this.props.getCategories();
  18. if(localStorage.getItem('userId')) this.props.getUser()
  19. // fetch ("https://api-clinics.herokuapp.com/api/v1/auth/login", {
  20. // method : "POST",
  21. // credentials: "include",
  22. // headers: {
  23. // "Content-Type": "application/json"
  24. // },
  25. // body: JSON.stringify ({
  26. // email: "test@test.com",
  27. // password: "qwerty"
  28. // })
  29. // })
  30. // .then (res => res.json ())
  31. // .then (res => console.log (res))
  32. }
  33. render() {
  34. return (
  35. <Loader flag={this.props.app.isFetching}>
  36. <Header/>
  37. <Switch>
  38. {route.map(el => (
  39. <PrivateRoute
  40. protectedRoute={el.protected}
  41. key={el.id}
  42. exact={el.exact}
  43. path={el.path}
  44. component={el.component}
  45. />
  46. ))}
  47. </Switch>
  48. <Footer />
  49. </Loader>
  50. );
  51. }
  52. }
  53. const mapStateToProps = state => {
  54. return {
  55. app:state.app
  56. }
  57. };
  58. const mapDispatchToProps = {
  59. getDoctors,
  60. getServices,
  61. getCategories,
  62. getUser
  63. };
  64. export default connect (mapStateToProps,mapDispatchToProps)(App)