Finished functionally complete client registration workflow
This commit is contained in:
39
src/sagas/auth.sagas.js
Normal file
39
src/sagas/auth.sagas.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { effects } from "redux-saga";
|
||||
import {
|
||||
isSendingAuthRequest,
|
||||
setAuthRequestError,
|
||||
setAuthRequestSuccess,
|
||||
clearAuthRequestError,
|
||||
setFormEmail,
|
||||
setFormPassword,
|
||||
setFormPasswordConfirmation
|
||||
} from "../actions/auth/reducer.actions";
|
||||
import { registerUser } from "../api/auth.api";
|
||||
|
||||
/**
|
||||
* Saga for registering a new user.
|
||||
* @param {*} postBody
|
||||
*/
|
||||
function* registerUserCall(postBody) {
|
||||
yield effects.put(isSendingAuthRequest(true));
|
||||
const { email, password1, password2 } = postBody;
|
||||
try {
|
||||
return yield effects.call(registerUser, email, password1, password2);
|
||||
} catch (exception) {
|
||||
yield effects.put(setAuthRequestError(exception));
|
||||
return false;
|
||||
} finally {
|
||||
yield effects.put(isSendingAuthRequest(false));
|
||||
}
|
||||
}
|
||||
|
||||
export function* registerUserFlow(request) {
|
||||
const wasSucessful = yield effects.call(registerUserCall, request.data);
|
||||
if (wasSucessful) {
|
||||
yield effects.put(setAuthRequestSuccess(wasSucessful));
|
||||
yield effects.put(clearAuthRequestError());
|
||||
yield effects.put(setFormEmail(""));
|
||||
yield effects.put(setFormPassword(""));
|
||||
yield effects.put(setFormPasswordConfirmation(""));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import { takeLatest } from "redux-saga/effects";
|
||||
import { SEND_REGISTER_REQUEST } from "../constants/auth.constants";
|
||||
import { registerUserFlow } from "./auth.sagas";
|
||||
|
||||
export default function* rootSaga() {
|
||||
|
||||
yield takeLatest(SEND_REGISTER_REQUEST, registerUserFlow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user