diff --git a/js/actions/event_actions.js b/js/actions/event_actions.js index 6d8ee12f..24889f4e 100644 --- a/js/actions/event_actions.js +++ b/js/actions/event_actions.js @@ -8,9 +8,8 @@ class EventActions { this.generateActions( 'applicationWillBoot', 'applicationDidBoot', - 'profileDidLoad', - //'userDidLogin', - //'userDidLogout', + 'userDidAuthenticate', + 'userDidLogout', 'routeDidChange' ); } diff --git a/js/components/header.js b/js/components/header.js index c16cba86..ed4a9a3d 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -59,19 +59,6 @@ let Header = React.createClass({ // close the mobile expanded navigation after a click by itself. // To get rid of this, we set the state of the component ourselves. history.listen(this.onRouteChange); - - if (this.state.currentUser && this.state.currentUser.email) { - EventActions.profileDidLoad.defer(this.state.currentUser); - } - }, - - componentWillUpdate(nextProps, nextState) { - const { currentUser: { email: curEmail } = {} } = this.state; - const { currentUser: { email: nextEmail } = {} } = nextState; - - if (nextEmail && curEmail !== nextEmail) { - EventActions.profileDidLoad.defer(nextState.currentUser); - } }, componentWillUnmount() { @@ -81,7 +68,7 @@ let Header = React.createClass({ }, getLogo() { - let { whitelabel } = this.state; + const { whitelabel } = this.state; if (whitelabel.head) { constructHead(whitelabel.head); @@ -102,7 +89,7 @@ let Header = React.createClass({ ); }, - getPoweredBy(){ + getPoweredBy() { return ( { + EventActions.userDidLogout(); + + // Reset all stores back to their initial state + alt.recycle(); + altWhitelabel.recycle(); + altUser.recycle(); + altThirdParty.recycle(); + }); } onSuccessLogoutCurrentUser() { diff --git a/js/third_party/intercom.js b/js/third_party/intercom.js index 4ab2ff50..fc14ced2 100644 --- a/js/third_party/intercom.js +++ b/js/third_party/intercom.js @@ -12,25 +12,28 @@ class IntercomHandler { this.loaded = false; } - onProfileDidLoad(profile) { + onUserDidAuthenticate(user) { if (this.loaded) { return; } - /* eslint-disable */ - Intercom('boot', { - /* eslint-enable */ + window.Intercom('boot', { app_id: 'oboxh5w1', - email: profile.email, + email: user.email, subdomain: getSubdomain(), widget: { activator: '#IntercomDefaultWidget' - } + } }); console.log('Intercom loaded'); this.loaded = true; } + onUserDidLogout() { + // kill intercom (with fire) + window.Intercom('shutdown'); + this.loaded = false; + } } export default altThirdParty.createStore(IntercomHandler, 'IntercomHandler'); diff --git a/js/third_party/notifications.js b/js/third_party/notifications.js index 85379479..9e33cdaf 100644 --- a/js/third_party/notifications.js +++ b/js/third_party/notifications.js @@ -17,18 +17,19 @@ class NotificationsHandler { this.loaded = false; } - onProfileDidLoad() { + onUserDidAuthenticate() { if (this.loaded) { return; } - let subdomain = getSubdomain(); + const subdomain = getSubdomain(); if (subdomain === 'ikonotv') { NotificationActions.fetchContractAgreementListNotifications().then( (res) => { if (res.notifications && res.notifications.length > 0) { - this.loaded = true; console.log('Contractagreement notifications loaded'); + this.loaded = true; + history.pushState(null, '/contract_notifications'); } } @@ -36,6 +37,10 @@ class NotificationsHandler { } this.loaded = true; } + + onUserDidLogout() { + this.loaded = false; + } } export default altThirdParty.createStore(NotificationsHandler, 'NotificationsHandler'); diff --git a/js/third_party/raven.js b/js/third_party/raven.js index 3d6ff315..f294bc95 100644 --- a/js/third_party/raven.js +++ b/js/third_party/raven.js @@ -12,17 +12,22 @@ class RavenHandler { this.loaded = false; } - onProfileDidLoad(profile) { + onUserDidAuthenticate(user) { if (this.loaded) { return; } Raven.setUserContext({ - email: profile.email + email: user.email }); console.log('Raven loaded'); this.loaded = true; } + + onUserDidLogout() { + Raven.setUserContext(); + this.loaded = false; + } } export default altThirdParty.createStore(RavenHandler, 'RavenHandler');