List projet + list request

This commit is contained in:
Gael Peltey
2020-02-19 11:53:32 +01:00
parent da5583c797
commit a10297e22a
15 changed files with 414 additions and 14 deletions

View File

@ -0,0 +1,53 @@
import { call, put } from 'redux-saga/effects';
import { projectUserListFailure, projectUserListSuccess, projectListFailure, projectListSuccess } from '../actions/project';
export function* projectUserListSaga() {
let result
try {
result = yield call(projectUserList);
} catch(err) {
yield put(projectUserListFailure(err));
return
}
if ('error' in result) {
yield put(projectUserListFailure(result.error));
return
}
yield put(projectUserListSuccess(result.data));
}
const projectUserList = () => {
return fetch('http://localhost:8001/api/v1/me', {
method: 'GET',
mode: 'cors',
credentials: 'include'
}).then(res => res.json())
}
export function* projectListSaga() {
let result
try {
result = yield call(projectList);
} catch(err) {
yield put(projectListFailure(err));
return
}
if ('error' in result) {
yield put(projectListFailure(result.error));
return
}
yield put(projectListSuccess(result.data));
}
const projectList = () => {
return fetch('http://localhost:8001/api/v1/projects', {
method: 'GET',
mode: 'cors',
credentials: 'include'
}).then(res => res.json())
}

View File

@ -1,7 +1,10 @@
import { all, takeLatest } from 'redux-saga/effects';
import { PROJECT_USER_LIST, PROJECT_LIST } from '../actions/project';
import { projectUserListSaga, projectListSaga } from './project';
export default function* rootSaga() {
yield all([
takeLatest(PROJECT_USER_LIST, projectUserListSaga),
takeLatest(PROJECT_LIST, projectListSaga),
]);
}