MyCrypto/common/containers/App/Notifications.jsx

79 lines
2.2 KiB
React
Raw Normal View History

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 {
props: {
notification: Notification,
onClose: (n: Notification) => void
};
render() {
const { msg, level } = this.props.notification;
let className = '';
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-06-22 21:16:21 +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>
);
2017-06-21 23:31:59 +00:00
}
2017-06-22 21:16:21 +00:00
onClose = () => {
this.props.onClose(this.props.notification);
};
2017-06-21 23:31:59 +00:00
}
export class Notifications extends React.Component {
props: {
notifications: Notification[],
closeNotification: (n: Notification) => void
};
render() {
if (!this.props.notifications.length) {
return null;
}
return (
<div className="alerts-container">
{this.props.notifications.map((n, i) =>
2017-06-22 21:16:21 +00:00
<NotificationRow
key={`${n.level}-${i}`}
notification={n}
onClose={this.props.closeNotification}
/>
2017-06-21 23:31:59 +00:00
)}
</div>
);
}
}
const mapStateToProps = state => ({
notifications: state.notifications
});
export default connect(mapStateToProps, { closeNotification })(Notifications);