@@ -8,13 +8,20 @@ import BackArrow from '../../assets/images/left-arrow.svg'
8
8
import GearIcon from '../../assets/images/icon-settings-gear.svg'
9
9
import TickIcon from '../../assets/images/icon-checkmark.svg'
10
10
import NotificationIcon from '../../assets/images/icon-bell.svg'
11
+
12
+ // TODO: We change this later based on API event mapping
11
13
const eventTypes = {
12
14
PROJECT : {
13
- ACTIVE : 'connect.notification.project.active' ,
14
- COMPLETED : 'connect.notification.project.completed'
15
+ ACTIVE : [
16
+ 'challenge.notification.events' ,
17
+ 'submission.notification.create'
18
+ ] ,
19
+ BROADCAST : 'admin.notifications.broadcast' ,
20
+ COMPLETED : 'challenge.notification.completed'
15
21
}
16
22
}
17
- const Item = ( { item, onDismiss, markNotificationAsRead } ) =>
23
+
24
+ const Item = ( { item, auth, onDismiss, markNotificationAsRead } ) =>
18
25
< div className = { styles [ 'noti-item' ] } >
19
26
< div className = { styles . left } >
20
27
< p className = { styles [ 'txt' ] } > { item . contents } </ p >
@@ -24,12 +31,15 @@ const Item = ({ item, onDismiss, markNotificationAsRead }) =>
24
31
{
25
32
! item . isRead &&
26
33
( < div className = { cn ( [ styles . point , item . isSeen && styles [ 'point-grey' ] , ! item . isSeen && styles [ 'point-red' ] ] ) }
27
- onClick = { ( ) => { markNotificationAsRead ( item ) } } /> ) }
34
+ onClick = { ( ) => {
35
+ markNotificationAsRead ( item , auth . tokenV3 )
36
+ } } /> ) }
28
37
</ div >
29
38
</ div >
30
39
31
40
Item . propTypes = {
32
- item : PropTypes . object ,
41
+ item : PropTypes . object . isRequired ,
42
+ auth : PropTypes . shape ( ) . isRequired ,
33
43
onDismiss : PropTypes . func ,
34
44
markNotificationAsRead : PropTypes . func . isRequired
35
45
}
@@ -39,45 +49,25 @@ export default class NotificationList extends React.Component {
39
49
super ( props )
40
50
this . state = {
41
51
completedSection : [ ] ,
42
- nonCompletedSection : [ ]
52
+ nonCompletedSection : [ ] ,
53
+ unreadCount : 0
43
54
}
44
55
}
45
56
46
- componentDidMount ( ) {
47
- const { notifications } = this . props
48
- this . setState ( {
49
- completedSection : _ . uniq (
50
- ( notifications || [
51
-
52
- ] ) ) . filter ( t => t . isComplete )
53
- } )
54
- this . setState ( {
55
- nonCompletedSection : _ . uniq (
56
- ( notifications || [
57
-
58
- ] ) ) . filter ( t => ! t . isComplete )
59
- } )
60
- }
61
-
62
57
challenges ( list ) {
63
58
list = list || [ ]
64
- const challengeTitles = _ . uniq (
65
- list . map ( noti => noti . sourceName ) . filter ( x => x )
66
- )
67
- var group = challengeTitles . map ( title =>
59
+ const challengeTitles = _ . uniq ( list . map ( noti => noti . sourceName ) . filter ( x => x ) )
60
+ return challengeTitles . map ( title =>
68
61
( {
69
62
challengeTitle : title , items : list . filter ( t => t . sourceName === title )
70
63
} ) )
71
-
72
- return group
73
64
}
74
65
75
66
render ( ) {
76
- const { onClose, onSettings, onDismiss, notifications, markNotificationAsRead,
77
- markAllNotificationAsRead, dismissChallengeNotifications } = this . props
78
- let completedSection = _ . filter ( ( notifications || [ ] ) , t => t . eventType === eventTypes . PROJECT . COMPLETED )
79
- let nonCompletedSection = _ . filter ( ( notifications || [ ] ) , t => t . eventType !== eventTypes . PROJECT . COMPLETED )
80
- const unreadCount = _ . filter ( ( notifications || [ ] ) , t => t . isRead === false ) . length
67
+ const { onClose, onSettings, notifications, onDismiss, unReadNotifications,
68
+ markNotificationAsRead, markAllNotificationAsRead,
69
+ dismissChallengeNotifications, auth } = this . props
70
+
81
71
return (
82
72
< >
83
73
< div className = { styles [ 'noti-header' ] } >
@@ -101,8 +91,10 @@ export default class NotificationList extends React.Component {
101
91
< div className = { styles . rights } >
102
92
< span
103
93
role = 'button'
104
- className = { cn ( styles [ 'white-link' ] , unreadCount <= 0 && styles [ 'disabled' ] ) }
105
- onClick = { unreadCount > 0 ? ( ) => markAllNotificationAsRead ( ) : null }
94
+ className = { cn ( styles [ 'white-link' ] , ! unReadNotifications && styles [ 'disabled' ] ) }
95
+ onClick = { ( ) => {
96
+ unReadNotifications && markAllNotificationAsRead ( auth . tokenV3 )
97
+ } }
106
98
>
107
99
Mark All as Read
108
100
</ span >
@@ -117,9 +109,11 @@ export default class NotificationList extends React.Component {
117
109
</ div >
118
110
< div className = { styles [ 'rights-mobile' ] } >
119
111
< div
120
- className = { cn ( styles [ 'btn-tick' ] , unreadCount <= 0 && styles [ 'disabled' ] ) }
112
+ className = { cn ( styles [ 'btn-tick' ] , ! unReadNotifications && styles [ 'disabled' ] ) }
121
113
role = 'button'
122
- onClick = { unreadCount > 0 ? markAllNotificationAsRead : null }
114
+ onClick = { ( ) => {
115
+ unReadNotifications && markAllNotificationAsRead ( auth . tokenV3 )
116
+ } }
123
117
>
124
118
< TickIcon />
125
119
</ div >
@@ -134,7 +128,7 @@ export default class NotificationList extends React.Component {
134
128
< div className = { styles [ 'noti-body' ] } >
135
129
< Fragment key = 'nonComplete' >
136
130
{
137
- this . challenges ( nonCompletedSection ) . map ( ( challenge , challengeIdx ) =>
131
+ this . challenges ( _ . uniq ( ( notifications || [ ] ) ) . filter ( t => ! eventTypes . PROJECT . COMPLETED . includes ( t . eventType ) ) ) . map ( ( challenge , challengeIdx ) =>
138
132
(
139
133
< Fragment key = { `nonComplete-${ challengeIdx } ` } >
140
134
< div key = { `noti-${ challengeIdx } ` } className = { styles [ 'challenge-title' ] } >
@@ -143,6 +137,7 @@ export default class NotificationList extends React.Component {
143
137
{ challenge . items . map ( ( item , itemIdx ) =>
144
138
( < Item
145
139
item = { item }
140
+ auth = { auth }
146
141
markNotificationAsRead = { markNotificationAsRead }
147
142
key = { `noti-${ challengeIdx } -${ itemIdx } ` }
148
143
onDismiss = { ( ) => onDismiss ( [ item ] ) }
@@ -154,14 +149,14 @@ export default class NotificationList extends React.Component {
154
149
< div className = { styles [ 'completed-header' ] } > Completed Challenges</ div >
155
150
< Fragment key = 'completed' >
156
151
{
157
- this . challenges ( completedSection ) . map ( ( challenge , challengeIdx ) =>
152
+ this . challenges ( _ . uniq ( ( notifications || [ ] ) ) . filter ( t => eventTypes . PROJECT . COMPLETED . includes ( t . eventType ) ) ) . map ( ( challenge , challengeIdx ) =>
158
153
(
159
154
< div key = { `noti-completed-${ challengeIdx } ` } className = { cn ( [ styles [ 'challenge-title' ] , styles [ 'completed-challenge' ] ] ) } >
160
155
< span > { challenge . challengeTitle } </ span >
161
156
< div className = { styles [ 'dismiss-challenge' ] } onClick = { c => {
162
157
const challegeId = challenge && challenge . items && challenge . items . length && challenge . items [ 0 ] . sourceId
163
158
if ( challegeId ) {
164
- dismissChallengeNotifications ( challegeId )
159
+ dismissChallengeNotifications ( challegeId , auth . tokenV3 )
165
160
}
166
161
} } > ×</ div >
167
162
</ div >
@@ -179,12 +174,14 @@ export default class NotificationList extends React.Component {
179
174
180
175
NotificationList . defaultProps = {
181
176
notifications : [ ] ,
177
+ auth : null ,
182
178
onDismiss : ( ) => null ,
183
179
markAllNotificationAsRead : ( ) => null ,
184
180
markNotificationAsRead : ( ) => null
185
181
}
186
182
187
183
NotificationList . propTypes = {
184
+ auth : PropTypes . shape ( ) ,
188
185
/**
189
186
* Array of Notifications, each with properties:
190
187
*
@@ -212,7 +209,7 @@ NotificationList.propTypes = {
212
209
onSettings : PropTypes . func ,
213
210
214
211
onClose : PropTypes . func ,
215
-
212
+ unReadNotifications : PropTypes . bool ,
216
213
markNotificationAsRead : PropTypes . func . isRequired ,
217
214
markAllNotificationAsRead : PropTypes . func . isRequired ,
218
215
dismissChallengeNotifications : PropTypes . func . isRequired
0 commit comments