Functionally complete full registration workflow

This commit is contained in:
Alexander Wong
2017-09-04 00:30:18 -06:00
parent 561664a701
commit f0c30f1023
18 changed files with 699 additions and 24 deletions

View File

@@ -18,10 +18,22 @@ import {
resetPasswordFlow,
} from "./auth.sagas";
import {
SEND_GET_SELF_USER_REQUEST
GET_SELF_USER_REQUEST,
CREATE_USER_INFO_REQUEST,
UPDATE_USER_INFO_REQUEST,
CREATE_CLIENT_REQUEST,
UPDATE_CLIENT_REQUEST,
CREATE_PROVIDER_REQUEST,
UPDATE_PROVIDER_REQUEST
} from "../constants/user.constants";
import {
getSelfUserFlow
getSelfUserFlow,
createUserInfoFlow,
updateUserInfoFlow,
createClientFlow,
updateClientFlow,
createProviderFlow,
updateProviderFlow
} from "./user.sagas";
export default function* rootSaga() {
@@ -32,5 +44,11 @@ export default function* rootSaga() {
yield takeLatest(SEND_CHANGE_PASSWORD_REQUEST, changePasswordFlow);
yield takeLatest(SEND_FORGOT_PASSWORD_REQUEST, forgotPasswordFlow);
yield takeLatest(SEND_RESET_PASSWORD_REQUEST, resetPasswordFlow);
yield takeLatest(SEND_GET_SELF_USER_REQUEST, getSelfUserFlow);
yield takeLatest(GET_SELF_USER_REQUEST, getSelfUserFlow);
yield takeLatest(CREATE_USER_INFO_REQUEST, createUserInfoFlow);
yield takeLatest(UPDATE_USER_INFO_REQUEST, updateUserInfoFlow);
yield takeLatest(CREATE_CLIENT_REQUEST, createClientFlow);
yield takeLatest(UPDATE_CLIENT_REQUEST, updateClientFlow);
yield takeLatest(CREATE_PROVIDER_REQUEST, createProviderFlow);
yield takeLatest(UPDATE_PROVIDER_REQUEST, updateProviderFlow);
}

View File

@@ -6,9 +6,12 @@ import {
setUserRequestSuccess,
clearUserRequestError,
clearUserRequestSuccess,
setSelfUser
setSelfUser,
setCompleteRegistrationStep
} from "../actions/user/reducer.actions";
import { getSelfUser } from "../api/user.api";
import { getSelfUserRequest } from "../actions/user/saga.actions";
import { CLIENT_OR_PROVIDER_STEP } from "../constants/user.constants";
import { getSelfUser, createUserInfo, updateUserInfo, createClient, updateClient, createProvider, updateProvider } from "../api/user.api";
function* getSelfUserCall() {
yield effects.put(isSendingUserRequest(true));
@@ -32,6 +35,84 @@ function* getSelfUserCall() {
}
}
function* createUserInfoCall(postBody) {
yield effects.put(isSendingUserRequest(true));
const { phone_number } = postBody;
try {
return yield effects.call(createUserInfo, phone_number);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
function* updateUserInfoCall(payload) {
yield effects.put(isSendingUserRequest(true));
const { username, phone_number } = payload;
try {
return yield effects.call(updateUserInfo, username, phone_number);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
function* createClientCall(postBody) {
yield effects.put(isSendingUserRequest(true));
const { business_number } = postBody;
try {
return yield effects.call(createClient, business_number);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
function* updateClientCall(payload) {
yield effects.put(isSendingUserRequest(true));
const { username, business_number } = payload;
try {
return yield effects.call(updateClient, username, business_number);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
function* createProviderCall(postBody) {
yield effects.put(isSendingUserRequest(true));
const { sin } = postBody;
try {
return yield effects.call(createProvider, sin);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
function* updateProviderCall(payload) {
yield effects.put(isSendingUserRequest(true));
const { username, sin } = payload;
try {
return yield effects.call(updateProvider, username, sin);
} catch (exception) {
yield effects.put(setUserRequestError(exception));
return false;
} finally {
yield effects.put(isSendingUserRequest(false));
}
}
export function* getSelfUserFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
@@ -41,3 +122,65 @@ export function* getSelfUserFlow(request) {
yield effects.put(setSelfUser({}));
}
}
export function* createUserInfoFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(createUserInfoCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(setCompleteRegistrationStep(CLIENT_OR_PROVIDER_STEP));
yield effects.put(getSelfUserRequest());
}
}
export function* updateUserInfoFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(updateUserInfoCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(setCompleteRegistrationStep(CLIENT_OR_PROVIDER_STEP));
yield effects.put(getSelfUserRequest());
}
}
export function* createClientFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(createClientCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(getSelfUserRequest());
}
}
export function* updateClientFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(updateClientCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(getSelfUserRequest());
}
}
export function* createProviderFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(createProviderCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(getSelfUserRequest());
}
}
export function* updateProviderFlow(request) {
yield effects.put(clearUserRequestSuccess());
yield effects.put(clearUserRequestError());
const wasSuccessful = yield effects.call(updateProviderCall, request.data);
if (wasSuccessful) {
yield effects.put(clearUserRequestError());
yield effects.put(getSelfUserRequest());
}
}