Add missing list check and error notices
[MAILPOET-2455]
This commit is contained in:
committed by
Jack Kitterhing
parent
e53c58201b
commit
8d0ed7a084
@ -25,3 +25,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mailpoet-form-missing-lists {
|
||||||
|
.select2-selection {
|
||||||
|
border-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mailpoet-form-lists-error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,6 +26,11 @@ export default () => {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const missingListError = useSelect(
|
||||||
|
(select) => select('mailpoet-form-editor').getNotice('missing-lists'),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const { changeFormSettings } = useDispatch('mailpoet-form-editor');
|
const { changeFormSettings } = useDispatch('mailpoet-form-editor');
|
||||||
|
|
||||||
const onSegmentsChange = (e) => {
|
const onSegmentsChange = (e) => {
|
||||||
@ -59,10 +64,17 @@ export default () => {
|
|||||||
const selectedSegments = settings.segments
|
const selectedSegments = settings.segments
|
||||||
? segments.filter((seg) => (settings.segments.includes(seg.id.toString())))
|
? segments.filter((seg) => (settings.segments.includes(seg.id.toString())))
|
||||||
: [];
|
: [];
|
||||||
|
const shouldDisplayMissingListError = missingListError && !selectedSegments.length;
|
||||||
return (
|
return (
|
||||||
<Panel>
|
<Panel>
|
||||||
<PanelBody title={MailPoet.I18n.t('formSettings')}>
|
<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
|
<Selection
|
||||||
item={{
|
item={{
|
||||||
segments: selectedSegments,
|
segments: selectedSegments,
|
||||||
|
@ -6,9 +6,14 @@ export default {
|
|||||||
if (select('mailpoet-form-editor').getIsFormSaving()) {
|
if (select('mailpoet-form-editor').getIsFormSaving()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dispatch('mailpoet-form-editor').saveFormStarted();
|
|
||||||
const formData = select('mailpoet-form-editor').getFormData();
|
|
||||||
dispatch('mailpoet-form-editor').removeNotice('save-form');
|
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({
|
MailPoet.Ajax.post({
|
||||||
api_version: window.mailpoet_api_version,
|
api_version: window.mailpoet_api_version,
|
||||||
endpoint: 'forms',
|
endpoint: 'forms',
|
||||||
|
@ -32,4 +32,7 @@ export default {
|
|||||||
getNonDismissibleNotices(state) {
|
getNonDismissibleNotices(state) {
|
||||||
return state.notices.filter((notice) => notice.isDismissible === false);
|
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