2020-06-08 10:29:24 +00:00
|
|
|
import apiClient from '../../../utils/apiClient';
|
2017-02-22 19:29:35 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2019-05-01 20:32:39 +00:00
|
|
|
import { startLoader, stopLoader } from './loader';
|
2016-08-15 21:06:12 +00:00
|
|
|
|
2019-06-19 20:21:25 +00:00
|
|
|
// eslint-disable-next-line
|
2016-08-17 19:53:25 +00:00
|
|
|
export function getProjects(username) {
|
2016-08-15 21:06:12 +00:00
|
|
|
return (dispatch) => {
|
2019-05-01 20:32:39 +00:00
|
|
|
dispatch(startLoader());
|
2016-08-17 19:53:25 +00:00
|
|
|
let url;
|
|
|
|
if (username) {
|
2020-06-08 10:29:24 +00:00
|
|
|
url = `/${username}/projects`;
|
2016-08-17 19:53:25 +00:00
|
|
|
} else {
|
2020-06-08 10:29:24 +00:00
|
|
|
url = '/projects';
|
2016-08-17 19:53:25 +00:00
|
|
|
}
|
2020-06-08 10:29:24 +00:00
|
|
|
apiClient.get(url)
|
2017-02-22 19:29:35 +00:00
|
|
|
.then((response) => {
|
2016-08-15 21:06:12 +00:00
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_PROJECTS,
|
|
|
|
projects: response.data
|
|
|
|
});
|
2019-05-01 20:32:39 +00:00
|
|
|
dispatch(stopLoader());
|
2016-08-15 21:06:12 +00:00
|
|
|
})
|
2020-04-25 14:48:39 +00:00
|
|
|
.catch((error) => {
|
|
|
|
const { response } = error;
|
2019-05-01 20:32:39 +00:00
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
});
|
|
|
|
dispatch(stopLoader());
|
|
|
|
});
|
2016-08-15 21:06:12 +00:00
|
|
|
};
|
|
|
|
}
|