mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Merge pull request #160 from ascribe/add-default-notifications-message
Discard (and log) global notifications that do not have a message specified
This commit is contained in:
commit
26dde8a42c
@ -26,11 +26,13 @@ let CreateEditionsForm = React.createClass({
|
||||
},
|
||||
|
||||
handleSuccess(response) {
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
const { handleSuccess } = this.props;
|
||||
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
if(this.props.handleSuccess) {
|
||||
this.props.handleSuccess(response);
|
||||
if (typeof handleSuccess === 'function') {
|
||||
handleSuccess(response);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1,19 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
export default class GlobalNotificationModel {
|
||||
constructor(message, type = 'info', dismissAfter = 5000) {
|
||||
if(message) {
|
||||
this.message = message;
|
||||
} else {
|
||||
throw new Error('A notifications message must be defined.');
|
||||
constructor(message, type = 'success', dismissAfter = 5000) {
|
||||
if (type !== 'success' && type !== 'danger') {
|
||||
throw new Error(`A notification's type either has to be success, or danger. Not: ${type}`);
|
||||
}
|
||||
|
||||
if(type === 'info' || type === 'success' || type === 'warning' || type === 'danger') {
|
||||
this.type = type;
|
||||
if (message) {
|
||||
this.message = message;
|
||||
} else {
|
||||
throw new Error('A notification\'s type either has to be info, success, warning, danger. Not: ' + type);
|
||||
console.logGlobal(new Error('Global notification did not contain a message and was ignored'), {
|
||||
dismissAfter,
|
||||
type
|
||||
});
|
||||
}
|
||||
|
||||
this.dismissAfter = dismissAfter;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -16,12 +16,14 @@ class GlobalNotificationStore {
|
||||
}
|
||||
|
||||
onAppendGlobalNotification(newNotification) {
|
||||
if (newNotification && newNotification.message) {
|
||||
this.notificationQueue.push(newNotification);
|
||||
|
||||
if (!this.notificationsPaused && this.notificationStatus === 'ready') {
|
||||
this.showNextNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showNextNotification() {
|
||||
this.notificationStatus = 'show';
|
||||
|
Loading…
Reference in New Issue
Block a user