App.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import React from 'react';
  2. import {connect} from 'react-redux';
  3. import {Switch, Route} from "react-router-dom";
  4. // import { BrowserHistory } from 'react-history'
  5. import {
  6. getDoctors,
  7. getServices,
  8. } from "./actions/actions";
  9. import {
  10. getUser,
  11. } from "./actions/auth"
  12. import Loader from "./components/loader";
  13. import Header from "./components/header/index";
  14. import Main from "./components/main/Main";
  15. import Doctors from "./components/specialists/Doctors";
  16. import Services from "./components/services/Services";
  17. // import Categories from "./components/services/categories"
  18. import MoreInfo from "./components/specialists/MoreInfo";
  19. import Appointment from "./components/appointment/Appointment";
  20. import Reviews from "./components/Reviews";
  21. import Admin from './components/Admin/Admin';
  22. import Auth from './containers/auth';
  23. import Footer from "./components/Footer";
  24. // import Calendar from "./components/Calendar"
  25. import User from './components/user'
  26. import { PrivateRoute } from "./privateRouter";
  27. const PAGENOTFOUND = () => <div>PAGE 404 NOT FOUND</div>;
  28. const route = [
  29. {
  30. id: 1,
  31. exact: true,
  32. path: "/",
  33. protected: false,
  34. // hasAccess: [],
  35. component: Main
  36. },
  37. {
  38. id: 2,
  39. exact: true,
  40. path: "/doctors",
  41. protected: false,
  42. component: Doctors
  43. },
  44. {
  45. id: 3,
  46. exact: true,
  47. path: "/services",
  48. protected: false,
  49. component: Services
  50. },
  51. {
  52. id: 3,
  53. exact: true,
  54. path: "/doctors/:doctor",
  55. protected: false,
  56. component: MoreInfo
  57. },
  58. {
  59. id: 4,
  60. exact: true,
  61. path: "/services/:service",
  62. protected: false,
  63. component: MoreInfo
  64. },
  65. {
  66. id: 5,
  67. exact: true,
  68. path: "/reviews",
  69. protected: false,
  70. component: Reviews
  71. },
  72. {
  73. id: 6,
  74. exact: true,
  75. path: "/admin",
  76. protected: true,
  77. component: Admin
  78. },
  79. {
  80. id: 7,
  81. exact: true,
  82. path: "/appointment/:doctorId",
  83. protected: false,
  84. component: Appointment
  85. },
  86. {
  87. id: 8,
  88. exact: true,
  89. path: "/auth",
  90. protected: false,
  91. component: Auth
  92. },
  93. {
  94. id: 9,
  95. exact: true,
  96. path: "/user",
  97. protected: true,
  98. component: User
  99. },
  100. {
  101. id: 10,
  102. component: PAGENOTFOUND
  103. },
  104. ];
  105. export class App extends React.Component {
  106. componentDidMount() {
  107. this.props.getDoctors();
  108. this.props.getServices();
  109. if(localStorage.getItem('userId')){
  110. this.props.getUser()
  111. }
  112. // fetch ("https://api-clinics.herokuapp.com/api/v1/auth/login", {
  113. // method : "POST",
  114. // credentials: "include",
  115. // headers: {
  116. // "Content-Type": "application/json"
  117. // },
  118. // body: JSON.stringify ({
  119. // email: "test@test.com",
  120. // password: "qwerty"
  121. // })
  122. // })
  123. // .then (res => res.json ())
  124. // .then (res => console.log (res))
  125. }
  126. render() {
  127. return (
  128. <Loader flag={this.props.app.isFetching}>
  129. <Header/>
  130. <Switch>
  131. {route.map(el => (
  132. <PrivateRoute
  133. protectedRoute={el.protected}
  134. key={el.id}
  135. exact={el.exact}
  136. path={el.path}
  137. component={el.component}
  138. />
  139. ))}
  140. </Switch>
  141. <Footer />
  142. </Loader>
  143. );
  144. }
  145. }
  146. const mapStateToProps = state => {
  147. return {
  148. app:state.app,
  149. user:state.auth.user
  150. }
  151. };
  152. const mapDispatchToProps = {
  153. getDoctors,
  154. getServices,
  155. getUser,
  156. };
  157. export default connect (mapStateToProps,mapDispatchToProps)(App)