Converted GetLinkModal to React-Bootstrap and added GetTeamInviteLinkModal

This commit is contained in:
hmhealey
2015-11-19 11:59:59 -05:00
parent e8f6dd2f33
commit b20144db8e
10 changed files with 163 additions and 108 deletions

View File

@@ -1,32 +1,28 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import UserStore from '../stores/user_store.jsx';
const Modal = ReactBootstrap.Modal;
export default class GetLinkModal extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
this.onShow = this.onShow.bind(this);
this.onHide = this.onHide.bind(this);
this.state = {copiedLink: false};
}
onShow(e) {
var button = e.relatedTarget;
this.setState({title: $(button).attr('data-title'), value: $(button).attr('data-value')});
this.copyLink = this.copyLink.bind(this);
this.state = {
copiedLink: false
};
}
onHide() {
this.setState({copiedLink: false});
this.props.onHide();
}
componentDidMount() {
if (this.refs.modal) {
$(ReactDOM.findDOMNode(this.refs.modal)).on('show.bs.modal', this.onShow);
$(ReactDOM.findDOMNode(this.refs.modal)).on('hide.bs.modal', this.onHide);
}
}
handleClick() {
copyLink() {
var copyTextarea = $(ReactDOM.findDOMNode(this.refs.textarea));
copyTextarea.select();
@@ -41,8 +37,18 @@ export default class GetLinkModal extends React.Component {
this.setState({copiedLink: false});
}
}
render() {
var currentUser = UserStore.getCurrentUser();
let helpText = null;
if (this.props.helpText) {
helpText = (
<p>
{this.props.helpText}
<br />
<br />
</p>
);
}
let copyLink = null;
if (document.queryCommandSupported('copy')) {
@@ -51,75 +57,59 @@ export default class GetLinkModal extends React.Component {
data-copy-btn='true'
type='button'
className='btn btn-primary pull-left'
onClick={this.handleClick}
data-clipboard-text={this.state.value}
onClick={this.copyLink}
>
Copy Link
{'Copy Link'}
</button>
);
}
var copyLinkConfirm = null;
if (this.state.copiedLink) {
copyLinkConfirm = <p className='alert alert-success copy-link-confirm'><i className='fa fa-check'></i> Link copied to clipboard.</p>;
copyLinkConfirm = <p className='alert alert-success copy-link-confirm'><i className='fa fa-check'></i>{' Link copied to clipboard.'}</p>;
}
if (currentUser != null) {
return (
<div
className='modal fade'
ref='modal'
id='get_link'
tabIndex='-1'
role='dialog'
aria-hidden='true'
>
<div className='modal-dialog'>
<div className='modal-content'>
<div className='modal-header'>
<button
type='button'
className='close'
data-dismiss='modal'
aria-label='Close'
>
<span aria-hidden='true'>&times;</span>
</button>
<h4
className='modal-title'
id='myModalLabel'
>
{this.state.title} Link
</h4>
</div>
<div className='modal-body'>
<p>
Send teammates the link below for them to sign-up to this team site.
<br /><br />
</p>
<textarea
className='form-control no-resize min-height'
readOnly='true'
ref='textarea'
value={this.state.value}
/>
</div>
<div className='modal-footer'>
<button
type='button'
className='btn btn-default'
data-dismiss='modal'
>
Close
</button>
{copyLink}
{copyLinkConfirm}
</div>
</div>
</div>
</div>
);
}
return <div/>;
return (
<Modal
show={this.props.show}
onHide={this.onHide}
>
<Modal.Header closeButton={true}>
{this.props.title}
</Modal.Header>
<Modal.Body>
{helpText}
<textarea
className='form-control no-resize min-height'
readOnly='true'
ref='textarea'
value={this.props.link}
/>
</Modal.Body>
<Modal.Footer>
<button
type='button'
className='btn btn-default'
onClick={this.onHide}
>
{'Close'}
</button>
{copyLink}
{copyLinkConfirm}
</Modal.Footer>
</Modal>
);
}
}
GetLinkModal.propTypes = {
show: React.PropTypes.bool.isRequired,
onHide: React.PropTypes.func.isRequired,
title: React.PropTypes.string.isRequired,
helpText: React.PropTypes.string,
link: React.PropTypes.string.isRequired
};
GetLinkModal.defaultProps = {
helpText: null
};

