Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Allow default team to be configured (#334)
Browse files Browse the repository at this point in the history
* Allow default team to be configured

* Rename DefaultTeamName to ExperimentalPrimaryTeam
  • Loading branch information
csduarte authored and enahum committed Jan 5, 2018
1 parent 2ba2458 commit 0db22ac
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 51 deletions.
11 changes: 10 additions & 1 deletion components/login/login_controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {addUserToTeamFromInvite} from 'actions/team_actions.jsx';
import {checkMfa, webLogin} from 'actions/user_actions.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';

import Constants from 'utils/constants.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx';
Expand Down Expand Up @@ -63,7 +64,11 @@ export default class LoginController extends React.Component {
componentDidMount() {
document.title = global.window.mm_config.SiteName;
BrowserStore.removeGlobalItem('team');
if (UserStore.getCurrentUser()) {
const experimentalPrimaryTeam = global.mm_config.ExperimentalPrimaryTeam;
const primaryTeam = TeamStore.getByName(experimentalPrimaryTeam);
if (UserStore.getCurrentUser() && primaryTeam) {
browserHistory.push(`/${primaryTeam.name}/channels/town-square`);
} else if (UserStore.getCurrentUser()) {
GlobalActions.redirectUserToDefaultTeam();
}

Expand Down Expand Up @@ -214,12 +219,16 @@ export default class LoginController extends React.Component {
}

finishSignin(team) {
const experimentalPrimaryTeam = global.mm_config.ExperimentalPrimaryTeam;
const primaryTeam = TeamStore.getByName(experimentalPrimaryTeam);
const query = this.props.location.query;
GlobalActions.loadCurrentLocale();
if (query.redirect_to && query.redirect_to.match(/^\/([^/]|$)/)) {
browserHistory.push(query.redirect_to);
} else if (team) {
browserHistory.push(`/${team.name}`);
} else if (primaryTeam) {
browserHistory.push(`/${primaryTeam.name}/channels/town-square`);
} else {
GlobalActions.redirectUserToDefaultTeam();
}
Expand Down
5 changes: 5 additions & 0 deletions components/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as GlobalActions from 'actions/global_actions.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import LocalizationStore from 'stores/localization_store.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx';

import Constants, {StoragePrefixes} from 'utils/constants.jsx';

Expand Down Expand Up @@ -91,9 +92,13 @@ export default class Root extends React.Component {
}

redirectIfNecessary(props) {
const experimentalPrimaryTeam = global.mm_config.ExperimentalPrimaryTeam;
const primaryTeam = TeamStore.getByName(experimentalPrimaryTeam);
if (props.location.pathname === '/') {
if (UserStore.getNoAccounts()) {
browserHistory.push('/signup_user_complete');
} else if (UserStore.getCurrentUser() && primaryTeam) {
browserHistory.push(`/${primaryTeam.name}/channels/town-square`);
} else if (UserStore.getCurrentUser()) {
GlobalActions.redirectUserToDefaultTeam();
} else {
Expand Down
70 changes: 36 additions & 34 deletions components/sidebar_header_dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,50 +387,52 @@ export default class SidebarHeaderDropdown extends React.Component {
);
}

const isAlreadyMember = this.state.teamMembers.reduce((result, item) => {
result[item.team_id] = true;
return result;
}, {});

for (const id in this.state.teamListings) {
if (this.state.teamListings.hasOwnProperty(id) && !isAlreadyMember[id]) {
moreTeams = true;
break;
if (!config.ExperimentalPrimaryTeam) {
const isAlreadyMember = this.state.teamMembers.reduce((result, item) => {
result[item.team_id] = true;
return result;
}, {});

for (const id in this.state.teamListings) {
if (this.state.teamListings.hasOwnProperty(id) && !isAlreadyMember[id]) {
moreTeams = true;
break;
}
}

if (moreTeams) {
teams.push(
<li key='joinTeam_li'>
<Link
id='joinAnotherTeam'
onClick={this.handleClick}
to='/select_team'
>
<FormattedMessage
id='navbar_dropdown.join'
defaultMessage='Join Another Team'
/>
</Link>
</li>
);
}
}

if (moreTeams) {
teams.push(
<li key='joinTeam_li'>
<Link
id='joinAnotherTeam'
onClick={this.handleClick}
to='/select_team'
<li key='leaveTeam_li'>
<button
className='style--none'
id='leaveTeam'
onClick={GlobalActions.showLeaveTeamModal}
>
<FormattedMessage
id='navbar_dropdown.join'
defaultMessage='Join Another Team'
id='navbar_dropdown.leave'
defaultMessage='Leave Team'
/>
</Link>
</button>
</li>
);
}

teams.push(
<li key='leaveTeam_li'>
<button
className='style--none'
id='leaveTeam'
onClick={GlobalActions.showLeaveTeamModal}
>
<FormattedMessage
id='navbar_dropdown.leave'
defaultMessage='Leave Team'
/>
</button>
</li>
);

let helpLink = null;
if (config.HelpLink) {
helpLink = (
Expand Down
35 changes: 19 additions & 16 deletions components/sidebar_right_menu/sidebar_right_menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class SidebarRightMenu extends React.Component {
}
}

if (moreTeams) {
if (moreTeams && !global.mm_config.ExperimentalPrimaryTeam) {
joinAnotherTeamLink = (
<li key='joinTeam_li'>
<Link to='/select_team'>
Expand Down Expand Up @@ -287,21 +287,24 @@ export default class SidebarRightMenu extends React.Component {
</li>
);

const leaveTeam = (
<li key='leaveTeam_li'>
<a
id='leaveTeam'
href='#'
onClick={GlobalActions.showLeaveTeamModal}
>
<LeaveTeamIcon className='icon'/>
<FormattedMessage
id='navbar_dropdown.leave'
defaultMessage='Leave Team'
/>
</a>
</li>
);
let leaveTeam = '';
if (!global.mm_config.ExperimentalPrimaryTeam) {
leaveTeam = (
<li key='leaveTeam_li'>
<a
id='leaveTeam'
href='#'
onClick={GlobalActions.showLeaveTeamModal}
>
<LeaveTeamIcon className='icon'/>
<FormattedMessage
id='navbar_dropdown.leave'
defaultMessage='Leave Team'
/>
</a>
</li>
);
}

if (isAdmin) {
teamSettingsLink = (
Expand Down

0 comments on commit 0db22ac

Please sign in to comment.