Functionally complete full registration workflow
This commit is contained in:
+145
-2
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user