partial fix for #100
This commit is contained in:
@@ -20,7 +20,8 @@ class ValidationView extends React.PureComponent {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
code: props.credCode || ''
|
||||
code: props.credCode || '',
|
||||
codeReceived: false
|
||||
};
|
||||
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
@@ -29,6 +30,24 @@ class ValidationView extends React.PureComponent {
|
||||
this.handleCancel = this.handleCancel.bind(this);
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
if (nextProps.credCode != prevState.code) {
|
||||
return {
|
||||
code: nextProps.credCode || '',
|
||||
codeReceived: !!nextProps.credCode
|
||||
};
|
||||
}
|
||||
|
||||
return prevState;
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
// Submit code audomatically if it's received from the parent.
|
||||
if (this.state.codeReceived && this.state.code != prevState.code) {
|
||||
this.props.onSubmit(this.props.credMethod, this.state.code.trim());
|
||||
}
|
||||
}
|
||||
|
||||
handleChange(e) {
|
||||
this.setState({code: e.target.value});
|
||||
}
|
||||
@@ -53,7 +72,6 @@ class ValidationView extends React.PureComponent {
|
||||
this.props.onCancel();
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
const { formatMessage } = this.props.intl;
|
||||
const methods = {'email': formatMessage(messages.email), 'tel': formatMessage(messages.phone)};
|
||||
|
||||
Reference in New Issue
Block a user