Handle form errors for email-templates

This commit is contained in:
cyril lopez 2018-01-22 12:25:50 +01:00
parent 46ecdd1e17
commit 2b099e3a2f
2 changed files with 23 additions and 3 deletions

View File

@ -102,13 +102,15 @@ class PopUpForm extends React.Component { // eslint-disable-line react/prefer-st
<Input
autoFocus={key === 0}
key={value}
didCheckErrors={this.props.didCheckErrors}
errors={get(this.props.formErrors, [findIndex(this.props.formErrors, ['name', value]), 'errors'], [])}
label={`users-permissions.PopUpForm.Email.${value}.label`}
name={`${dataToEdit}.${value}`}
onChange={this.props.onChange}
placeholder={`users-permissions.PopUpForm.Email.${value}.placeholder`}
type={includes(value, 'email') ? 'email' : 'text'}
value={get(values, value)}
validations={{}}
validations={value !== 'options.response_email' ? { required: true } : {}}
/>
))}
<div className="col-md-6" />
@ -116,6 +118,8 @@ class PopUpForm extends React.Component { // eslint-disable-line react/prefer-st
<Input
key={value}
customBootstrapClass="col-md-12"
didCheckErrors={this.props.didCheckErrors}
errors={get(this.props.formErrors, [findIndex(this.props.formErrors, ['name', value]), 'errors'], [])}
label={`users-permissions.PopUpForm.Email.${value}.label`}
name={`${dataToEdit}.${value}`}
inputDescription={includes(value, 'object') ? 'users-permissions.PopUpForm.Email.email_templates.inputDescription' : ''}
@ -123,7 +127,7 @@ class PopUpForm extends React.Component { // eslint-disable-line react/prefer-st
onChange={this.props.onChange}
placeholder={`users-permissions.PopUpForm.Email.${this.props.dataToEdit}.${value}.placeholder`}
type={includes(value, 'object') ? 'text' : 'textarea'}
validations={{}}
validations={{ required: true }}
value={get(values, value)}
/>
))}

View File

@ -1,4 +1,4 @@
import { get, isEmpty } from 'lodash';
import { get, isEmpty, isObject } from 'lodash';
export default function checkFormValidity(settingType, data) {
const formErrors = [];
@ -15,6 +15,22 @@ export default function checkFormValidity(settingType, data) {
});
break;
}
case 'email-templates': {
Object.keys(data.options).map((value) => {
if (isObject(data.options[value])) {
Object.keys(data.options[value]).map(subValue => {
if (isEmpty(get(data, ['options', value, subValue]))) {
formErrors.push({ name: `options.${value}.${subValue}`, errors: [{ id: 'components.Input.error.validation.required' }] });
}
});
}
if (value !== 'response_email' && isEmpty(get(data, ['options', value]))) {
formErrors.push({ name: `options.${value}`, errors: [{ id: 'components.Input.error.validation.required' }] });
}
});
break;
}
default:
}