Files
mattermost/web/react/components/sidebar_header.jsx

142 lines
4.7 KiB
React
Raw Normal View History

// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
2015-06-14 23:53:32 -08:00
// See License.txt for license information.
import NavbarDropdown from './navbar_dropdown.jsx';
import TutorialTip from './tutorial/tutorial_tip.jsx';
2015-10-30 11:35:16 -04:00
import PreferenceStore from '../stores/preference_store.jsx';
2015-10-30 11:35:16 -04:00
import Constants from '../utils/constants.jsx';
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;
export default class SidebarHeader extends React.Component {
constructor(props) {
super(props);
2015-07-23 14:59:43 +05: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
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();
if (this.refs.dropdown.blockToggle) {
this.refs.dropdown.blockToggle = false;
return;
}
$('.team__header').find('.dropdown-toggle').dropdown('toggle');
}
2015-10-30 11:35:16 -04:00
createTutorialTip() {
const screens = [];
screens.push(
<div>
<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>
);
}
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
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) {
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-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}
<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'
>
<div className='team__name'>{this.props.teamDisplayName}</div>
2015-10-29 00:02:17 +05:00
</OverlayTrigger>
</div>
</a>
<NavbarDropdown
ref='dropdown'
teamType={this.props.teamType}
teamDisplayName={this.props.teamDisplayName}
teamName={this.props.teamName}
2016-02-08 07:26:10 -05:00
currentUser={this.props.currentUser}
/>
2015-06-14 23:53:32 -08:00
</div>
);
}
}
SidebarHeader.defaultProps = {
2016-02-08 07:26:10 -05:00
teamDisplayName: '',
teamType: ''
};
SidebarHeader.propTypes = {
teamDisplayName: React.PropTypes.string,
teamName: React.PropTypes.string,
2016-02-08 07:26:10 -05:00
teamType: React.PropTypes.string,
currentUser: React.PropTypes.object
};