|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { Team } from "../../core/Team";
|
|
|
|
|
import { FETCH_TEAMS } from "../Constants";
|
|
|
|
|
import { FETCH_TEAMS, ADD_TEAM } from "../Constants";
|
|
|
|
|
|
|
|
|
|
export const setTeamsList = (teamsList: Team[]) => {
|
|
|
|
|
return {
|
|
|
|
@ -8,11 +8,32 @@ export const setTeamsList = (teamsList: Team[]) => {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const addNewTeam = (newTeam: Team) => {
|
|
|
|
|
return async dispatch => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Ecuries', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(newTeam)
|
|
|
|
|
});
|
|
|
|
|
const team = await response.json();
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ADD_TEAM,
|
|
|
|
|
payload: team
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('Error---------', error);
|
|
|
|
|
//dispatch(fetchDataRejected(error))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getTeamsList = () => {
|
|
|
|
|
return async dispatch => {
|
|
|
|
|
try {
|
|
|
|
|
const teamsPromise = await fetch('https://codefirst.iut.uca.fr/containers/enzojolys-r-dash_container/Ecuries');
|
|
|
|
|
console.log(teamsPromise);
|
|
|
|
|
const teamsListJson = await teamsPromise.json();
|
|
|
|
|
const teamsList: Team[] = teamsListJson.map(elt => new Team(elt["name"], elt["owner"], elt["users"], elt["logo"]));
|
|
|
|
|
dispatch(setTeamsList(teamsList));
|
|
|
|
@ -21,4 +42,4 @@ export const getTeamsList = () => {
|
|
|
|
|
//dispatch(fetchDataRejected(error))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|