'use strict'; import React from 'react'; import Router from 'react-router'; import Raven from 'raven-js'; import UserActions from '../actions/user_actions'; import UserStore from '../stores/user_store'; import WhitelabelActions from '../actions/whitelabel_actions'; import WhitelabelStore from '../stores/whitelabel_store'; import Alt from '../alt'; import Nav from 'react-bootstrap/lib/Nav'; import Navbar from 'react-bootstrap/lib/Navbar'; import CollapsibleNav from 'react-bootstrap/lib/CollapsibleNav'; import DropdownButton from 'react-bootstrap/lib/DropdownButton'; import MenuItem from 'react-bootstrap/lib/MenuItem'; import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink'; import NavItemLink from 'react-router-bootstrap/lib/NavItemLink'; import HeaderNotificationDebug from './header_notification_debug'; import { mergeOptions } from '../utils/general_utils'; import { getLangText } from '../utils/lang_utils'; let Header = React.createClass({ propTypes: { showAddWork: React.PropTypes.bool }, mixins: [Router.Navigation, Router.State], getDefaultProps() { return { showAddWork: true }; }, getInitialState() { return mergeOptions(WhitelabelStore.getState(), UserStore.getState()); }, componentDidMount() { UserActions.fetchCurrentUser(); UserStore.listen(this.onChange); WhitelabelActions.fetchWhitelabel(); WhitelabelStore.listen(this.onChange); }, componentWillUnmount() { UserStore.unlisten(this.onChange); WhitelabelStore.unlisten(this.onChange); }, handleLogout(){ UserActions.logoutCurrentUser(); Alt.flush(); // kill intercom (with fire) window.Intercom('shutdown'); this.transitionTo('login'); }, getLogo(){ let logo = ( ascribe ); if (this.state.whitelabel && this.state.whitelabel.logo){ logo = ; } return logo; }, getPoweredBy(){ if (this.state.whitelabel && this.state.whitelabel.logo) { return (
  • {getLangText('powered by')} ascribe
  • ); } return null; }, onChange(state) { this.setState(state); if(this.state.currentUser && this.state.currentUser.email) { // bootup intercom if the user is logged in window.Intercom('boot', { app_id: 'oboxh5w1', email: this.state.currentUser.email, subdomain: window.location.host.split('.')[0], widget: { activator: '#IntercomDefaultWidget' } }); Raven.setUserContext({ email: this.state.currentUser.email }); } }, render() { let account = null; let signup = null; let collection = null; let addNewWork = null; if (this.state.currentUser.username){ account = ( {getLangText('Account Settings')} {getLangText('Log out')} ); collection = {getLangText('COLLECTION')}; addNewWork = this.props.showAddWork ? + {getLangText('NEW WORK')} : null; } else { account = {getLangText('LOGIN')}; signup = {getLangText('SIGNUP')}; } return (
    ); } }); export default Header;