2015-10-08 12:27:09 -04:00
|
|
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2015-11-19 21:12:56 -05:00
|
|
|
import NavbarDropdown from './navbar_dropdown.jsx';
|
|
|
|
|
import TutorialTip from './tutorial/tutorial_tip.jsx';
|
2015-10-30 11:35:16 -04:00
|
|
|
|
2015-11-19 21:12:56 -05:00
|
|
|
import PreferenceStore from '../stores/preference_store.jsx';
|
2015-10-30 11:35:16 -04:00
|
|
|
|
2015-11-19 21:12:56 -05:00
|
|
|
import Constants from '../utils/constants.jsx';
|
2016-01-31 22:03:30 -03:00
|
|
|
|
|
|
|
|
import {FormattedHTMLMessage} from 'mm-intl';
|
|
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
const Preferences = Constants.Preferences;
|
|
|
|
|
const TutorialSteps = Constants.TutorialSteps;
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-10-29 00:02:17 +05:00
|
|
|
const Tooltip = ReactBootstrap.Tooltip;
|
|
|
|
|
const OverlayTrigger = ReactBootstrap.OverlayTrigger;
|
|
|
|
|
|
2015-08-31 09:35:31 -07:00
|
|
|
export default class SidebarHeader extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2015-07-23 14:59:43 +05:00
|
|
|
|
2015-08-31 09:35:31 -07:00
|
|
|
this.toggleDropdown = this.toggleDropdown.bind(this);
|
2015-10-30 11:35:16 -04:00
|
|
|
this.onPreferenceChange = this.onPreferenceChange.bind(this);
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
this.state = this.getStateFromStores();
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
PreferenceStore.addChangeListener(this.onPreferenceChange);
|
|
|
|
|
}
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
PreferenceStore.removeChangeListener(this.onPreferenceChange);
|
|
|
|
|
}
|
|
|
|
|
getStateFromStores() {
|
2016-02-08 07:26:10 -05:00
|
|
|
const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, this.props.currentUser.id, 999);
|
2015-10-30 11:35:16 -04:00
|
|
|
|
2015-12-15 11:36:14 -05:00
|
|
|
return {showTutorialTip: tutorialStep === TutorialSteps.MENU_POPOVER};
|
2015-10-30 11:35:16 -04:00
|
|
|
}
|
|
|
|
|
onPreferenceChange() {
|
|
|
|
|
this.setState(this.getStateFromStores());
|
2015-06-14 23:53:32 -08:00
|
|
|
}
|
2015-09-17 22:00:33 -07:00
|
|
|
toggleDropdown(e) {
|
|
|
|
|
e.preventDefault();
|
2015-07-30 10:54:41 -04:00
|
|
|
if (this.refs.dropdown.blockToggle) {
|
|
|
|
|
this.refs.dropdown.blockToggle = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$('.team__header').find('.dropdown-toggle').dropdown('toggle');
|
2015-08-31 09:35:31 -07:00
|
|
|
}
|
2015-10-30 11:35:16 -04:00
|
|
|
createTutorialTip() {
|
|
|
|
|
const screens = [];
|
|
|
|
|
|
|
|
|
|
screens.push(
|
|
|
|
|
<div>
|
2016-01-31 22:03:30 -03:00
|
|
|
<FormattedHTMLMessage
|
|
|
|
|
id='sidebar_header.tutorial'
|
|
|
|
|
defaultMessage='<h4>Main Menu</h4>
|
|
|
|
|
<p>The <strong>Main Menu</strong> is where you can <strong>Invite New Members</strong>, access your <strong>Account Settings</strong> and set your <strong>Theme Color</strong>.</p>
|
|
|
|
|
<p>Team administrators can also access their <strong>Team Settings</strong> from this menu.</p><p>System administrators will find a <strong>System Console</strong> option to administrate the entire system.</p>'
|
|
|
|
|
/>
|
2015-10-30 11:35:16 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
onClick={this.toggleDropdown}
|
|
|
|
|
>
|
|
|
|
|
<TutorialTip
|
|
|
|
|
ref='tip'
|
|
|
|
|
placement='right'
|
|
|
|
|
screens={screens}
|
2015-11-02 20:57:23 +05:00
|
|
|
overlayClass='tip-overlay--header'
|
2015-10-30 11:35:16 -04:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-08-31 09:35:31 -07:00
|
|
|
render() {
|
2016-02-08 07:26:10 -05:00
|
|
|
var me = this.props.currentUser;
|
2015-08-04 09:40:58 -07:00
|
|
|
var profilePicture = null;
|
2015-07-08 12:51:43 -07:00
|
|
|
|
2015-07-15 09:03:28 -07:00
|
|
|
if (!me) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2015-08-04 09:40:58 -07:00
|
|
|
if (me.last_picture_update) {
|
2015-09-03 10:49:36 -04:00
|
|
|
profilePicture = (
|
|
|
|
|
<img
|
|
|
|
|
className='user__picture'
|
2016-02-08 07:26:10 -05:00
|
|
|
src={'/api/v1/users/' + me.id + '/image?time=' + me.update_at}
|
2015-09-03 10:49:36 -04:00
|
|
|
/>
|
|
|
|
|
);
|
2015-08-04 09:40:58 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-30 11:35:16 -04:00
|
|
|
let tutorialTip = null;
|
|
|
|
|
if (this.state.showTutorialTip) {
|
|
|
|
|
tutorialTip = this.createTutorialTip();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 23:53:32 -08:00
|
|
|
return (
|
2015-08-04 09:40:58 -07:00
|
|
|
<div className='team__header theme'>
|
2015-10-30 11:35:16 -04:00
|
|
|
{tutorialTip}
|
2015-08-31 09:35:31 -07:00
|
|
|
<a
|
|
|
|
|
href='#'
|
|
|
|
|
onClick={this.toggleDropdown}
|
|
|
|
|
>
|
2015-08-04 09:40:58 -07:00
|
|
|
{profilePicture}
|
|
|
|
|
<div className='header__info'>
|
|
|
|
|
<div className='user__name'>{'@' + me.username}</div>
|
2015-10-29 00:02:17 +05:00
|
|
|
<OverlayTrigger
|
|
|
|
|
trigger={['hover', 'focus']}
|
|
|
|
|
delayShow={1000}
|
|
|
|
|
placement='bottom'
|
|
|
|
|
overlay={<Tooltip id='team-name__tooltip'>{this.props.teamDisplayName}</Tooltip>}
|
|
|
|
|
ref='descriptionOverlay'
|
|
|
|
|
>
|
2015-08-31 09:35:31 -07:00
|
|
|
<div className='team__name'>{this.props.teamDisplayName}</div>
|
2015-10-29 00:02:17 +05:00
|
|
|
</OverlayTrigger>
|
2015-07-08 11:50:10 -04:00
|
|
|
</div>
|
|
|
|
|
</a>
|
2015-08-31 09:35:31 -07:00
|
|
|
<NavbarDropdown
|
|
|
|
|
ref='dropdown'
|
|
|
|
|
teamType={this.props.teamType}
|
2015-10-01 17:52:47 -07:00
|
|
|
teamDisplayName={this.props.teamDisplayName}
|
|
|
|
|
teamName={this.props.teamName}
|
2016-02-08 07:26:10 -05:00
|
|
|
currentUser={this.props.currentUser}
|
2015-08-31 09:35:31 -07:00
|
|
|
/>
|
2015-06-14 23:53:32 -08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-08-31 09:35:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SidebarHeader.defaultProps = {
|
2016-02-08 07:26:10 -05:00
|
|
|
teamDisplayName: '',
|
2015-08-31 09:35:31 -07:00
|
|
|
teamType: ''
|
|
|
|
|
};
|
|
|
|
|
SidebarHeader.propTypes = {
|
|
|
|
|
teamDisplayName: React.PropTypes.string,
|
2015-10-01 17:52:47 -07:00
|
|
|
teamName: React.PropTypes.string,
|
2016-02-08 07:26:10 -05:00
|
|
|
teamType: React.PropTypes.string,
|
|
|
|
|
currentUser: React.PropTypes.object
|
2015-08-31 09:35:31 -07:00
|
|
|
};
|