diff --git a/assets/js/src/form_editor/store/form_validator.jsx b/assets/js/src/form_editor/store/form_validator.jsx index a48604ce6c..731adb4676 100644 --- a/assets/js/src/form_editor/store/form_validator.jsx +++ b/assets/js/src/form_editor/store/form_validator.jsx @@ -1,7 +1,15 @@ -export default (formData) => { +export default (formData, formBlocks) => { const errors = []; if (!formData.settings.segments || formData.settings.segments.length === 0) { 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; }; diff --git a/assets/js/src/form_editor/store/reducers/change_form_settings.jsx b/assets/js/src/form_editor/store/reducers/change_form_settings.jsx index 4053af12e3..81b50679e1 100644 --- a/assets/js/src/form_editor/store/reducers/change_form_settings.jsx +++ b/assets/js/src/form_editor/store/reducers/change_form_settings.jsx @@ -10,6 +10,6 @@ export default (state, action) => { }; return { ...newState, - formErrors: validateForm(newState.formData), + formErrors: validateForm(newState.formData, newState.formBlocks), }; }; diff --git a/assets/js/src/form_editor/store/reducers/save_form_started.jsx b/assets/js/src/form_editor/store/reducers/save_form_started.jsx index 4a0183bbb4..6923aaeb45 100644 --- a/assets/js/src/form_editor/store/reducers/save_form_started.jsx +++ b/assets/js/src/form_editor/store/reducers/save_form_started.jsx @@ -2,7 +2,7 @@ import MailPoet from 'mailpoet'; export default (state) => { // 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 sidebarOpenedPanels = [...state.sidebar.openedPanels]; 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 { ...state, isFormSaving: !hasMissingLists,