import React from 'react' import ReactDOM from 'react-dom' import { getClientKey } from 'boost/activityRecord' import linkState from 'boost/linkState' import _ from 'lodash' import { request, WEB_URL } from 'boost/api' const FORM_MODE = 'FORM_MODE' const DONE_MODE = 'DONE_MODE' export default class ContactTab extends React.Component { constructor (props) { super(props) this.state = { title: '', content: '', email: '', mode: FORM_MODE, alert: null } } componentDidMount () { let titleInput = ReactDOM.findDOMNode(this.refs.title) if (titleInput != null) titleInput.focus() } handleBackButtonClick (e) { this.setState({ mode: FORM_MODE }) } handleSendButtonClick (e) { let input = _.pick(this.state, ['title', 'content', 'email']) input.clientKey = getClientKey() this.setState({ alert: { type: 'info', message: 'Sending...' } }, () => { request.post(WEB_URL + 'apis/inquiry') .send(input) .then(res => { console.log('sent') this.setState({ title: '', content: '', mode: DONE_MODE, alert: null }) }) .catch(err => { if (err.code === 'ECONNREFUSED') { this.setState({ alert: { type: 'error', message: 'Can\'t connect to API server.' } }) } else { console.error(err) this.setState({ alert: { type: 'error', message: err.message } }) } }) }) } render () { switch (this.state.mode) { case DONE_MODE: return (