// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var EmailItem = require('./team_signup_email_item.jsx'); var Client = require('../utils/client.jsx'); 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.config.ByPassEmail }; if (!this.state.emailEnabled) { this.props.state.wizard = 'username'; this.props.updateParent(this.props.state); } } 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].validate(this.props.state.team.email)) { valid = false; } else { emails.push(this.refs['email_' + i].getValue()); } } 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( ); } else { emails.push( ); } } content = (
{emails}
Add Invitation
); bottomContent = (

{'if you prefer, you can invite team members later'}
{' and '} {'skip this step '} {'for now.'}

); } else { content = (
{'Email is currently disabled for your team, and emails cannot be sent. Contact your system administrator to enable email and email invitations.'}
); } return (

{'Invite Team Members'}

{content}
{bottomContent}
); } } TeamSignupSendInvitesPage.propTypes = { state: React.PropTypes.object.isRequired, updateParent: React.PropTypes.func.isRequired };