2017-08-23 00:19:50 +05:30
|
|
|
import React from 'react';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { MessageDescriptor } from 'react-intl';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
|
|
|
import FormComponent from './FormComponent';
|
2016-07-28 09:55:02 +05:30
|
|
|
import FormError from './FormError';
|
2019-12-08 03:23:22 +05:30
|
|
|
import { ValidationError } from './FormModel';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-12-08 03:23:22 +05:30
|
|
|
type Error = ValidationError | MessageDescriptor;
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default class FormInputComponent<P, S = {}> extends FormComponent<
|
2020-05-24 04:38:24 +05:30
|
|
|
P & {
|
|
|
|
error?: Error;
|
|
|
|
},
|
|
|
|
S & {
|
|
|
|
error?: Error;
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
> {
|
2020-05-24 04:38:24 +05:30
|
|
|
componentDidUpdate() {
|
|
|
|
if (this.state && this.state.error) {
|
|
|
|
this.setState({
|
|
|
|
error: undefined,
|
|
|
|
});
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
}
|
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
renderError() {
|
|
|
|
const error = (this.state && this.state.error) || this.props.error;
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return <FormError error={error} />;
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
setError(error: Error) {
|
|
|
|
// @ts-ignore
|
|
|
|
this.setState({ error });
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
}
|