import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import { Link } from 'react-router' import ReactGA from 'react-ga' import Modal from './Modal'; import Icon from '../../components/Icon'; import * as pusherActions from '../../services/pusher/actions'; import * as uiActions from '../../services/ui/actions'; import * as helpers from '../../helpers'; class EditCommand extends React.Component{ constructor(props){ super(props) this.state = { id: helpers.generateGuid(), icon: 'power_settings_new', command: '{"url":"https://myserver.local:8080/sendCommand/power"}' } } componentDidMount(){ if (this.props.command){ this.props.uiActions.setWindowTitle("Edit command"); this.setState(this.props.command); } else { this.props.uiActions.setWindowTitle("Create command"); } } handleSubmit(e){ e.preventDefault(); this.props.pusherActions.setCommand({ id: this.state.id, icon: this.state.icon, command: this.state.command }); window.history.back(); return false; } render(){ return (

Create command

this.handleSubmit(e)}>
Icon
this.setState({ icon: e.target.value })} />
Material icon, see docs
Command
Ajax configuration (JSON string)
) } } const mapStateToProps = (state, ownProps) => { var id = ownProps.params.id; return { command: (id && state.pusher.commands && state.pusher.commands[id] !== undefined ? state.pusher.commands[id] : null) } } const mapDispatchToProps = (dispatch) => { return { pusherActions: bindActionCreators(pusherActions, dispatch), uiActions: bindActionCreators(uiActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(EditCommand)