2016-08-15 23:06:12 +02:00
|
|
|
import axios from 'axios';
|
2017-02-22 20:29:35 +01:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2019-05-01 22:32:39 +02:00
|
|
|
import { startLoader, stopLoader } from './loader';
|
2016-08-15 23:06:12 +02:00
|
|
|
|
2018-08-24 23:41:23 +02:00
|
|
|
const __process = (typeof global !== 'undefined' ? global : window).process;
|
|
|
|
const ROOT_URL = __process.env.API_URL;
|
2016-08-15 23:06:12 +02:00
|
|
|
|
2019-06-19 22:21:25 +02:00
|
|
|
// eslint-disable-next-line
|
2016-08-17 21:53:25 +02:00
|
|
|
export function getProjects(username) {
|
2016-08-15 23:06:12 +02:00
|
|
|
return (dispatch) => {
|
2019-05-01 22:32:39 +02:00
|
|
|
dispatch(startLoader());
|
2016-08-17 21:53:25 +02:00
|
|
|
let url;
|
|
|
|
if (username) {
|
|
|
|
url = `${ROOT_URL}/${username}/projects`;
|
|
|
|
} else {
|
|
|
|
url = `${ROOT_URL}/projects`;
|
|
|
|
}
|
|
|
|
axios.get(url, { withCredentials: true })
|
2017-02-22 20:29:35 +01:00
|
|
|
.then((response) => {
|
2016-08-15 23:06:12 +02:00
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_PROJECTS,
|
|
|
|
projects: response.data
|
|
|
|
});
|
2019-05-01 22:32:39 +02:00
|
|
|
dispatch(stopLoader());
|
2016-08-15 23:06:12 +02:00
|
|
|
})
|
2020-04-25 16:48:39 +02:00
|
|
|
.catch((error) => {
|
|
|
|
const { response } = error;
|
2019-05-01 22:32:39 +02:00
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
});
|
|
|
|
dispatch(stopLoader());
|
|
|
|
});
|
2016-08-15 23:06:12 +02:00
|
|
|
};
|
|
|
|
}
|