// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import EmailItem from './team_signup_email_item.jsx';
import * as Client from '../utils/client.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'mm-intl';
export default class TeamSignupSendInvitesPage extends React.Component {
constructor(props) {
super(props);
this.submitBack = this.submitBack.bind(this);
this.submitNext = this.submitNext.bind(this);
this.submitAddInvite = this.submitAddInvite.bind(this);
this.submitSkip = this.submitSkip.bind(this);
this.keySubmit = this.keySubmit.bind(this);
this.state = {
emailEnabled: global.window.mm_config.SendEmailNotifications === 'true'
};
}
submitBack(e) {
e.preventDefault();
this.props.state.wizard = 'team_url';
this.props.updateParent(this.props.state);
}
submitNext(e) {
e.preventDefault();
var valid = true;
if (this.state.emailEnabled) {
var emails = [];
for (var i = 0; i < this.props.state.invites.length; i++) {
if (this.refs['email_' + i].getWrappedInstance().validate(this.props.state.team.email)) {
emails.push(this.refs['email_' + i].getWrappedInstance().getValue());
} else {
valid = false;
}
}
if (valid) {
this.props.state.invites = emails;
}
}
if (valid) {
this.props.state.wizard = 'username';
this.props.updateParent(this.props.state);
}
}
submitAddInvite(e) {
e.preventDefault();
this.props.state.wizard = 'send_invites';
if (!this.props.state.invites) {
this.props.state.invites = [];
}
this.props.state.invites.push('');
this.props.updateParent(this.props.state);
}
submitSkip(e) {
e.preventDefault();
this.props.state.wizard = 'username';
this.props.updateParent(this.props.state);
}
keySubmit(e) {
if (e && e.keyCode === 13) {
this.submitNext(e);
}
}
componentDidMount() {
if (!this.state.emailEnabled) {
// Must use keypress not keyup due to event chain of pressing enter
$('body').keypress(this.keySubmit);
}
}
componentWillUnmount() {
if (!this.state.emailEnabled) {
$('body').off('keypress', this.keySubmit);
}
}
render() {
Client.track('signup', 'signup_team_05_send_invites');
var content = null;
var bottomContent = null;
if (this.state.emailEnabled) {
var emails = [];
for (var i = 0; i < this.props.state.invites.length; i++) {
if (i === 0) {
emails.push(