You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
7 years ago
|
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(""));
|
||
|
}
|
||
|
}
|