code cleanup

This commit is contained in:
zmagod 2017-11-06 15:37:09 +01:00
parent 54e360bb52
commit 3255d5cf7c
4 changed files with 19 additions and 21 deletions

View file

@ -45,7 +45,9 @@ class TeamSwitch extends Component<Props, State> {
changeTeam(teamId) {
this.props.changeTeam(teamId);
window.location = ROOT_PATH;
setTimeout(() => {
window.location = ROOT_PATH;
}, 1500);
}
displayTeams() {

View file

@ -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<Teams$Team>): 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);
});

View file

@ -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<Props> {
@ -41,10 +41,9 @@ class LeaveTeamModal extends Component<Props> {
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<Props> {
export default connect(null, {
addTeamsData,
setCurrentTeam
getCurrentTeam
})(LeaveTeamModal);

View file

@ -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<*> =>