diff --git a/app/javascript/src/components/Navigation/components/TeamSwitch.jsx b/app/javascript/src/components/Navigation/components/TeamSwitch.jsx index 5518074f3..88ccc0f72 100644 --- a/app/javascript/src/components/Navigation/components/TeamSwitch.jsx +++ b/app/javascript/src/components/Navigation/components/TeamSwitch.jsx @@ -45,7 +45,9 @@ class TeamSwitch extends Component { changeTeam(teamId) { this.props.changeTeam(teamId); - window.location = ROOT_PATH; + setTimeout(() => { + window.location = ROOT_PATH; + }, 1500); } displayTeams() { diff --git a/app/javascript/src/components/actions/TeamsActions.js b/app/javascript/src/components/actions/TeamsActions.js index cbfa8883b..8daeb6cc2 100644 --- a/app/javascript/src/components/actions/TeamsActions.js +++ b/app/javascript/src/components/actions/TeamsActions.js @@ -5,7 +5,11 @@ import type { Actopm$SetCurrentTeam } from "flow-typed"; import type { Dispatch } from "redux-thunk"; -import { getTeams, changeCurrentTeam, fetchCurrentTeam } from "../../services/api/teams_api"; +import { + getTeams, + changeCurrentTeam, + fetchCurrentTeam +} from "../../services/api/teams_api"; import { GET_LIST_OF_TEAMS, SET_CURRENT_TEAM } from "../../config/action_types"; export function addTeamsData(data: Array): Action$AddTeamData { @@ -43,10 +47,7 @@ export function getCurrentTeam(): Dispatch { export function changeTeam(teamID: number): Dispatch { return dispatch => { changeCurrentTeam(teamID) - .then(response => { - const { teams } = response; - dispatch(addTeamsData(teams)); - }) + .then(response => dispatch(addTeamsData(response))) .catch(error => { console.log("get Teams Error: ", error); }); diff --git a/app/javascript/src/scenes/SettingsPage/scenes/teams/components/LeaveTeamModal.jsx b/app/javascript/src/scenes/SettingsPage/scenes/teams/components/LeaveTeamModal.jsx index b246d1e3d..feaa33253 100644 --- a/app/javascript/src/scenes/SettingsPage/scenes/teams/components/LeaveTeamModal.jsx +++ b/app/javascript/src/scenes/SettingsPage/scenes/teams/components/LeaveTeamModal.jsx @@ -8,7 +8,7 @@ import { leaveTeam } from "../../../../../services/api/teams_api"; import { addTeamsData, - setCurrentTeam + getCurrentTeam } from "../../../../../components/actions/TeamsActions"; type Team = { @@ -23,7 +23,7 @@ type Props = { team: Team, addTeamsData: Function, hideLeaveTeamModal: Function, - setCurrentTeam: Function + getCurrentTeam: Function }; class LeaveTeamModal extends Component { @@ -41,10 +41,9 @@ class LeaveTeamModal extends Component { const { id, user_team_id } = this.props.team; leaveTeam(id, user_team_id) .then(response => { - const { teams, currentTeam } = response; - this.props.updateTeamsState(teams); - this.props.addTeamsData(teams); - this.props.setCurrentTeam(currentTeam); + this.props.updateTeamsState(response); + this.props.addTeamsData(response); + this.props.getCurrentTeam(); }) .catch(error => { console.log("error: ", error.response.data.message); @@ -101,5 +100,5 @@ class LeaveTeamModal extends Component { export default connect(null, { addTeamsData, - setCurrentTeam + getCurrentTeam })(LeaveTeamModal); diff --git a/app/javascript/src/services/api/teams_api.js b/app/javascript/src/services/api/teams_api.js index dc8e7dad3..5015ed68c 100644 --- a/app/javascript/src/services/api/teams_api.js +++ b/app/javascript/src/services/api/teams_api.js @@ -27,17 +27,13 @@ export const getTeams = (): Promise<*> => axiosInstance.get(TEAMS_PATH).then(({ data }) => data.teams); export const changeCurrentTeam = (teamID: number): Promise<*> => - axiosInstance.post(CHANGE_TEAM_PATH, { team_id: teamID }).then(({ data }) => { - const teams = data.teams; - return { teams }; - }); + axiosInstance + .post(CHANGE_TEAM_PATH, { team_id: teamID }) + .then(({ data }) => data.teams); export const leaveTeam = (teamID: number, userTeamID: number): Promise<*> => { const teamUrl = `${LEAVE_TEAM_PATH}?team=${teamID}&user_team=${userTeamID}`; - return axiosInstance.delete(teamUrl).then(({ data }) => { - const teams = data.teams; - return { teams }; - }); + return axiosInstance.delete(teamUrl).then(({ data }) => data.teams); }; export const fetchCurrentTeam = (): Promise<*> =>