2017-06-21 23:31:59 +00:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { closeNotification } from 'actions/notifications';
|
|
|
|
import type { Notification } from 'actions/notifications';
|
|
|
|
|
2017-06-22 21:16:21 +00:00
|
|
|
class NotificationRow extends React.Component {
|
2017-07-04 03:28:56 +00:00
|
|
|
props: {
|
|
|
|
notification: Notification,
|
|
|
|
onClose: (n: Notification) => void
|
|
|
|
};
|
|
|
|
render() {
|
|
|
|
const { msg, level } = this.props.notification;
|
|
|
|
let className = '';
|
2017-06-22 21:16:21 +00:00
|
|
|
|
2017-07-04 03:28:56 +00:00
|
|
|
switch (level) {
|
|
|
|
case 'danger':
|
|
|
|
className = 'alert-danger';
|
|
|
|
break;
|
|
|
|
case 'success':
|
|
|
|
className = 'alert-success';
|
|
|
|
break;
|
|
|
|
case 'warning':
|
|
|
|
className = 'alert-warning';
|
|
|
|
break;
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 03:28:56 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`alert popup ${className} animated-show-hide`}
|
|
|
|
role="alert"
|
|
|
|
aria-live="assertive"
|
|
|
|
>
|
|
|
|
<span className="sr-only">{level}</span>
|
|
|
|
<div className="container" dangerouslySetInnerHTML={{ __html: msg }} />
|
|
|
|
<i
|
|
|
|
tabIndex="0"
|
|
|
|
aria-label="dismiss"
|
|
|
|
className="icon-close"
|
|
|
|
onClick={this.onClose}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
this.props.onClose(this.props.notification);
|
|
|
|
};
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Notifications extends React.Component {
|
2017-07-04 03:28:56 +00:00
|
|
|
props: {
|
|
|
|
notifications: Notification[],
|
|
|
|
closeNotification: (n: Notification) => void
|
|
|
|
};
|
|
|
|
render() {
|
|
|
|
if (!this.props.notifications.length) {
|
|
|
|
return null;
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
2017-07-04 03:28:56 +00:00
|
|
|
return (
|
|
|
|
<div className="alerts-container">
|
|
|
|
{this.props.notifications.map((n, i) =>
|
|
|
|
<NotificationRow
|
|
|
|
key={`${n.level}-${i}`}
|
|
|
|
notification={n}
|
|
|
|
onClose={this.props.closeNotification}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-21 23:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-07-04 03:28:56 +00:00
|
|
|
notifications: state.notifications
|
2017-06-21 23:31:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, { closeNotification })(Notifications);
|