@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
import cn from 'classnames' ;
4
4
import _ from 'lodash' ;
5
5
import moment from 'moment' ;
6
+ import { Link } from 'topcoder-react-utils' ;
6
7
import IconArrow from 'assets/images/notifications/arrow.svg' ;
7
8
import styles from './style.scss' ;
8
9
import TabsPanel from './TabsPanel' ;
@@ -18,39 +19,68 @@ const eventTypes = {
18
19
} ,
19
20
BROADCAST : 'admin.notification.broadcast' ,
20
21
} ;
22
+
23
+ // Dynamic element, to select between Link and Div
24
+ const ConditionalWrapper = ( {
25
+ condition, renderLink, renderDiv, children,
26
+ } ) => (
27
+ condition ? renderLink ( children ) : renderDiv ( children )
28
+ ) ;
29
+
21
30
const Item = ( {
22
- item, auth, markNotificationAsRead, showPoint,
31
+ item, auth, markNotificationAsRead, showPoint, isLink ,
23
32
} ) => (
24
- < div className = { styles [ 'noti-item' ] } >
25
- < div className = { styles . left } >
26
- < p className = { styles . txt } > { item . contents } </ p >
27
- < span className = { styles [ 'time-txt' ] } > { moment ( item . date ) . fromNow ( ) } </ span >
28
- </ div >
29
- < div className = { styles . right } >
30
- {
31
- ! item . isRead
32
- && showPoint
33
- && (
34
- < div
35
- role = "button"
36
- className = { cn ( [ styles . point , item . isSeen && styles [ 'point-grey' ] , ! item . isSeen && styles [ 'point-red' ] ] ) }
37
- onClick = { ( ) => {
38
- markNotificationAsRead ( item , auth . tokenV3 ) ;
39
- } }
40
- onKeyPress = { ( ) => {
41
- markNotificationAsRead ( item , auth . tokenV3 ) ;
42
- } }
43
- tabIndex = "0"
44
- />
45
- ) }
46
- </ div >
47
- </ div >
33
+ < ConditionalWrapper
34
+ condition = { isLink }
35
+ renderLink = { children => (
36
+ < Link
37
+ to = { `/challenges/${ item . sourceId } ` }
38
+ className = { styles [ 'noti-item' ] }
39
+ onClick = { ( ) => ! item . isRead && markNotificationAsRead ( item , auth . tokenV3 ) }
40
+ >
41
+ { children }
42
+ </ Link >
43
+ ) }
44
+ renderDiv = { children => (
45
+ < div className = { styles [ 'noti-item' ] } >
46
+ { children }
47
+ </ div >
48
+ ) }
49
+ >
50
+ < Fragment >
51
+ < div className = { styles . left } >
52
+ < p className = { styles . txt } > { item . contents } </ p >
53
+ < span className = { styles [ 'time-txt' ] } > { moment ( item . date ) . fromNow ( ) } </ span >
54
+ </ div >
55
+ < div className = { styles . right } >
56
+ {
57
+ ! item . isRead
58
+ && showPoint
59
+ && (
60
+ < div
61
+ role = "button"
62
+ className = { cn ( [ styles . point , item . isSeen && styles [ 'point-grey' ] , ! item . isSeen && styles [ 'point-red' ] ] ) }
63
+ onClick = { ( ) => {
64
+ if ( ! isLink ) {
65
+ markNotificationAsRead ( item , auth . tokenV3 ) ;
66
+ }
67
+ } }
68
+ onKeyPress = { ( ) => {
69
+ markNotificationAsRead ( item , auth . tokenV3 ) ;
70
+ } }
71
+ tabIndex = "0"
72
+ />
73
+ ) }
74
+ </ div >
75
+ </ Fragment >
76
+ </ ConditionalWrapper >
48
77
) ;
49
78
Item . propTypes = {
50
79
item : PropTypes . shape ( ) . isRequired ,
51
80
auth : PropTypes . shape ( ) . isRequired ,
52
81
markNotificationAsRead : PropTypes . func . isRequired ,
53
82
showPoint : PropTypes . bool . isRequired ,
83
+ isLink : PropTypes . bool . isRequired ,
54
84
} ;
55
85
56
86
const challenges = ( listReceived ) => {
@@ -102,6 +132,13 @@ export default class NotificationList extends React.Component {
102
132
this . setState ( { collapsedChallenges : collapsed } ) ;
103
133
}
104
134
135
+ isLink = ( item ) => {
136
+ const ret = ( eventTypes . PROJECT . ACTIVE . includes ( item . eventType )
137
+ || eventTypes . PROJECT . COMPLETED . includes ( item . eventType ) )
138
+ && item . sourceId ;
139
+ return ret ;
140
+ }
141
+
105
142
render ( ) {
106
143
const {
107
144
auth, notifications, loadNotifications, markNotificationAsRead,
@@ -180,6 +217,7 @@ export default class NotificationList extends React.Component {
180
217
markNotificationAsRead = { markNotificationAsRead }
181
218
key = { `noti-item-${ item . id } ` }
182
219
showPoint = { activeTab !== 'completed' }
220
+ isLink = { this . isLink ( item ) }
183
221
/>
184
222
) ) }
185
223
</ Fragment >
0 commit comments