add error-message when repeated data is sended in topic-edit-modal component

This commit is contained in:
Guillermo Giuliana 2021-12-13 18:21:12 -03:00
parent fbfbcef21a
commit dd9e269fa5
1 changed files with 10 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import SubmitButton from 'core-components/submit-button';
import IconSelector from 'core-components/icon-selector';
import ColorSelector from 'core-components/color-selector';
import InfoTooltip from 'core-components/info-tooltip';
import Message from 'core-components/message';
class TopicEditModal extends React.Component {
@ -26,7 +27,8 @@ class TopicEditModal extends React.Component {
state = {
values: this.props.defaultValues || {title: '', icon: 'address-card', color: '#ff6900', private: false},
loading: false
loading: false,
errorMessage: false
};
render() {
@ -34,6 +36,7 @@ class TopicEditModal extends React.Component {
<div className="topic-edit-modal">
<Header title={i18n((this.props.addForm) ? 'ADD_TOPIC' : 'EDIT_TOPIC')} description={i18n((this.props.addForm) ? 'ADD_TOPIC_DESCRIPTION' : 'EDIT_TOPIC_DESCRIPTION')} />
<Form values={this.state.values} onChange={this.onFormChange.bind(this)} onSubmit={this.onSubmit.bind(this)} loading={this.state.loading}>
{this.state.errorMessage ? <Message type="error">{i18n(this.state.errorMessage)}</Message> : null}
<FormField name="title" label={i18n('TITLE')} fieldProps={{size: 'large'}} validation="TITLE" required />
<FormField name="icon" className="topic-edit-modal__icon" label={i18n('ICON')} decorator={IconSelector} />
<FormField name="color" className="topic-edit-modal__color" label={i18n('COLOR')} decorator={ColorSelector} />
@ -68,13 +71,16 @@ class TopicEditModal extends React.Component {
}
}).then(() => {
this.context.closeModal();
this.setState({
errorMessage: false
});
if(this.props.onChange) {
this.props.onChange();
}
}).catch(() => {
}).catch((e) => {
this.setState({
loading: false
loading: false,
errorMessage: e.message
});
});
}