From b54d1342990253d3fe4a00c64df27cdd1bb0719b Mon Sep 17 00:00:00 2001 From: David Meza Date: Thu, 3 Aug 2017 07:59:42 -0500 Subject: PLT-6484 Add /leave command to leave a channel (#6402) * PLT-6484 Add /leave command to leave a channel * Text changes requeted on review. * PLT-6484 Display the right error message when trying to /leave town-square * PLT-6484 Be able to execute /leave command in direct and group message channels with the same effect as clicking x * PLT-6484 Refactor to create new leave_private_channel_modal.jsx * PLT-6484 Remove previous leave private channel logic to use new leave_private_channel_modal.jsx * Remove dot in command description. Change localized error when leaving Town square. * disable /leave command in reply threads on the right-hand sidebar, since it is not obvious which channel you should leave --- webapp/components/channel_header.jsx | 59 +--------- .../modals/leave_private_channel_modal.jsx | 120 +++++++++++++++++++++ webapp/components/navbar.jsx | 62 +---------- webapp/components/needs_team/needs_team.jsx | 2 + 4 files changed, 125 insertions(+), 118 deletions(-) create mode 100644 webapp/components/modals/leave_private_channel_modal.jsx (limited to 'webapp/components') diff --git a/webapp/components/channel_header.jsx b/webapp/components/channel_header.jsx index 10e568794..bee06c700 100644 --- a/webapp/components/channel_header.jsx +++ b/webapp/components/channel_header.jsx @@ -14,7 +14,6 @@ import ChannelMembersModal from './channel_members_modal.jsx'; import ChannelNotificationsModal from './channel_notifications_modal.jsx'; import DeleteChannelModal from './delete_channel_modal.jsx'; import RenameChannelModal from './rename_channel_modal.jsx'; -import ConfirmModal from './confirm_modal.jsx'; import ToggleModalButton from './toggle_modal_button.jsx'; import ChannelStore from 'stores/channel_store.jsx'; @@ -60,8 +59,6 @@ export default class ChannelHeader extends React.Component { this.initWebrtc = this.initWebrtc.bind(this); this.onBusy = this.onBusy.bind(this); this.openDirectMessageModal = this.openDirectMessageModal.bind(this); - this.createLeaveChannelModal = this.createLeaveChannelModal.bind(this); - this.hideLeaveChannelModal = this.hideLeaveChannelModal.bind(this); const state = this.getStateFromStores(); state.showEditChannelHeaderModal = false; @@ -91,7 +88,6 @@ export default class ChannelHeader extends React.Component { enableFormatting: PreferenceStore.getBool(Preferences.CATEGORY_ADVANCED_SETTINGS, 'formatting', true), isBusy: WebrtcStore.isBusy(), isFavorite: channel && ChannelUtils.isFavoriteChannel(channel), - showLeaveChannelModal: false, pinsOpen: SearchStore.getIsPinnedPosts() }; } @@ -144,9 +140,7 @@ export default class ChannelHeader extends React.Component { handleLeave() { if (this.state.channel.type === Constants.PRIVATE_CHANNEL) { - this.setState({ - showLeaveChannelModal: true - }); + GlobalActions.showLeavePrivateChannelModal(this.state.channel); } else { ChannelActions.leaveChannel(this.state.channel.id); } @@ -233,54 +227,6 @@ export default class ChannelHeader extends React.Component { }); } - hideLeaveChannelModal() { - this.setState({ - showLeaveChannelModal: false - }); - } - - createLeaveChannelModal() { - const title = ( - {this.state.channel.display_name} - }} - /> - ); - - const message = ( - {this.state.channel.display_name} - }} - /> - ); - - const buttonClass = 'btn btn-danger'; - const button = ( - - ); - - return ( - ChannelActions.leaveChannel(this.state.channel.id)} - onCancel={this.hideLeaveChannelModal} - /> - ); - } - render() { const flagIcon = Constants.FLAG_ICON_SVG; const pinIcon = Constants.PIN_ICON_SVG; @@ -885,8 +831,6 @@ export default class ChannelHeader extends React.Component { ); } - const leaveChannelModal = this.createLeaveChannelModal(); - let pinnedIconClass = 'channel-header__icon'; if (this.state.pinsOpen) { pinnedIconClass += ' active'; @@ -1001,7 +945,6 @@ export default class ChannelHeader extends React.Component { {editHeaderModal} {editPurposeModal} {channelMembersModal} - {leaveChannelModal} {this.state.channel.display_name} + }} + /> + ); + + message = ( + {this.state.channel.display_name} + }} + /> + ); + } + + const buttonClass = 'btn btn-danger'; + const button = ( + + ); + + return ( + + ); + } +} + +LeavePrivateChannelModal.propTypes = { + intl: intlShape.isRequired +}; + +export default injectIntl(LeavePrivateChannelModal); diff --git a/webapp/components/navbar.jsx b/webapp/components/navbar.jsx index 81959f352..0217dc15c 100644 --- a/webapp/components/navbar.jsx +++ b/webapp/components/navbar.jsx @@ -12,7 +12,6 @@ import ChannelMembersModal from './channel_members_modal.jsx'; import ChannelNotificationsModal from './channel_notifications_modal.jsx'; import DeleteChannelModal from './delete_channel_modal.jsx'; import RenameChannelModal from './rename_channel_modal.jsx'; -import ConfirmModal from './confirm_modal.jsx'; import ToggleModalButton from './toggle_modal_button.jsx'; import StatusIcon from './status_icon.jsx'; @@ -75,9 +74,6 @@ export default class Navbar extends React.Component { this.openDirectMessageModal = this.openDirectMessageModal.bind(this); this.getPinnedPosts = this.getPinnedPosts.bind(this); - this.createLeaveChannelModal = this.createLeaveChannelModal.bind(this); - this.hideLeaveChannelModal = this.hideLeaveChannelModal.bind(this); - const state = this.getStateFromStores(); state.showEditChannelPurposeModal = false; state.showEditChannelHeaderModal = false; @@ -97,8 +93,7 @@ export default class Navbar extends React.Component { users: [], userCount: ChannelStore.getCurrentStats().member_count, currentUser: UserStore.getCurrentUser(), - isFavorite: channel && ChannelUtils.isFavoriteChannel(channel), - showLeaveChannelModal: false + isFavorite: channel && ChannelUtils.isFavoriteChannel(channel) }; } @@ -139,9 +134,7 @@ export default class Navbar extends React.Component { handleLeave() { if (this.state.channel.type === Constants.PRIVATE_CHANNEL) { - this.setState({ - showLeaveChannelModal: true - }); + GlobalActions.showLeavePrivateChannelModal(this.state.channel); } else { ChannelActions.leaveChannel(this.state.channel.id); } @@ -739,54 +732,6 @@ export default class Navbar extends React.Component { return buttons; } - hideLeaveChannelModal() { - this.setState({ - showLeaveChannelModal: false - }); - } - - createLeaveChannelModal() { - const title = ( - {this.state.channel.display_name} - }} - /> - ); - - const message = ( - {this.state.channel.display_name} - }} - /> - ); - - const buttonClass = 'btn btn-danger'; - const button = ( - - ); - - return ( - ChannelActions.leaveChannel(this.state.channel.id)} - onCancel={this.hideLeaveChannelModal} - /> - ); - } - getTeammateStatus() { const channel = this.state.channel; @@ -961,8 +906,6 @@ export default class Navbar extends React.Component { var channelMenuDropdown = this.createDropdown(channel, channelTitle, isSystemAdmin, isTeamAdmin, isChannelAdmin, isDirect, isGroup, popoverContent); - const leaveChannelModal = this.createLeaveChannelModal(); - return (
); -- cgit v1.2.3-1-g7c22