const mapStateToProps = (state) => {
  return {
    account: getAccount(state),
    cart: getCart(state),
    authenticityToken: getAuthenticityToken(state)
  }
}
  return (dispatch, getState) => {
    dispatch(loginRequest())

    const authenticityToken = getAuthenticityToken(getState()).authenticityToken

    let formData = new FormData()
    formData.append('spree_user[email]', email)
    formData.append('spree_user[password]', password)

    return fetch(
      Routes.spree_create_new_session_path({format: 'js'}),
      {
        method: 'post',
        credentials: 'same-origin',
        headers: {
          'X-CSRF-Token': authenticityToken
        },
        body: formData
      }
    )
      .then(api.checkStatus)
      .then(api.parseJSON)
      .then(json => {
        dispatch(loginSuccess(json))
        dispatch(fetchAccount())
      })
      .catch(error => dispatch(loginFailure(error)))
  }