Add unique custom field name checking
[MAILPOET-2463]
This commit is contained in:
committed by
Pavel Dohnal
parent
f88ac20fbd
commit
64c4e3f35b
@@ -75,9 +75,10 @@ export function createCustomFieldDone(response) {
|
||||
};
|
||||
}
|
||||
|
||||
export function createCustomFieldStarted() {
|
||||
export function createCustomFieldStarted(customField) {
|
||||
return {
|
||||
type: 'CREATE_CUSTOM_FIELD_STARTED',
|
||||
customField,
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -68,7 +68,14 @@ export default {
|
||||
},
|
||||
|
||||
CREATE_CUSTOM_FIELD(action) {
|
||||
dispatch('mailpoet-form-editor').createCustomFieldStarted();
|
||||
if (select('mailpoet-form-editor').getIsCustomFieldCreating()) {
|
||||
return;
|
||||
}
|
||||
dispatch('mailpoet-form-editor').createCustomFieldStarted(action.data);
|
||||
// Check if it really started. Could been blocked by an error.
|
||||
if (!select('mailpoet-form-editor').getIsCustomFieldCreating()) {
|
||||
return;
|
||||
}
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'customFields',
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import MailPoet from 'mailpoet';
|
||||
import createCustomFieldDone from './reducers/create_custom_field_done.jsx';
|
||||
import createCustomFieldFailed from './reducers/create_custom_field_failed.jsx';
|
||||
import createCustomFieldStarted from './reducers/create_custom_field_started.jsx';
|
||||
import createCustomFieldStartedFactory from './reducers/create_custom_field_started.jsx';
|
||||
import changeFormName from './reducers/change_form_name.jsx';
|
||||
import changeFormSettings from './reducers/change_form_settings.jsx';
|
||||
import changeFormStyles from './reducers/change_form_styles.jsx';
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
customFieldDeleteFailed,
|
||||
} from './reducers/custom_field_delete.jsx';
|
||||
|
||||
const createCustomFieldStarted = createCustomFieldStartedFactory(MailPoet);
|
||||
const saveFormStarted = saveFormStartedFactory(MailPoet);
|
||||
|
||||
export default (defaultState) => (state = defaultState, action) => {
|
||||
|
@@ -1,8 +1,20 @@
|
||||
export default (state) => {
|
||||
import { trim } from 'lodash';
|
||||
|
||||
export default (MailPoet) => (state, action) => {
|
||||
const notices = state.notices.filter((notice) => notice.id !== 'custom-field');
|
||||
const fieldName = trim(action.customField.name);
|
||||
const duplicity = state.customFields.find((field) => (field.name === fieldName));
|
||||
if (duplicity) {
|
||||
notices.push({
|
||||
id: 'custom-field',
|
||||
content: MailPoet.I18n.t('customFieldWithNameExists').replace('[name]', fieldName),
|
||||
isDismissible: true,
|
||||
status: 'error',
|
||||
});
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
isCustomFieldCreating: true,
|
||||
isCustomFieldCreating: !duplicity,
|
||||
notices,
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user