text: import agent from '../agent';
  import Header from './Header';
  import React from 'react';
  import { connect } from 'react-redux';
  import { APP_LOAD, REDIRECT } from '../constants/actionTypes';
  
  const mapStateToProps = state => ({
    appLoaded: state.common.appLoaded,
    appName: state.common.appName,
    currentUser: state.common.currentUser,
    redirectTo: state.common.redirectTo
  });
  
  const mapDispatchToProps = dispatch => ({
    onLoad: (payload, token) =>
      dispatch({ type: APP_LOAD, payload, token, skipTracking: true }),
    onRedirect: () =>
      dispatch({ type: REDIRECT })
  });
  
  class App extends React.Component {
    componentWillReceiveProps(nextProps) {
      if (nextProps.redirectTo) {
        this.context.router.replace(nextProps.redirectTo);
        this.props.onRedirect();
      }
    }
  
    componentWillMount() {
      const token = window.localStorage.getItem('jwt');
      if (token) {
        agent.setToken(token);
      }
  
      this.props.onLoad(token ? agent.Auth.current() : null, token);
    }
  
    render() {
      if (this.props.appLoaded) {
        return (
          <div>
            <Header
              appName={this.props.appName}
              currentUser={this.props.currentUser} />
            {this.props.children}
          </div>
        );
      }
      return (
        <div>
          <Header
            appName={this.props.appName}
            currentUser={this.props.currentUser} />
        </div>
      );
    }
  }
  
  App.contextTypes = {
    router: React.PropTypes.object.isRequired
  };
  
  export default connect(mapStateToProps, mapDispatchToProps)(App);