|
@@ -1,53 +1,30 @@
|
|
|
import React, { PureComponent } from 'react';
|
|
import React, { PureComponent } from 'react';
|
|
|
import appEvents from 'app/core/app_events';
|
|
import appEvents from 'app/core/app_events';
|
|
|
-import { addAppNotification, clearAppNotification } from '../../actions/appNotification';
|
|
|
|
|
|
|
+import AppNotificationItem from './AppNotificationItem';
|
|
|
|
|
+import { notifyApp, clearAppNotification } from 'app/core/actions';
|
|
|
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
|
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
|
|
-import { AppNotification, AppNotificationSeverity, StoreState } from 'app/types';
|
|
|
|
|
|
|
+import { AppNotification, StoreState } from 'app/types';
|
|
|
|
|
+import {
|
|
|
|
|
+ createErrorNotification,
|
|
|
|
|
+ createSuccessNotification,
|
|
|
|
|
+ createWarningNotification,
|
|
|
|
|
+} from '../../copy/appNotification';
|
|
|
|
|
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
appNotifications: AppNotification[];
|
|
appNotifications: AppNotification[];
|
|
|
- addAppNotification: typeof addAppNotification;
|
|
|
|
|
|
|
+ notifyApp: typeof notifyApp;
|
|
|
clearAppNotification: typeof clearAppNotification;
|
|
clearAppNotification: typeof clearAppNotification;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class AppNotificationList extends PureComponent<Props> {
|
|
export class AppNotificationList extends PureComponent<Props> {
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- appEvents.on('alert-warning', options => this.addAppNotification(options[0], options[1], 'warning', 5000));
|
|
|
|
|
- appEvents.on('alert-success', options => this.addAppNotification(options[0], options[1], 'success', 3000));
|
|
|
|
|
- appEvents.on('alert-error', options => this.addAppNotification(options[0], options[1], 'error', 7000));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- addAppNotification(title, text, severity, timeout) {
|
|
|
|
|
- const id = Date.now();
|
|
|
|
|
- const newAlert = {
|
|
|
|
|
- id: id,
|
|
|
|
|
- title: title || '',
|
|
|
|
|
- text: text || '',
|
|
|
|
|
- severity: severity || AppNotificationSeverity.Info,
|
|
|
|
|
- icon: this.getIconForSeverity(severity),
|
|
|
|
|
- remove: this.clearAutomatically(id, timeout),
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- this.props.addAppNotification(newAlert);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const { notifyApp } = this.props;
|
|
|
|
|
|
|
|
- getIconForSeverity(severity) {
|
|
|
|
|
- switch (severity) {
|
|
|
|
|
- case AppNotificationSeverity.Success:
|
|
|
|
|
- return 'fa fa-check';
|
|
|
|
|
- case AppNotificationSeverity.Error:
|
|
|
|
|
- return 'fa fa-exclamation-triangle';
|
|
|
|
|
- default:
|
|
|
|
|
- return 'fa fa-exclamation';
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ appEvents.on('alert-warning', options => notifyApp(createWarningNotification(options[0], options[1])));
|
|
|
|
|
+ appEvents.on('alert-success', options => notifyApp(createSuccessNotification(options[0], options[1])));
|
|
|
|
|
+ appEvents.on('alert-error', options => notifyApp(createErrorNotification(options[0], options[1])));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- clearAutomatically = (id, timeout) => {
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- this.props.clearAppNotification(id);
|
|
|
|
|
- }, timeout);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
onClearAppNotification = id => {
|
|
onClearAppNotification = id => {
|
|
|
this.props.clearAppNotification(id);
|
|
this.props.clearAppNotification(id);
|
|
|
};
|
|
};
|
|
@@ -59,22 +36,11 @@ export class AppNotificationList extends PureComponent<Props> {
|
|
|
<div>
|
|
<div>
|
|
|
{appNotifications.map((appNotification, index) => {
|
|
{appNotifications.map((appNotification, index) => {
|
|
|
return (
|
|
return (
|
|
|
- <div key={index} className={`alert-${appNotification.severity} alert`}>
|
|
|
|
|
- <div className="alert-icon">
|
|
|
|
|
- <i className={appNotification.icon} />
|
|
|
|
|
- </div>
|
|
|
|
|
- <div className="alert-body">
|
|
|
|
|
- <div className="alert-title">{appNotification.title}</div>
|
|
|
|
|
- <div className="alert-text">{appNotification.text}</div>
|
|
|
|
|
- </div>
|
|
|
|
|
- <button
|
|
|
|
|
- type="button"
|
|
|
|
|
- className="alert-close"
|
|
|
|
|
- onClick={() => this.onClearAppNotification(appNotification.id)}
|
|
|
|
|
- >
|
|
|
|
|
- <i className="fa fa fa-remove" />
|
|
|
|
|
- </button>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <AppNotificationItem
|
|
|
|
|
+ key={`${appNotification.id}-${index}`}
|
|
|
|
|
+ appNotification={appNotification}
|
|
|
|
|
+ onClearNotification={id => this.onClearAppNotification(id)}
|
|
|
|
|
+ />
|
|
|
);
|
|
);
|
|
|
})}
|
|
})}
|
|
|
</div>
|
|
</div>
|
|
@@ -87,7 +53,7 @@ const mapStateToProps = (state: StoreState) => ({
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
const mapDispatchToProps = {
|
|
|
- addAppNotification,
|
|
|
|
|
|
|
+ notifyApp,
|
|
|
clearAppNotification,
|
|
clearAppNotification,
|
|
|
};
|
|
};
|
|
|
|
|
|