UserForm: ajout retour de validation d'API
This commit is contained in:
@ -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()
|
||||
]);
|
||||
}
|
||||
|
9
frontend/src/sagas/user/root.saga.js
Normal file
9
frontend/src/sagas/user/root.saga.js
Normal 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),
|
||||
]);
|
||||
}
|
17
frontend/src/sagas/user/user.saga.js
Normal file
17
frontend/src/sagas/user/user.saga.js
Normal 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));
|
||||
}
|
Reference in New Issue
Block a user