accounts-frontend/packages/app/components/ui/form/FormInputComponent.tsx

37 lines
751 B
TypeScript
Raw Normal View History

import React from 'react';
2019-12-07 16:58:52 +05:30
import { MessageDescriptor } from 'react-intl';
import FormComponent from './FormComponent';
import FormError from './FormError';
2019-12-08 03:23:22 +05:30
import { ValidationError } from './FormModel';
2019-12-08 03:23:22 +05:30
type Error = ValidationError | MessageDescriptor;
2019-12-07 16:58:52 +05:30
export default class FormInputComponent<P, S = {}> extends FormComponent<
P & {
2019-12-07 16:58:52 +05:30
error?: Error;
},
S & {
2019-12-07 16:58:52 +05:30
error?: Error;
}
> {
2019-12-10 13:17:32 +05:30
componentDidUpdate() {
if (this.state && this.state.error) {
2019-12-10 13:17:32 +05:30
this.setState({
error: undefined,
});
}
}
renderError() {
const error = (this.state && this.state.error) || this.props.error;
return <FormError error={error} />;
}
setError(error: Error) {
2019-12-07 16:58:52 +05:30
// @ts-ignore
this.setState({ error });
}
}