16
16
// window is undefined
17
17
}
18
18
19
- const Header = ( { profile } ) => {
19
+ const Header = ( {
20
+ profile, auth, notifications, loadNotifications, markNotificationAsRead,
21
+ markAllNotificationAsRead, markAllNotificationAsSeen, dismissChallengeNotifications,
22
+ } ) => {
20
23
const [ activeLevel1Id , setActiveLevel1Id ] = useState ( ) ;
21
24
const [ path , setPath ] = useState ( ) ;
22
25
const [ openMore , setOpenMore ] = useState ( true ) ;
@@ -48,6 +51,17 @@ const Header = ({ profile }) => {
48
51
useEffect ( ( ) => {
49
52
setPath ( window . location . pathname ) ;
50
53
} , [ ] ) ;
54
+
55
+ /*
56
+ * Reload notificaitons if token was changed
57
+ * This prevent to use expired token in API call
58
+ */
59
+ if ( auth ) {
60
+ useEffect ( ( ) => {
61
+ loadNotifications ( auth . tokenV3 ) ;
62
+ } , [ auth . tokenV3 ] ) ;
63
+ }
64
+
51
65
if ( TopNavRef ) {
52
66
return (
53
67
< div >
@@ -56,13 +70,19 @@ const Header = ({ profile }) => {
56
70
rightMenu = { (
57
71
< LoginNavRef
58
72
loggedIn = { ! _ . isEmpty ( profile ) }
59
- notificationButtonState = "none"
60
- notifications = { [ ] }
73
+ notificationButtonState = "new"
74
+ notifications = { notifications || [ ] }
75
+ loadNotifications = { loadNotifications }
76
+ markNotificationAsRead = { markNotificationAsRead }
77
+ markAllNotificationAsRead = { markAllNotificationAsRead }
78
+ markAllNotificationAsSeen = { markAllNotificationAsSeen }
79
+ dismissChallengeNotifications = { dismissChallengeNotifications }
61
80
accountMenu = { config . ACCOUNT_MENU }
62
81
switchText = { config . ACCOUNT_MENU_SWITCH_TEXT }
63
82
onSwitch = { handleSwitchMenu }
64
83
onMenuOpen = { handleCloseOpenMore }
65
- showNotification = { false }
84
+ showNotification
85
+ auth = { auth }
66
86
profile = { normalizedProfile }
67
87
authURLs = { config . HEADER_AUTH_URLS }
68
88
/>
@@ -86,13 +106,21 @@ const Header = ({ profile }) => {
86
106
87
107
Header . defaultProps = {
88
108
profile : null ,
109
+ auth : null ,
89
110
} ;
90
111
91
112
Header . propTypes = {
92
113
profile : PT . shape ( {
93
114
photoURL : PT . string ,
94
115
handle : PT . string ,
95
116
} ) ,
117
+ auth : PT . shape ( ) ,
118
+ notifications : PT . arrayOf ( PT . object ) . isRequired ,
119
+ loadNotifications : PT . func . isRequired ,
120
+ markNotificationAsRead : PT . func . isRequired ,
121
+ markAllNotificationAsRead : PT . func . isRequired ,
122
+ markAllNotificationAsSeen : PT . func . isRequired ,
123
+ dismissChallengeNotifications : PT . func . isRequired ,
96
124
} ;
97
125
98
126
export default Header ;
0 commit comments