Skip to main content

19.2 Fixing the Redirect to the Frontpage

SideDrawer.js

src\components\Navigation\SideDrawer\SideDrawer.js
import React, { Fragment } from "react";
import Logo from "../../Logo/Logo";
import Backdrop from "../../UI/Backdrop/Backdrop";
import NavigationItems from "../NavigationItems/NavigationItems";
import classes from "./SideDrawer.module.css";

const sideDrawer = (props) => {
let attachedClasses = [classes.SideDrawer, classes.Close];
if (props.open) {
attachedClasses = [classes.SideDrawer, classes.Open];
}
return (
<Fragment>
<Backdrop show={props.open} clicked={props.closed} />
<div className={attachedClasses.join(" ")} onClick={props.closed}>
<div className={classes.Logo}>
<Logo />
</div>
<nav>
<NavigationItems isAuthenticated={props.isAuth} />
</nav>
</div>
</Fragment>
);
};

export default sideDrawer;

CheckoutSummary.module.css

src\components\Order\CheckoutSummary\CheckoutSummary.module.css
.CheckoutSummary {
text-align: center;
width: 80%;
margin: auto;
}

App.js

src\App.js
import React, { Component } from "react";
import { connect } from "react-redux";
import { Redirect, Route, Switch, withRouter } from "react-router-dom";
import Layout from "./components/Layout/Layout";
import Auth from "./containers/Auth/Auth";
import Logout from "./containers/Auth/Logout/Logout";
import BurgerBuilder from "./containers/BurgerBuilder/BurgerBuilder";
import Checkout from "./containers/Checkout/Checkout";
import Orders from "./containers/Orders/Orders";
import * as actions from "./store/actions/index";

class App extends Component {
componentDidMount() {
this.props.onTryAutoSignup();
}
render() {
let routes = (
<Switch>
<Route path="/auth" component={Auth} />
<Route path="/" exact component={BurgerBuilder} />
<Redirect to="/" />
</Switch>
);

if (this.props.isAuthenticated) {
routes = (
<Switch>
<Route path="/checkout" component={Checkout} />
<Route path="/orders" component={Orders} />
<Route path="/logout" component={Logout} />
<Route path="/auth" component={Auth} />
<Route path="/" exact component={BurgerBuilder} />
<Redirect to="/" />
</Switch>
);
}

return (
<div>
<Layout>{routes}</Layout>
</div>
);
}
}

const mapStatetoProps = (state) => {
return {
isAuthenticated: state.auth.token !== null,
};
};

const mapDispatchtoProps = (dispatch) => {
return {
onTryAutoSignup: () => dispatch(actions.authCheckState()),
};
};

export default withRouter(connect(mapStatetoProps, mapDispatchtoProps)(App));