#100: form loading state for profile

This commit is contained in:
SleepWalker
2016-05-27 23:04:17 +03:00
parent 808f239286
commit c51bd17259
9 changed files with 78 additions and 18 deletions

View File

@@ -29,19 +29,42 @@ export default class Form extends Component {
};
state = {
isTouched: false
isTouched: false,
isLoading: this.props.isLoading || false
};
componentWillMount() {
if (this.props.form) {
this.props.form.addLoadingListener(this.onLoading);
}
}
componentWillReceiveProps(nextProps) {
if (nextProps.id !== this.props.id) {
this.setState({
isTouched: false
});
}
if (typeof nextProps.isLoading !== 'undefined') {
this.setState({
isLoading: nextProps.isLoading
});
}
if (nextProps.form && nextProps.form !== this.props.form) {
throw new Error('The FormModel instance should not be changed during component lifetime');
}
}
componentWillUnmount() {
if (this.props.form) {
this.props.form.removeLoadingListener(this.onLoading);
}
}
render() {
const {isLoading} = this.props;
const {isLoading} = this.state;
return (
<form
@@ -100,4 +123,6 @@ export default class Form extends Component {
this.props.onInvalid(errors);
}
};
onLoading = (isLoading) => this.setState({isLoading});
}