2018-10-13 03:16:20 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-02-27 20:58:55 +03:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import {
|
|
|
|
faBan,
|
|
|
|
faCheck,
|
|
|
|
faCircle,
|
|
|
|
faExclamationTriangle,
|
|
|
|
} from '@fortawesome/free-solid-svg-icons';
|
2020-07-14 21:32:26 +03:00
|
|
|
import { Alert, Button } from 'reactstrap';
|
2018-10-13 03:16:20 +03:00
|
|
|
|
|
|
|
class NotificationList extends React.Component {
|
2019-02-27 20:58:55 +03:00
|
|
|
static getIcon(severity) {
|
|
|
|
// TODO: Move this and the usage in NotificationsMenu to a shared component.
|
2018-10-13 03:16:20 +03:00
|
|
|
switch (severity) {
|
|
|
|
case 'danger':
|
2019-02-27 20:58:55 +03:00
|
|
|
return faBan;
|
2018-10-13 03:16:20 +03:00
|
|
|
case 'warning':
|
2019-02-27 20:58:55 +03:00
|
|
|
return faExclamationTriangle;
|
2020-06-30 23:56:56 +03:00
|
|
|
case 'darker-info':
|
|
|
|
return faCircle;
|
2018-10-13 03:16:20 +03:00
|
|
|
case 'success':
|
2019-02-27 20:58:55 +03:00
|
|
|
return faCheck;
|
2018-10-13 03:16:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-06-07 00:39:50 +03:00
|
|
|
const { notifications, clearNotification } = this.props;
|
2018-10-13 03:16:20 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ul id="notification-box" className="list-unstyled">
|
|
|
|
{notifications.map((notification, idx) => (
|
|
|
|
<li key={notification.created}>
|
2020-07-14 21:32:26 +03:00
|
|
|
<Alert color={notification.severity}>
|
2019-02-27 20:58:55 +03:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={NotificationList.getIcon(notification.severity)}
|
2019-04-09 20:24:47 +03:00
|
|
|
title={notification.severity}
|
2018-10-13 03:16:20 +03:00
|
|
|
/>
|
2019-06-07 00:39:50 +03:00
|
|
|
<span className="ml-1">{notification.message}</span>
|
2018-11-16 11:28:34 +03:00
|
|
|
{notification.url && notification.linkText && (
|
|
|
|
<span>
|
|
|
|
<a href={notification.url}>{notification.linkText}</a>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{notification.sticky && (
|
2020-07-14 21:32:26 +03:00
|
|
|
<Button
|
2019-06-07 00:39:50 +03:00
|
|
|
onClick={() => clearNotification(idx)}
|
2020-07-14 21:32:26 +03:00
|
|
|
className="close pt-1"
|
2018-11-16 11:28:34 +03:00
|
|
|
>
|
|
|
|
x
|
2020-07-14 21:32:26 +03:00
|
|
|
</Button>
|
2018-11-16 11:28:34 +03:00
|
|
|
)}
|
2020-07-14 21:32:26 +03:00
|
|
|
</Alert>
|
2018-11-16 11:28:34 +03:00
|
|
|
</li>
|
|
|
|
))}
|
2018-10-13 03:16:20 +03:00
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationList.propTypes = {
|
2018-11-14 19:36:18 +03:00
|
|
|
notifications: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
created: PropTypes.number.isRequired,
|
|
|
|
message: PropTypes.string.isRequired,
|
2020-07-14 21:32:26 +03:00
|
|
|
severity: PropTypes.oneOf([
|
|
|
|
'danger',
|
|
|
|
'warning',
|
|
|
|
'darker-info',
|
|
|
|
'success',
|
|
|
|
]),
|
2018-11-14 19:36:18 +03:00
|
|
|
sticky: PropTypes.bool,
|
|
|
|
}),
|
|
|
|
).isRequired,
|
2019-06-07 00:39:50 +03:00
|
|
|
clearNotification: PropTypes.func.isRequired,
|
2018-10-13 03:16:20 +03:00
|
|
|
};
|
|
|
|
|
2019-06-07 00:39:50 +03:00
|
|
|
export default NotificationList;
|