diff --git a/constants.tsx b/constants.tsx new file mode 100644 index 0000000..46bd710 --- /dev/null +++ b/constants.tsx @@ -0,0 +1,14 @@ +export enum AppRoute { + Login = '/login', + Root = '/', + Favorites = '/favorites', + OfferWithId = '/offer/:id' +} + +export enum AuthorizationStatus { + Auth = 'AUTH', + NoAuth = 'NO_AUTH', + Unknown = 'UNKNOWN', +} + + diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index 7f1478b..d945e28 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -1,4 +1,11 @@ import MainScreen from '../../pages/main'; +import {BrowserRouter, Route, Routes} from 'react-router-dom'; +import NotFound from '../../pages/not_found'; +import Login from '../../pages/login'; +import Offer from '../../pages/offer'; +import {AppRoute, AuthorizationStatus} from '../../../constants'; +import PrivateRoute from '../private-route/private-route'; +import Favorites from '../../pages/favorites'; type AppScreenPros = { offersAmount: number; @@ -6,7 +13,30 @@ type AppScreenPros = { function App({offersAmount}: AppScreenPros): JSX.Element { return ( - + + + } + /> + } + /> + } + /> + } + /> + } + /> + + ); } diff --git a/src/components/private-route/private-route.tsx b/src/components/private-route/private-route.tsx new file mode 100644 index 0000000..ec1a0c6 --- /dev/null +++ b/src/components/private-route/private-route.tsx @@ -0,0 +1,15 @@ +import {Navigate} from 'react-router-dom'; +import {AppRoute, AuthorizationStatus} from '../../../constants'; + +type PrivateRouteProps = { + authorizationStatus: AuthorizationStatus; + children: JSX.Element; +} + +function PrivateRoute({authorizationStatus, children}: PrivateRouteProps): JSX.Element { + return ( + authorizationStatus === AuthorizationStatus.Auth ? children : + ); +} + +export default PrivateRoute; diff --git a/src/index.tsx b/src/index.tsx index a156882..00bb76e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -10,7 +10,6 @@ const offersAmount = 312; root.render( -

Hello, World!

); diff --git a/src/pages/main.tsx b/src/pages/main.tsx index 2bcde38..7c02a35 100644 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -118,17 +118,17 @@ function MainScreen({offersAmount}: MainScreenPros): JSX.Element { {offersAmount} places to stay in Amsterdam
Sort by - + Popular
    -
  • Popular
  • -
  • Price: low to high
  • -
  • Price: high to low
  • -
  • Top rated first
  • +
  • Popular
  • +
  • Price: low to high
  • +
  • Price: high to low
  • +
  • Top rated first
diff --git a/src/pages/not_found.tsx b/src/pages/not_found.tsx new file mode 100644 index 0000000..3d7c1a4 --- /dev/null +++ b/src/pages/not_found.tsx @@ -0,0 +1,14 @@ +import {Link} from 'react-router-dom'; +import {Fragment} from 'react'; + + +function NotFound(): JSX.Element { + return ( + +

404 Not Found

+ Go to main page +
+ ); +} + +export default NotFound;