import React from 'react' import PropTypes from 'prop-types' import { Column, Row, Box, Button, BoundInput, BoundButton } from 'ui' import { sizeInfo, colorInfo } from 'ui/style' import { FormBinder } from 'react-form-binder' import autobind from 'autobind-decorator' export class ProfileForm extends React.Component { static propTypes = { user: PropTypes.object.isRequired, onSaved: PropTypes.func.isRequired, onModifiedChanged: PropTypes.func, onChangePassword: PropTypes.func, onChangeEmail: PropTypes.func } static bindings = { email: { isValid: (r, v) => (v !== ''), isDisabled: (r) => (!!r._id) }, firstName: { isValid: (r, v) => (v !== '') }, lastName: { isValid: (r, v) => (v !== '') }, save: { noValue: true, isDisabled: (r) => (!r.anyModified || !r.allValid) } } constructor(props) { super(props) this.state = { binder: new FormBinder( this.props.user, ProfileForm.bindings, this.props.onModifiedChanged) } } componentWillReceiveProps(nextProps) { if (nextProps.user !== this.props.user) { this.setState({ binder: new FormBinder( nextProps.user, ProfileForm.bindings, nextProps.onModifiedChanged) }) } } @autobind handleSubmit(e) { e.preventDefault() let obj = this.state.binder.getValues() if (obj && this.props.onSaved) { this.props.onSaved(obj) } } @autobind handleChangeEmail() { this.props.onChangeEmail(this.state.binder.getFieldValue('email')) } render() { const { binder } = this.state return (