import React, { PropTypes } from 'react' import { Link } from 'react-router' import linkState from 'boost/linkState' import { login } from 'boost/api' export default class LoginPage extends React.Component { constructor (props) { super(props) this.state = { user: {}, isSending: false, error: null } this.linkState = linkState } handleSubmit (e) { e.preventDefault() this.setState({ isSending: true, error: null }, function () { login(this.state.user) .then(function (res) { localStorage.setItem('token', res.body.token) localStorage.setItem('currentUser', JSON.stringify(res.body.user)) try { this.props.history.pushState('home') } catch (e) { console.error(e) } }.bind(this)) .catch(function (err) { console.error(err) if (err.response == null) { return this.setState({ error: {name: 'CunnectionRefused', message: 'Can\'t connect to API server.'}, isSending: false }) } // Connection Failed or Whatever this.setState({ error: err.response.body, isSending: false }) }.bind(this)) }) } render () { return (