import React from "react" import { connect } from "react-redux" import { bindActionCreators } from "redux" import { updateUser } from "../../actions/users" function mapStateToProps(state) { return { polochonToken: state.userStore.get("polochonToken"), polochonUrl: state.userStore.get("polochonUrl"), }; } const mapDispatchToProps = (dispatch) => bindActionCreators({ updateUser }, dispatch) class UserEdit extends React.PureComponent { constructor(props) { super(props); this.state = { polochonToken: props.polochonToken, polochonUrl: props.polochonUrl, }; this.handleSubmit = this.handleSubmit.bind(this); this.handleUrlInput = this.handleUrlInput.bind(this); this.handleTokenInput = this.handleTokenInput.bind(this); } handleSubmit(ev) { ev.preventDefault(); this.props.updateUser({ "polochon_url": this.refs.polochonUrl.value, "polochon_token": this.refs.polochonToken.value, "password": this.refs.newPassword.value, "password_confirm": this.refs.newPasswordConfirm.value, }); } handleTokenInput() { this.setState({ polochonToken: this.refs.polochonToken.value }); } handleUrlInput() { this.setState({ polochonUrl: this.refs.polochonUrl.value }); } componentWillReceiveProps(nextProps) { if ((nextProps.polochonUrl !== "") && (this.state.polochonUrl === "") && (nextProps.polochonToken !== "") && (this.state.polochonToken === "")) { this.setState({ polochonToken: nextProps.polochonToken, polochonUrl: nextProps.polochonUrl, }); } } render() { return (

Edit user


this.handleSubmit(ev)}>

); } } export default connect(mapStateToProps, mapDispatchToProps)(UserEdit);