mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-30 20:06:20 +08:00
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
|
import axios from "axios";
|
||
|
import _ from "lodash";
|
||
|
import { TEAMS_PATH, CHANGE_TEAM_PATH } from "../../app/routes";
|
||
|
import { GET_LIST_OF_TEAMS, SET_CURRENT_TEAM } from "./types";
|
||
|
|
||
|
function addTeamsData(data) {
|
||
|
return {
|
||
|
type: GET_LIST_OF_TEAMS,
|
||
|
payload: data
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function setCurrentUser(user) {
|
||
|
return {
|
||
|
type: SET_CURRENT_TEAM,
|
||
|
user: user
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function getTeamsList() {
|
||
|
return dispatch => {
|
||
|
axios
|
||
|
.get(TEAMS_PATH, { withCredentials: true })
|
||
|
.then(response => {
|
||
|
let teams = response.data;
|
||
|
dispatch(addTeamsData(teams));
|
||
|
let current_team = _.find(teams, team => team.current_team);
|
||
|
dispatch(setCurrentUser(current_team));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
console.log("get Teams Error: ", error);
|
||
|
});
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function changeTeam(team_id) {
|
||
|
console.log("in banana");
|
||
|
return dispatch => {
|
||
|
axios
|
||
|
.post(CHANGE_TEAM_PATH, { team_id }, { withCredentials: true })
|
||
|
.then(response => {
|
||
|
let teams = response.data;
|
||
|
dispatch(addTeamsData(teams));
|
||
|
let current_team = _.find(teams, team => team.current_team);
|
||
|
dispatch(setCurrentUser(current_team));
|
||
|
})
|
||
|
.catch(error => {
|
||
|
console.log("get Teams Error: ", error);
|
||
|
});
|
||
|
};
|
||
|
}
|