Use different functions for dismissible and non dismissible notices
[MAILPOET-2450]
This commit is contained in:
committed by
Jack Kitterhing
parent
8aef0d3b74
commit
cd3f039958
@@ -4,11 +4,11 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const dismissibleNotices = useSelect(
|
const dismissibleNotices = useSelect(
|
||||||
(select) => select('mailpoet-form-editor').getNotices(true),
|
(select) => select('mailpoet-form-editor').getDismissibleNotices(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const nonDismissibleNotices = useSelect(
|
const nonDismissibleNotices = useSelect(
|
||||||
(select) => select('mailpoet-form-editor').getNotices(),
|
(select) => select('mailpoet-form-editor').getNonDismissibleNotices(),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -20,14 +20,20 @@ export function saveFormDone(result) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addNotice(content, status, isDismissible = false, id = null) {
|
const createAddNoticeAction = (content, status, isDismissible, id) => ({
|
||||||
return {
|
type: 'ADD_NOTICE',
|
||||||
type: 'ADD_NOTICE',
|
content,
|
||||||
content,
|
status,
|
||||||
status,
|
isDismissible,
|
||||||
isDismissible,
|
id,
|
||||||
id,
|
});
|
||||||
};
|
|
||||||
|
export function addNotice(content, status, id) {
|
||||||
|
return createAddNoticeAction(content, status, false, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addDismissibleNotice(content, status, id) {
|
||||||
|
return createAddNoticeAction(content, status, true, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeNotice(id) {
|
export function removeNotice(id) {
|
||||||
|
@@ -11,14 +11,14 @@ export default {
|
|||||||
data: formData,
|
data: formData,
|
||||||
}).done(() => {
|
}).done(() => {
|
||||||
dispatch('mailpoet-form-editor').saveFormDone();
|
dispatch('mailpoet-form-editor').saveFormDone();
|
||||||
dispatch('mailpoet-form-editor').addNotice(MailPoet.I18n.t('formSaved'), 'success', true, 'save-form');
|
dispatch('mailpoet-form-editor').addDismissibleNotice(MailPoet.I18n.t('formSaved'), 'success', 'save-form');
|
||||||
}).fail((response) => {
|
}).fail((response) => {
|
||||||
let errorMessage = null;
|
let errorMessage = null;
|
||||||
if (response.errors.length > 0) {
|
if (response.errors.length > 0) {
|
||||||
errorMessage = response.errors.map((error) => (error.message));
|
errorMessage = response.errors.map((error) => (error.message));
|
||||||
}
|
}
|
||||||
dispatch('mailpoet-form-editor').saveFormDone();
|
dispatch('mailpoet-form-editor').saveFormDone();
|
||||||
dispatch('mailpoet-form-editor').addNotice(errorMessage, 'error', true, 'save-form');
|
dispatch('mailpoet-form-editor').addDismissibleNotice(errorMessage, 'error', 'save-form');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -11,7 +11,10 @@ export default {
|
|||||||
getIsFormSaving(state) {
|
getIsFormSaving(state) {
|
||||||
return state.isFormSaving;
|
return state.isFormSaving;
|
||||||
},
|
},
|
||||||
getNotices(state, dismissible = false) {
|
getDismissibleNotices(state) {
|
||||||
return state.notices.filter((notice) => notice.isDismissible === dismissible);
|
return state.notices.filter((notice) => notice.isDismissible === true);
|
||||||
|
},
|
||||||
|
getNonDismissibleNotices(state) {
|
||||||
|
return state.notices.filter((notice) => notice.isDismissible === false);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user