2017-08-21 21:30:54 +08:00
|
|
|
import axios from "../../app/axios";
|
2017-08-03 22:03:15 +08:00
|
|
|
import _ from "lodash";
|
|
|
|
import { TEAMS_PATH, CHANGE_TEAM_PATH } from "../../app/routes";
|
2017-08-09 21:21:02 +08:00
|
|
|
import { GET_LIST_OF_TEAMS, SET_CURRENT_TEAM } from "../../app/action_types";
|
2017-08-03 22:03:15 +08:00
|
|
|
|
2017-08-28 23:05:09 +08:00
|
|
|
export function addTeamsData(data) {
|
2017-08-03 22:03:15 +08:00
|
|
|
return {
|
|
|
|
type: GET_LIST_OF_TEAMS,
|
|
|
|
payload: data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:05:09 +08:00
|
|
|
export function setCurrentTeam(team) {
|
2017-08-03 22:03:15 +08:00
|
|
|
return {
|
2017-08-28 23:05:09 +08:00
|
|
|
team,
|
2017-08-07 19:51:22 +08:00
|
|
|
type: SET_CURRENT_TEAM
|
2017-08-03 22:03:15 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTeamsList() {
|
|
|
|
return dispatch => {
|
|
|
|
axios
|
|
|
|
.get(TEAMS_PATH, { withCredentials: true })
|
|
|
|
.then(response => {
|
2017-08-25 14:54:32 +08:00
|
|
|
const teams = response.data.teams.collection;
|
2017-08-03 22:03:15 +08:00
|
|
|
dispatch(addTeamsData(teams));
|
2017-08-25 14:54:32 +08:00
|
|
|
const currentTeam = _.find(teams, team => team.current_team);
|
2017-08-28 23:05:09 +08:00
|
|
|
dispatch(setCurrentTeam(currentTeam));
|
2017-08-03 22:03:15 +08:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log("get Teams Error: ", error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:05:09 +08:00
|
|
|
export function changeTeam(teamId) {
|
2017-08-03 22:03:15 +08:00
|
|
|
return dispatch => {
|
|
|
|
axios
|
2017-08-30 22:18:21 +08:00
|
|
|
.post(CHANGE_TEAM_PATH, { team_id: 44 }, { withCredentials: true })
|
2017-08-03 22:03:15 +08:00
|
|
|
.then(response => {
|
2017-08-28 23:05:09 +08:00
|
|
|
const teams = response.data.teams.collection;
|
2017-08-03 22:03:15 +08:00
|
|
|
dispatch(addTeamsData(teams));
|
2017-08-28 23:05:09 +08:00
|
|
|
const currentTeam = _.find(teams, team => team.current_team);
|
|
|
|
dispatch(setCurrentTeam(currentTeam));
|
2017-08-03 22:03:15 +08:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.log("get Teams Error: ", error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|