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

27 lines
610 B
TypeScript
Raw Normal View History

import React from 'react';
2019-12-07 13:28:52 +02:00
import { MessageDescriptor } from 'react-intl';
import FormComponent from './FormComponent';
import FormError from './FormError';
2019-12-07 23:53:22 +02:00
import { ValidationError } from './FormModel';
2019-12-07 23:53:22 +02:00
type Error = ValidationError | MessageDescriptor;
2019-12-07 13:28:52 +02:00
export default class FormInputComponent<P, S = {}> extends FormComponent<
2020-05-24 02:08:24 +03:00
P & {
error?: Error;
},
S & {
error?: Error;
}
> {
2020-05-24 02:08:24 +03:00
renderError() {
return <FormError error={this.state?.error || this.props.error} />;
2020-05-24 02:08:24 +03:00
}
2020-05-24 02:08:24 +03:00
setError(error: Error) {
// @ts-ignore
this.setState({ error });
}
}