Add missing list check and error notices
[MAILPOET-2455]
This commit is contained in:
committed by
Jack Kitterhing
parent
e53c58201b
commit
8d0ed7a084
@ -26,6 +26,11 @@ export default () => {
|
||||
[]
|
||||
);
|
||||
|
||||
const missingListError = useSelect(
|
||||
(select) => select('mailpoet-form-editor').getNotice('missing-lists'),
|
||||
[]
|
||||
);
|
||||
|
||||
const { changeFormSettings } = useDispatch('mailpoet-form-editor');
|
||||
|
||||
const onSegmentsChange = (e) => {
|
||||
@ -59,10 +64,17 @@ export default () => {
|
||||
const selectedSegments = settings.segments
|
||||
? segments.filter((seg) => (settings.segments.includes(seg.id.toString())))
|
||||
: [];
|
||||
const shouldDisplayMissingListError = missingListError && !selectedSegments.length;
|
||||
return (
|
||||
<Panel>
|
||||
<PanelBody title={MailPoet.I18n.t('formSettings')}>
|
||||
<BaseControl label={MailPoet.I18n.t('settingsListLabel')}>
|
||||
<BaseControl
|
||||
label={MailPoet.I18n.t('settingsListLabel')}
|
||||
className={shouldDisplayMissingListError ? 'mailpoet-form-missing-lists' : null}
|
||||
>
|
||||
{shouldDisplayMissingListError ? (
|
||||
<span className="mailpoet-form-lists-error">{MailPoet.I18n.t('settingsPleaseSelectList')}</span>
|
||||
) : null }
|
||||
<Selection
|
||||
item={{
|
||||
segments: selectedSegments,
|
||||
|
@ -6,9 +6,14 @@ export default {
|
||||
if (select('mailpoet-form-editor').getIsFormSaving()) {
|
||||
return;
|
||||
}
|
||||
dispatch('mailpoet-form-editor').saveFormStarted();
|
||||
const formData = select('mailpoet-form-editor').getFormData();
|
||||
dispatch('mailpoet-form-editor').removeNotice('save-form');
|
||||
const formData = select('mailpoet-form-editor').getFormData();
|
||||
if (!formData.settings.segments || formData.settings.segments.length === 0) {
|
||||
dispatch('mailpoet-form-editor').addDismissibleNotice(MailPoet.I18n.t('settingsPleaseSelectList'), 'error', 'missing-lists');
|
||||
return;
|
||||
}
|
||||
dispatch('mailpoet-form-editor').saveFormStarted();
|
||||
dispatch('mailpoet-form-editor').removeNotice('missing-lists');
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'forms',
|
||||
|
@ -32,4 +32,7 @@ export default {
|
||||
getNonDismissibleNotices(state) {
|
||||
return state.notices.filter((notice) => notice.isDismissible === false);
|
||||
},
|
||||
getNotice(state, id) {
|
||||
return state.notices.find((notice) => notice.id === id);
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user