2017-08-22 21:49:50 +03:00
|
|
|
import React from 'react';
|
2019-12-07 13:28:52 +02:00
|
|
|
import { MessageDescriptor } from 'react-intl';
|
2016-05-02 12:20:50 +03:00
|
|
|
|
|
|
|
import FormComponent from './FormComponent';
|
2016-07-28 07:25:02 +03:00
|
|
|
import FormError from './FormError';
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2018-04-18 22:49:10 +03:00
|
|
|
type Error = string | MessageDescriptor;
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
export default class FormInputComponent<P, S = {}> extends FormComponent<
|
2019-11-27 11:03:32 +02:00
|
|
|
P & {
|
2019-12-07 13:28:52 +02:00
|
|
|
error?: Error;
|
2019-11-27 11:03:32 +02:00
|
|
|
},
|
|
|
|
S & {
|
2019-12-07 13:28:52 +02:00
|
|
|
error?: Error;
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
> {
|
|
|
|
componentWillReceiveProps() {
|
|
|
|
if (this.state && this.state.error) {
|
|
|
|
Reflect.deleteProperty(this.state, 'error');
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
this.setState(this.state);
|
2016-05-02 12:20:50 +03:00
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
}
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
renderError() {
|
|
|
|
const error = (this.state && this.state.error) || this.props.error;
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
return <FormError error={error} />;
|
|
|
|
}
|
2016-05-02 12:20:50 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
setError(error: Error) {
|
2019-12-07 13:28:52 +02:00
|
|
|
// @ts-ignore
|
2019-11-27 11:03:32 +02:00
|
|
|
this.setState({ error });
|
|
|
|
}
|
2016-05-02 12:20:50 +03:00
|
|
|
}
|