UserForm: ajout retour de validation d'API

This commit is contained in:
2020-03-09 11:32:21 +01:00
parent de6832e94f
commit 67732aa00a
11 changed files with 163 additions and 19 deletions

View File

@ -2,11 +2,13 @@ import { all } from 'redux-saga/effects';
import { rootSaga as authRootSaga } from './auth/root.saga';
import { rootSaga as failureRootSaga } from './failure/root.saga';
import { rootSaga as initRootSaga } from './init/root.saga';
import { rootSaga as userRootSaga } from './user/root.saga';
export default function* rootSaga() {
yield all([
initRootSaga(),
authRootSaga(),
failureRootSaga(),
userRootSaga()
]);
}

View File

@ -0,0 +1,9 @@
import { all, takeLatest } from 'redux-saga/effects';
import { CREATE_USER_REQUEST } from '../../actions/user.actions';
import { createUserSaga } from './user.saga';
export function* rootSaga() {
yield all([
takeLatest(CREATE_USER_REQUEST, createUserSaga),
]);
}

View File

@ -0,0 +1,17 @@
import { call, put } from 'redux-saga/effects';
import { APIClient } from '../../services/api-client.service';
import { createUserFailure, createUserSuccess } from '../../actions/user.actions';
export function* createUserSaga({username, password}) {
const client = new APIClient();
let user;
try {
user = yield call(client.createUser, username, password);
} catch(err) {
console.error(err);
yield put(createUserFailure(err));
return
}
yield put(createUserSuccess(user));
}