/
index.jsx
76 lines (68 loc) · 2.45 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react'
import { connect } from 'react-redux'
import { ListGroup, ListGroupItem, Panel, Button, Tooltip, OverlayTrigger } from 'react-bootstrap'
import _ from 'lodash'
import NotificationComponent from '~/components/Notifications'
import ContentWrapper from '~/components/Layout/ContentWrapper'
import PageHeader from '~/components/Layout/PageHeader'
import { fetchNotifications } from '~/actions'
import styles from './style.scss'
// TODO: extending components is discouraged,
// should be reworked with composition eventually
class NotificationHub extends NotificationComponent {
constructor(props, context) {
super(props, context, {
itemComponent: ListGroupItem,
renderDivider: false,
styles: styles
})
}
renderMessage(message) {
return <p className={styles.message}>{message}</p>
}
render() {
const notifications = this.props.notifications || []
const unreadCount = _.filter(notifications, { read: false }).length
const trashTip = <Tooltip id="ttip">Delete all</Tooltip>
const readTip = <Tooltip id="ttip">Mark all as read</Tooltip>
return (
<ContentWrapper>
<PageHeader>
<span>Notifications</span>
</PageHeader>
{notifications.length > 0 ? (
<Panel>
<Panel.Body>
<div className="pull-right">
<OverlayTrigger placement="left" overlay={readTip}>
<Button disabled={unreadCount === 0} onClick={this.markAllAsRead}>
<em className="glyphicon glyphicon-eye-open" />
</Button>
</OverlayTrigger>
<OverlayTrigger placement="left" overlay={trashTip}>
<Button className={styles['bar-btn']} onClick={this.trashAll}>
<em className="glyphicon glyphicon-trash" />
</Button>
</OverlayTrigger>
</div>
</Panel.Body>
</Panel>
) : (
<div className={styles.empty}>
<p>You have no notifications!</p>
</div>
)}
<ListGroup
style={{
padding: 0
}}
>
{this.renderMenuItems(notifications)}
</ListGroup>
</ContentWrapper>
)
}
}
const mapStateToProps = state => ({ notifications: state.notifications })
const mapDispatchToProps = { fetchNotifications }
export default connect(mapStateToProps, mapDispatchToProps)(NotificationHub)