Skip to content

Commit

Permalink
MM-15763: Displays custom error message when rejected to join team vi…
Browse files Browse the repository at this point in the history
…a UI. (mattermost#2863)
  • Loading branch information
mkraft committed May 28, 2019
1 parent b481b79 commit 36813d1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ exports[`components/select_team/SelectTeam should match snapshot, on error 1`] =
<label
className="control-label"
>
error message
<Component />
</label>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions components/select_team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function mapStateToProps(state) {
canManageSystem: haveISystemPermission(state, {permission: Permissions.MANAGE_SYSTEM}),
canJoinPublicTeams: haveISystemPermission(state, {permission: Permissions.JOIN_PUBLIC_TEAMS}),
canJoinPrivateTeams: haveISystemPermission(state, {permission: Permissions.JOIN_PRIVATE_TEAMS}),
siteURL: config.SiteURL,
};
}

Expand Down
30 changes: 28 additions & 2 deletions components/select_team/select_team.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import SystemPermissionGate from 'components/permissions_gates/system_permission
import SiteNameAndDescription from 'components/common/site_name_and_description';
import LogoutIcon from 'components/icon/logout_icon';

import FormattedMarkdownMessage from 'components/formatted_markdown_message';

import SelectTeamItem from './components/select_team_item.jsx';

const TEAMS_PER_PAGE = 200;
const TEAM_MEMBERSHIP_DENIAL_ERROR_ID = 'api.team.add_members.user_denied';

export default class SelectTeam extends React.Component {
static propTypes = {
Expand All @@ -39,6 +42,7 @@ export default class SelectTeam extends React.Component {
canJoinPublicTeams: PropTypes.bool.isRequired,
canJoinPrivateTeams: PropTypes.bool.isRequired,
history: PropTypes.object,
siteURL: PropTypes.string,
actions: PropTypes.shape({
getTeams: PropTypes.func.isRequired,
loadRolesIfNeeded: PropTypes.func.isRequired,
Expand Down Expand Up @@ -69,14 +73,36 @@ export default class SelectTeam extends React.Component {
}

handleTeamClick = async (team) => {
const {siteURL, currentUserRoles} = this.props;
this.setState({loadingTeamId: team.id});

const {data, error} = await this.props.actions.addUserToTeam(team.id, this.props.currentUserId);
if (data) {
this.props.history.push(`/${team.name}/channels/${Constants.DEFAULT_CHANNEL}`);
} else if (error) {
let errorMsg = error.message;

if (error.server_error_id === TEAM_MEMBERSHIP_DENIAL_ERROR_ID) {
if (currentUserRoles.includes(Constants.PERMISSIONS_SYSTEM_ADMIN)) {
errorMsg = (
<FormattedMarkdownMessage
id='join_team_group_constrained_denied_admin'
defaultMessage={`You need to be a member of a linked group to join this team. You can add a group to this team [here](${siteURL}/admin_console/user_management/groups).`}
values={{siteURL}}
/>
);
} else {
errorMsg = (
<FormattedMarkdownMessage
id='join_team_group_constrained_denied'
defaultMessage='You need to be a member of a linked group to join this team.'
/>
);
}
}

this.setState({
error,
error: errorMsg,
loadingTeamId: '',
});
}
Expand Down Expand Up @@ -114,7 +140,7 @@ export default class SelectTeam extends React.Component {
openContent = (
<div className='signup__content'>
<div className={'form-group has-error'}>
<label className='control-label'>{this.state.error.message}</label>
<label className='control-label'>{this.state.error}</label>
</div>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,8 @@
"invite_member.send2": "Send Invitations",
"invite_member.sending": " Sending",
"invite_member.teamInviteLink": "You can also invite people using the {link}.",
"join_team_group_constrained_denied": "You need to be a member of a linked group to join this team.",
"join_team_group_constrained_denied_admin": "You need to be a member of a linked group to join this team. You can add a group to this team [here]({siteURL}/admin_console/user_management/groups).",
"katex.error": "Couldn't compile your Latex code. Please review the syntax and try again.",
"last_users_message.added_to_channel.type": "were **added to the channel** by {actor}.",
"last_users_message.added_to_team.type": "were **added to the team** by {actor}.",
Expand Down

0 comments on commit 36813d1

Please sign in to comment.