Add validation of missing obligatory blocks
[MAILPOET-2451]
This commit is contained in:
committed by
Jack Kitterhing
parent
a848731fec
commit
d9295569a2
@@ -1,7 +1,15 @@
|
|||||||
export default (formData) => {
|
export default (formData, formBlocks) => {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
if (!formData.settings.segments || formData.settings.segments.length === 0) {
|
if (!formData.settings.segments || formData.settings.segments.length === 0) {
|
||||||
errors.push('missing-lists');
|
errors.push('missing-lists');
|
||||||
}
|
}
|
||||||
|
const emailInput = formBlocks.filter((block) => (block.attributes.id === 'email'));
|
||||||
|
const submit = formBlocks.filter((block) => (block.attributes.id === 'submit'));
|
||||||
|
if (!emailInput) {
|
||||||
|
errors.push('missing-email-input');
|
||||||
|
}
|
||||||
|
if (!submit) {
|
||||||
|
errors.push('missing-submit');
|
||||||
|
}
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
@@ -10,6 +10,6 @@ export default (state, action) => {
|
|||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
...newState,
|
...newState,
|
||||||
formErrors: validateForm(newState.formData),
|
formErrors: validateForm(newState.formData, newState.formBlocks),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -2,7 +2,7 @@ import MailPoet from 'mailpoet';
|
|||||||
|
|
||||||
export default (state) => {
|
export default (state) => {
|
||||||
// remove all form saving related notices
|
// remove all form saving related notices
|
||||||
const notices = state.notices.filter((notice) => !['save-form', 'missing-lists'].includes(notice.id));
|
const notices = state.notices.filter((notice) => !['save-form', 'missing-lists', 'missing-block'].includes(notice.id));
|
||||||
const hasMissingLists = state.formErrors.includes('missing-lists');
|
const hasMissingLists = state.formErrors.includes('missing-lists');
|
||||||
const sidebarOpenedPanels = [...state.sidebar.openedPanels];
|
const sidebarOpenedPanels = [...state.sidebar.openedPanels];
|
||||||
if (hasMissingLists) {
|
if (hasMissingLists) {
|
||||||
@@ -17,6 +17,17 @@ export default (state) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasMissingEmail = state.formErrors.includes('missing-email-input');
|
||||||
|
const hasMissingSubmit = state.formErrors.includes('missing-submit');
|
||||||
|
if (hasMissingEmail || hasMissingSubmit) {
|
||||||
|
notices.push({
|
||||||
|
id: 'missing-block',
|
||||||
|
content: MailPoet.I18n.t('missingObligatoryBlock'),
|
||||||
|
isDismissible: true,
|
||||||
|
status: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
isFormSaving: !hasMissingLists,
|
isFormSaving: !hasMissingLists,
|
||||||
|
Reference in New Issue
Block a user