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

37 lines
823 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<
2020-05-24 04:38:24 +05:30
P & {
error?: Error;
},
S & {
error?: Error;
}
> {
2020-05-24 04:38:24 +05:30
componentDidUpdate() {
if (this.state && this.state.error) {
this.setState({
error: undefined,
});
}
}
2020-05-24 04:38:24 +05:30
renderError() {
const error = (this.state && this.state.error) || this.props.error;
2020-05-24 04:38:24 +05:30
return <FormError error={error} />;
}
2020-05-24 04:38:24 +05:30
setError(error: Error) {
// @ts-ignore
this.setState({ error });
}
}