App.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { lazy, Suspense } from 'react';
  2. import { BrowserRouter, Switch, Route } from 'react-router-dom';
  3. import { connect } from 'react-redux';
  4. import { ToastContainer } from 'react-toastify';
  5. import s from './App.module.css';
  6. import { IAppProps, IAppState } from './typescript/app/interfaces';
  7. import PrivateRoute from './components/Routes/PrivateRoute/PrivateRoute';
  8. import PublicRoute from './components/Routes/PublicRoute/PublicRoute';
  9. import Loader from './components/Loader/Loader';
  10. const Navigation = lazy(
  11. () =>
  12. import(
  13. './components/Navigation/Navigation' /* webpackChunkName: "Navigation" */
  14. ),
  15. );
  16. const Categories = lazy(
  17. () =>
  18. import(
  19. './components/Categories/Categories' /* webpackChunkName: "Categories" */
  20. ),
  21. );
  22. const Goods = lazy(
  23. () => import('./components/Goods/Goods' /* webpackChunkName: "Goods" */),
  24. );
  25. const DetailGood = lazy(
  26. () =>
  27. import(
  28. './components/Goods/DetailGood/DetailGood' /* webpackChunkName: "DetailGood" */
  29. ),
  30. );
  31. const Orders = lazy(
  32. () => import('./components/Orders/Orders' /* webpackChunkName: "Orders" */),
  33. );
  34. const DetailOrder = lazy(
  35. () =>
  36. import(
  37. './components/Orders/DetailOrder/DetailOrder' /* webpackChunkName: "DetailOrder" */
  38. ),
  39. );
  40. const Authorization = lazy(
  41. () =>
  42. import(
  43. './components/Authorization/Authorization' /* webpackChunkName: "AuthorizationPage" */
  44. ),
  45. );
  46. const SignInForm = lazy(
  47. () =>
  48. import(
  49. './components/Authorization/SignIn/SignIn' /* webpackChunkName: "SignInForm" */
  50. ),
  51. );
  52. const RegistrationForm = lazy(
  53. () =>
  54. import(
  55. './components/Authorization/Registration/RegistrationForm' /* webpackChunkName: "RegistrationForm" */
  56. ),
  57. );
  58. function App({ isLoading }: IAppProps) {
  59. return (
  60. <div className={s.appWrapper}>
  61. <Suspense fallback={<Loader />}>
  62. <BrowserRouter>
  63. <Switch>
  64. <Route path={'/authorization'}>
  65. <Authorization />
  66. <PublicRoute exact path={'/authorization/login'} restricted>
  67. <SignInForm />
  68. </PublicRoute>
  69. <PublicRoute
  70. exact
  71. path={'/authorization/registration'}
  72. restricted
  73. >
  74. <RegistrationForm />
  75. </PublicRoute>
  76. </Route>
  77. <PrivateRoute path="/">
  78. <Navigation />
  79. </PrivateRoute>
  80. <PrivateRoute exact path="/categories">
  81. <Navigation />
  82. <Categories />
  83. </PrivateRoute>
  84. <PrivateRoute exact path="/categories/goods/:name">
  85. <Navigation />
  86. <Goods />
  87. </PrivateRoute>
  88. <PrivateRoute exact path="/categories/goods/:name/:id">
  89. <Navigation />
  90. <DetailGood />
  91. </PrivateRoute>
  92. <PrivateRoute exact path="/orders">
  93. <Navigation />
  94. <Orders />
  95. </PrivateRoute>
  96. <PrivateRoute path="/orders/:id">
  97. <Navigation />
  98. <DetailOrder />
  99. </PrivateRoute>
  100. </Switch>
  101. {isLoading && <Loader />}
  102. <ToastContainer
  103. position="top-right"
  104. autoClose={3000}
  105. hideProgressBar={false}
  106. newestOnTop={false}
  107. closeOnClick
  108. rtl={false}
  109. pauseOnFocusLoss
  110. draggable
  111. pauseOnHover
  112. />
  113. </BrowserRouter>
  114. </Suspense>
  115. </div>
  116. );
  117. }
  118. const mapStateToProps = (state: IAppState) => ({
  119. isLoading: state.isLoading.flag,
  120. });
  121. export default connect(mapStateToProps)(App);