2018-04-19 01:19:10 +05:30
|
|
|
// @flow
|
|
|
|
import type { MessageDescriptor } from 'react-intl';
|
2017-08-23 00:19:50 +05:30
|
|
|
import React from 'react';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
|
|
|
import FormComponent from './FormComponent';
|
2016-07-28 09:55:02 +05:30
|
|
|
import FormError from './FormError';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2018-04-19 01:19:10 +05:30
|
|
|
type Error = string | MessageDescriptor;
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2018-04-19 01:19:10 +05:30
|
|
|
export default class FormInputComponent<P, S = void> extends FormComponent<P & {
|
|
|
|
error?: Error,
|
|
|
|
}, S & {
|
|
|
|
error?: Error,
|
|
|
|
}> {
|
2016-05-02 14:50:50 +05:30
|
|
|
componentWillReceiveProps() {
|
|
|
|
if (this.state && this.state.error) {
|
|
|
|
Reflect.deleteProperty(this.state, 'error');
|
|
|
|
|
|
|
|
this.setState(this.state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError() {
|
|
|
|
const error = this.state && this.state.error || this.props.error;
|
|
|
|
|
2016-07-28 09:55:02 +05:30
|
|
|
return <FormError error={error} />;
|
2016-05-02 14:50:50 +05:30
|
|
|
}
|
|
|
|
|
2018-04-19 01:19:10 +05:30
|
|
|
setError(error: Error) {
|
2016-05-02 14:50:50 +05:30
|
|
|
this.setState({error});
|
|
|
|
}
|
|
|
|
}
|