View File

@@ -0,0 +1,53 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import Constants from '../utils/constants.jsx';
import GetLinkModal from './get_link_modal.jsx';
import ModalStore from '../stores/modal_store.jsx';
import TeamStore from '../stores/team_store.jsx';
export default class GetTeamInviteLinkModal extends React.Component {
constructor(props) {
super(props);
this.handleToggle = this.handleToggle.bind(this);
this.state = {
show: false
};
}
componentDidMount() {
ModalStore.addModalListener(Constants.ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL, this.handleToggle);
}
componentWillUnmount() {
ModalStore.removeModalListener(Constants.ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL, this.handleToggle);
}
handleToggle(value) {
this.setState({
show: value
});
}
render() {
return (
<GetLinkModal
show={this.state.show}
onHide={() => this.setState({show: false})}
title='Team Invite Link'
helpText='Send teammates the link below for them to sign-up to this team site.'
link={TeamStore.getCurrentInviteLink()}
/>
);
}
static show() {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL,
value: true
});
}
}

View File

@@ -10,6 +10,7 @@ import ModalStore from '../stores/modal_store.jsx';
import UserStore from '../stores/user_store.jsx';
import TeamStore from '../stores/team_store.jsx';
import ConfirmModal from './confirm_modal.jsx';
import GetTeamInviteLinkModal from './get_team_invite_link_modal.jsx';
const Modal = ReactBootstrap.Modal;
@@ -23,6 +24,7 @@ export default class InviteMemberModal extends React.Component {
this.addInviteFields = this.addInviteFields.bind(this);
this.clearFields = this.clearFields.bind(this);
this.removeInviteFields = this.removeInviteFields.bind(this);
this.showGetTeamInviteLinkModal = this.showGetTeamInviteLinkModal.bind(this);
this.state = {
show: false,
@@ -188,6 +190,12 @@ export default class InviteMemberModal extends React.Component {
this.setState({inviteIds: inviteIds, idCount: count});
}
showGetTeamInviteLinkModal() {
this.handleHide(false);
GetTeamInviteLinkModal.show();
}
render() {
var currentUser = UserStore.getCurrentUser();
@@ -333,22 +341,18 @@ export default class InviteMemberModal extends React.Component {
} else {
var teamInviteLink = null;
if (currentUser && TeamStore.getCurrent().type === 'O') {
var linkUrl = utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + TeamStore.getCurrent().invite_id;
var link =
(
<a
href='#'
data-toggle='modal'
data-target='#get_link'
data-title='Team Invite'
data-value={linkUrl}
onClick={() => this.handleHide(this, false)}
>Team Invite Link</a>
var link = (
<a
href='#'
onClick={this.showGetTeamInviteLinkModal}
>
{'Team Invite Link'}
</a>
);
teamInviteLink = (
<p>
You can also invite people using the {link}.
{'You can also invite people using the '}{link}{'.'}
</p>
);
}

View File

@@ -7,6 +7,7 @@ import UserStore from '../stores/user_store.jsx';
import TeamStore from '../stores/team_store.jsx';
import AboutBuildModal from './about_build_modal.jsx';
import GetTeamInviteLinkModal from './get_team_invite_link_modal.jsx';
import InviteMemberModal from './invite_member_modal.jsx';
import UserSettingsModal from './user_settings/user_settings_modal.jsx';
@@ -105,10 +106,7 @@ export default class NavbarDropdown extends React.Component {
<li>
<a
href='#'
data-toggle='modal'
data-target='#get_link'
data-title='Team Invite'
data-value={Utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + TeamStore.getCurrent().invite_id}
onClick={GetTeamInviteLinkModal.show}
>
{'Get Team Invite Link'}
</a>

View File

@@ -1,10 +1,10 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import GetTeamInviteLinkModal from './get_team_invite_link_modal.jsx';
import InviteMemberModal from './invite_member_modal.jsx';
import UserSettingsModal from './user_settings/user_settings_modal.jsx';
import UserStore from '../stores/user_store.jsx';
import TeamStore from '../stores/team_store.jsx';
import * as client from '../utils/client.jsx';
import * as utils from '../utils/utils.jsx';
@@ -56,12 +56,12 @@ export default class SidebarRightMenu extends React.Component {
if (this.props.teamType === 'O') {
teamLink = (
<li>
<a href='#'
data-toggle='modal'
data-target='#get_link'
data-title='Team Invite'
data-value={utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + TeamStore.getCurrent().invite_id}
><i className='fa fa-link'></i>Get Team Invite Link</a>
<a
href='#'
onClick={GetTeamInviteLinkModal.show}
>
<i className='glyphicon glyphicon-link'></i>{'Get Team Invite Link'}
</a>
</li>
);
}

View File

@@ -7,7 +7,7 @@ import ErrorBar from '../components/error_bar.jsx';
import ErrorStore from '../stores/error_store.jsx';
import MentionList from '../components/mention_list.jsx';
import GetLinkModal from '../components/get_link_modal.jsx';
import GetTeamInviteLinkModal from '../components/get_team_invite_link_modal.jsx';
import RenameChannelModal from '../components/rename_channel_modal.jsx';
import EditPostModal from '../components/edit_post_modal.jsx';
import DeletePostModal from '../components/delete_post_modal.jsx';
@@ -67,8 +67,8 @@ function setupChannelPage(props, team, channel) {
// Modals
//
ReactDOM.render(
<GetLinkModal />,
document.getElementById('get_link_modal')
<GetTeamInviteLinkModal />,
document.getElementById('get_team_invite_link_modal')
);
ReactDOM.render(

View File

@@ -34,6 +34,7 @@ class ModalStoreClass extends EventEmitter {
case ActionTypes.TOGGLE_IMPORT_THEME_MODAL:
case ActionTypes.TOGGLE_INVITE_MEMBER_MODAL:
case ActionTypes.TOGGLE_DELETE_POST_MODAL:
case ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL:
this.emit(type, value, args);
break;
}

View File

@@ -31,6 +31,7 @@ class TeamStoreClass extends EventEmitter {
this.getCurrentId = this.getCurrentId.bind(this);
this.getCurrent = this.getCurrent.bind(this);
this.getCurrentTeamUrl = this.getCurrentTeamUrl.bind(this);
this.getCurrentInviteLink = this.getCurrentInviteLink.bind(this);
this.saveTeam = this.saveTeam.bind(this);
}
@@ -92,6 +93,16 @@ class TeamStoreClass extends EventEmitter {
return null;
}
getCurrentInviteLink() {
const current = this.getCurrent();
if (current) {
return getWindowLocationOrigin() + '/signup_user_complete/?id=' + current.invite_id;
}
return '';
}
saveTeam(team) {
var teams = this.getAll();
teams[team.id] = team;

View File

@@ -101,10 +101,7 @@ export function createDefaultIntroMessage(channel) {
<a
className='intro-links'
href='#'
data-toggle='modal'
data-target='#get_link'
data-title='Team Invite'
data-value={Utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + team.id}
onClick={GetTeamInviteLinkModal.show}
>
<i className='fa fa-user-plus'></i>{'Invite others to this team'}
</a>

View File

@@ -48,7 +48,8 @@ export default {
TOGGLE_IMPORT_THEME_MODAL: null,
TOGGLE_INVITE_MEMBER_MODAL: null,
TOGGLE_DELETE_POST_MODAL: null
TOGGLE_DELETE_POST_MODAL: null,
TOGGLE_GET_TEAM_INVITE_LINK_MODAL: null
}),
PayloadSources: keyMirror({