import AlertErrorIcon from '../../../components/icons-components/AlertErrorIcon';
import AlertSuccessIcon from '../../../components/icons-components/AlertSuccessIcon';
import { translateWithParameters, translate } from '../../../helpers/l10n';
-import { resetValue, saveValue } from '../store/actions';
+import { resetValue, saveValue, checkValue } from '../store/actions';
import { passValidation } from '../store/settingsPage/validationMessages/actions';
import { cancelChange, changeValue } from '../store/settingsPage/changedValues/actions';
import { TYPE_PASSWORD } from '../constants';
};
state = {
- success: false
+ success: false,
+ hasError: false
};
componentDidMount() {
this.props.changeValue(this.props.setting.definition.key, value);
if (this.props.setting.definition.type === TYPE_PASSWORD) {
this.handleSave();
+ } else {
+ this.handleCheck();
}
};
return this.props
.resetValue(definition.key, componentKey)
.then(() => {
- this.safeSetState({ success: true });
+ this.props.changeValue(definition.key, definition.defaultValue);
+ this.safeSetState({ success: true, hasError: false });
this.timeout = setTimeout(() => this.safeSetState({ success: false }), 3000);
})
.catch(() => {
this.props.passValidation(this.props.setting.definition.key);
};
+ handleCheck = () => {
+ this.safeSetState({ success: false });
+ const componentKey = this.props.component ? this.props.component.key : null;
+ if (this.props.checkValue(this.props.setting.definition.key, componentKey)) {
+ this.safeSetState({ hasError: false });
+ } else {
+ this.safeSetState({ hasError: true });
+ }
+ };
+
handleSave = () => {
if (this.props.changedValue != null) {
this.safeSetState({ success: false });
render() {
const { setting, changedValue, loading } = this.props;
+ const { hasError } = this.state;
const { definition } = setting;
const propertyName = getPropertyName(definition);
value={effectiveValue}
/>
- {!hasValueChanged && (
+ {(!hasValueChanged || hasError) && (
<DefinitionDefaults
isDefault={isDefault}
onReset={this.handleReset}
/>
)}
- {hasValueChanged && (
- <DefinitionChanges onCancel={this.handleCancel} onSave={this.handleSave} />
- )}
+ {hasValueChanged &&
+ !hasError && (
+ <DefinitionChanges onCancel={this.handleCancel} onSave={this.handleSave} />
+ )}
</div>
</div>
);
saveValue,
resetValue,
passValidation,
- cancelChange
+ cancelChange,
+ checkValue
})(Definition);
() => {}
);
+export const checkValue = (key, componentKey) => (dispatch, getState) => {
+ const state = getState();
+ const definition = getSettingsAppDefinition(state, key);
+ const value = getSettingsAppChangedValue(state, key);
+
+ if (isEmptyValue(definition, value)) {
+ if (definition.defaultValue === undefined) {
+ dispatch(failValidation(key, translate('settings.state.value_cant_be_empty_no_default')));
+ } else {
+ dispatch(failValidation(key, translate('settings.state.value_cant_be_empty')));
+ }
+ return false;
+ }
+
+ dispatch(passValidation(key));
+ return true;
+};
+
export const saveValue = (key, componentKey) => (dispatch, getState) => {
dispatch(startLoading(key));