text: import React, {Component} from 'react'
  import {connect} from 'react-redux'
  import {withRouter, Route, Switch, Redirect} from 'react-router-dom'
  import PropTypes from 'prop-types'
  import {me, setCart} from './store'
  import {Login, Signup, AllProducts, Cart, SingleProduct} from './components'
  
  /**
   * COMPONENT
   */
  class Routes extends Component {
    async componentDidMount() {
      await this.props.loadInitialData()
      this.props.setCart(this.props.user.id)
    }
  
    render() {
      return (
        <Switch>
          {/* Routes placed here are available to all visitors */}
          <Route path="/login" component={Login} />
          <Route path="/signup" component={Signup} />
          <Route path="/products/:productId" component={SingleProduct} />
          <Route path="/products" component={AllProducts} />
          <Route path="/cart" component={Cart} />
          <Redirect to="/products" />
          {/* Displays our Login component as a fallback */}
          <Route component={Login} />
        </Switch>
      )
    }
  }
  
  /**
   * CONTAINER
   */
  const mapState = state => {
    return {
      // Being 'logged in' for our purposes will be defined has having a state.user that has a truthy id.
      // Otherwise, state.user will be an empty object, and state.user.id will be falsey
      isLoggedIn: !!state.user.id,
      user: state.user
    }
  }
  
  const mapDispatch = dispatch => {
    return {
      // load user first and then set the cart
      async loadInitialData() {
        await dispatch(me())
      },
      setCart: userId => dispatch(setCart(userId))
    }
  }
  
  // The `withRouter` wrapper makes sure that updates are not blocked
  // when the url changes
  export default withRouter(connect(mapState, mapDispatch)(Routes))
  
  /**
   * PROP TYPES
   */
  Routes.propTypes = {
    loadInitialData: PropTypes.func.isRequired,
    isLoggedIn: PropTypes.bool.isRequired
  }
  