Files
mattermost/webapp/components/tutorial/tutorial_tip.jsx

169 lines
5.6 KiB
React
Raw Normal View History

2015-10-30 11:35:16 -04:00
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
2016-03-14 08:50:46 -04:00
import UserStore from 'stores/user_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
2015-10-30 11:35:16 -04:00
2016-03-14 08:50:46 -04:00
import Constants from 'utils/constants.jsx';
2016-03-14 08:50:46 -04:00
import {FormattedMessage} from 'react-intl';
2015-10-30 11:35:16 -04:00
const Preferences = Constants.Preferences;
2016-03-14 08:50:46 -04:00
import {Overlay} from 'react-bootstrap';
import React from 'react';
2015-10-30 11:35:16 -04:00
2016-03-28 22:03:18 +05:00
import tutorialGif from 'images/tutorialTip.gif';
import tutorialGifWhite from 'images/tutorialTipWhite.gif';
2015-10-30 11:35:16 -04:00
export default class TutorialTip extends React.Component {
constructor(props) {
super(props);
this.handleNext = this.handleNext.bind(this);
this.toggle = this.toggle.bind(this);
this.state = {currentScreen: 0, show: false};
}
toggle() {
const show = !this.state.show;
this.setState({show});
if (!show && this.state.currentScreen >= this.props.screens.length - 1) {
const step = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 0);
2015-10-30 11:35:16 -04:00
AsyncClient.savePreference(
Preferences.TUTORIAL_STEP,
UserStore.getCurrentId(),
(step + 1).toString()
);
2015-10-30 11:35:16 -04:00
}
}
handleNext() {
if (this.state.currentScreen < this.props.screens.length - 1) {
this.setState({currentScreen: this.state.currentScreen + 1});
return;
}
this.toggle();
}
skipTutorial(e) {
e.preventDefault();
AsyncClient.savePreference(
Preferences.TUTORIAL_STEP,
UserStore.getCurrentId(),
'999'
);
2015-10-30 11:35:16 -04:00
}
render() {
const buttonText = this.state.currentScreen === this.props.screens.length - 1 ? (
<FormattedMessage
id='tutorial_tip.ok'
defaultMessage='Okay'
/>
) : (
<FormattedMessage
id='tutorial_tip.next'
defaultMessage='Next'
/>
);
2015-10-30 11:35:16 -04:00
const dots = [];
if (this.props.screens.length > 1) {
for (let i = 0; i < this.props.screens.length; i++) {
2015-11-13 10:13:54 -05:00
let className = 'circle';
2015-10-30 11:35:16 -04:00
if (i === this.state.currentScreen) {
2015-11-13 10:13:54 -05:00
className += ' active';
2015-10-30 11:35:16 -04:00
}
2015-11-13 10:13:54 -05:00
dots.push(
<a
href='#'
key={'dotactive' + i}
className={className}
onClick={(e) => { //eslint-disable-line no-loop-func
e.preventDefault();
this.setState({currentScreen: i});
}}
/>
);
2015-10-30 11:35:16 -04:00
}
}
2016-03-28 22:03:18 +05:00
var tutorialGifImage = tutorialGif;
2016-01-27 23:45:02 +05:00
if (this.props.overlayClass === 'tip-overlay--header' || this.props.overlayClass === 'tip-overlay--sidebar') {
2016-03-28 22:03:18 +05:00
tutorialGifImage = tutorialGifWhite;
2015-11-09 23:43:44 +05:00
}
2015-10-30 11:35:16 -04:00
return (
2015-11-02 20:57:23 +05:00
<div className={'tip-div ' + this.props.overlayClass}>
2015-10-30 11:35:16 -04:00
<img
className='tip-button'
2016-03-28 22:03:18 +05:00
src={tutorialGifImage}
2015-11-02 11:40:53 +05:00
width='35'
2015-10-30 11:35:16 -04:00
onClick={this.toggle}
ref='target'
/>
<Overlay
show={this.state.show}
>
<div className='tip-backdrop'/>
</Overlay>
2015-10-30 11:35:16 -04:00
<Overlay
placement={this.props.placement}
show={this.state.show}
rootClose={true}
onHide={this.toggle}
target={() => this.refs.target}
>
<div className={'tip-overlay ' + this.props.overlayClass}>
2015-11-02 20:57:23 +05:00
<div className='arrow'></div>
2015-10-30 11:35:16 -04:00
{this.props.screens[this.state.currentScreen]}
2016-01-04 15:11:16 +05:00
<div className='tutorial__footer'>
<div className='tutorial__circles'>{dots}</div>
<div className='text-right'>
<button
className='btn btn-primary'
onClick={this.handleNext}
2015-11-02 11:40:53 +05:00
>
2016-01-04 15:11:16 +05:00
{buttonText}
</button>
<div className='tip-opt'>
<FormattedMessage
id='tutorial_tip.seen'
defaultMessage='Seen this before? '
/>
2016-01-04 15:11:16 +05:00
<a
href='#'
onClick={this.skipTutorial}
>
<FormattedMessage
id='tutorial_tip.out'
defaultMessage='Opt out of these tips.'
/>
2016-01-04 15:11:16 +05:00
</a>
</div>
2015-11-02 11:40:53 +05:00
</div>
</div>
2015-10-30 11:35:16 -04:00
</div>
</Overlay>
</div>
);
}
}
TutorialTip.defaultProps = {
overlayClass: ''
};
2015-10-30 11:35:16 -04:00
TutorialTip.propTypes = {
screens: React.PropTypes.array.isRequired,
placement: React.PropTypes.string.isRequired,
overlayClass: React.PropTypes.string
2015-10-30 11:35:16 -04:00
};