e87390adb9
* update eslint and dependencies, fix linting errors that can be fixed with --fix * fix lots of linting errors * update eslintrc, fix some linting errors * fix all server side linting errors, untested * fix errors that fixing linting errors had caused * fix client side eslint errors * fix client side linting errors * fix refs lint errors * fix more linting errors * update eslint and dependencies, fix linting errors that can be fixed with --fix * fix lots of linting errors * update eslintrc, fix some linting errors * fix all server side linting errors, untested * fix errors that fixing linting errors had caused * fix client side eslint errors * fix client side linting errors * fix refs lint errors * fix more linting errors * fix some accessibility linting errors * fix a lot of linting errors * fix a billion more linting errors * hopefully fix all linting errors, still need to test * fix bugs that fixing linting had caused
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import axios from 'axios';
|
|
import * as ActionTypes from '../../../constants';
|
|
import { showErrorModal, setPreviousPath } from './ide';
|
|
import { resetProject } from './project';
|
|
|
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
|
|
|
export function getProjects(username) {
|
|
return (dispatch) => {
|
|
let url;
|
|
if (username) {
|
|
url = `${ROOT_URL}/${username}/projects`;
|
|
} else {
|
|
url = `${ROOT_URL}/projects`;
|
|
}
|
|
axios.get(url, { withCredentials: true })
|
|
.then((response) => {
|
|
dispatch({
|
|
type: ActionTypes.SET_PROJECTS,
|
|
projects: response.data
|
|
});
|
|
})
|
|
.catch(response => dispatch({
|
|
type: ActionTypes.ERROR,
|
|
error: response.data
|
|
}));
|
|
};
|
|
}
|
|
|
|
export function deleteProject(id) {
|
|
return (dispatch, getState) => {
|
|
axios.delete(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
|
|
.then(() => {
|
|
const state = getState();
|
|
if (id === state.project.id) {
|
|
dispatch(resetProject());
|
|
dispatch(setPreviousPath('/'));
|
|
}
|
|
dispatch({
|
|
type: ActionTypes.DELETE_PROJECT,
|
|
id
|
|
});
|
|
})
|
|
.catch((response) => {
|
|
if (response.status === 403) {
|
|
dispatch(showErrorModal('staleSession'));
|
|
} else {
|
|
dispatch({
|
|
type: ActionTypes.ERROR,
|
|
error: response.data
|
|
});
|
|
}
|
|
});
|
|
};
|
|
}
|