List projet + list request
This commit is contained in:
53
frontend/src/sagas/project.js
Normal file
53
frontend/src/sagas/project.js
Normal 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())
|
||||
}
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user