From 36d234d9508cc593a9b989957c5cc4beb5e723cd Mon Sep 17 00:00:00 2001 From: Riddhiagrawal001 <50551695+Riddhiagrawal001@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:38:16 +0530 Subject: [PATCH] fix: user management bugs (#1343) --- .../AuthModule/Common/CommonAuthTypes.res | 2 + .../AuthModule/Common/CommonAuthUtils.res | 2 + src/screens/APIUtils/APIUtils.res | 45 ++++++++++++------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/entryPoints/AuthModule/Common/CommonAuthTypes.res b/src/entryPoints/AuthModule/Common/CommonAuthTypes.res index e741f34c4..550845c5b 100644 --- a/src/entryPoints/AuthModule/Common/CommonAuthTypes.res +++ b/src/entryPoints/AuthModule/Common/CommonAuthTypes.res @@ -24,12 +24,14 @@ type authFlow = | ActivateFromEmail type data = {code: string, message: string, type_: string} type subCode = + | HE_02 | UR_00 | UR_01 | UR_03 | UR_05 | UR_16 | UR_29 + | UR_33 | UR_38 | UR_40 | UR_41 diff --git a/src/entryPoints/AuthModule/Common/CommonAuthUtils.res b/src/entryPoints/AuthModule/Common/CommonAuthUtils.res index 08017cdb4..92c6ec617 100644 --- a/src/entryPoints/AuthModule/Common/CommonAuthUtils.res +++ b/src/entryPoints/AuthModule/Common/CommonAuthUtils.res @@ -117,11 +117,13 @@ let parseErrorMessage = errorMessage => { let errorSubCodeMapper = (subCode: string) => { switch subCode { + | "HE_02" => HE_02 | "UR_01" => UR_01 | "UR_03" => UR_03 | "UR_05" => UR_05 | "UR_16" => UR_16 | "UR_29" => UR_29 + | "UR_33" => UR_33 | "UR_38" => UR_38 | "UR_40" => UR_40 | "UR_41" => UR_41 diff --git a/src/screens/APIUtils/APIUtils.res b/src/screens/APIUtils/APIUtils.res index 0950d896b..cd6fbfe26 100644 --- a/src/screens/APIUtils/APIUtils.res +++ b/src/screens/APIUtils/APIUtils.res @@ -56,7 +56,8 @@ let useGetURL = () => { switch (userEntity, userManagementRevamp) { | (#Organization, true) | (#Merchant, true) - | (#Profile, true) => + | (#Profile, true) + | (#Internal, true) => `account/${merchantId}/profile/connectors` | _ => connectorBaseURL } @@ -116,15 +117,12 @@ let useGetURL = () => { | Some(queryParams) => `payments/${key_id}?${queryParams}` | None => `payments/${key_id}` } + | None => - switch queryParamerters { - | Some(queryParams) => - switch (transactionEntity, userManagementRevamp) { - | (#Merchant, true) => `payments/list?${queryParams}` - | (#Profile, true) => `payments/profile/list?${queryParams}` - | _ => `payments/list?limit=100` - } - | None => `payments/list?limit=100` + switch (transactionEntity, userManagementRevamp) { + | (#Merchant, true) => `payments/list?limit=100` + | (#Profile, true) => `payments/profile/list?limit=100` + | _ => `payments/list?limit=100` } } | Post => @@ -226,7 +224,8 @@ let useGetURL = () => { switch (userEntity, userManagementRevamp) { | (#Organization, true) | (#Merchant, true) - | (#Profile, true) => `routing/list/profile` + | (#Profile, true) + | (#Internal, true) => `routing/list/profile` | _ => `routing` } } @@ -345,7 +344,8 @@ let useGetURL = () => { switch (userEntity, userManagementRevamp) { | (#Organization, true) | (#Merchant, true) - | (#Profile, true) => `routing/payouts/list/profile` + | (#Profile, true) + | (#Internal, true) => `routing/payouts/list/profile` | _ => `routing/payouts` } } @@ -465,7 +465,8 @@ let useGetURL = () => { switch (userEntity, userManagementRevamp) { | (#Organization, true) | (#Merchant, true) - | (#Profile, true) => + | (#Profile, true) + | (#Internal, true) => `account/${merchantId}/profile` | _ => `account/${merchantId}/business_profile` } @@ -761,14 +762,18 @@ let responseHandler = async ( let errorDict = json->getDictFromJsonObject->getObj("error", Dict.make()) let errorStringifiedJson = errorDict->JSON.Encode.object->JSON.stringify - //TODO:- - // errorCodes to be handled - // let errorCode = errorDict->getString("code", "") - if isPlayground && responseStatus === 403 { popUpCallBack() } else if showErrorToast { switch responseStatus { + | 400 => { + let errorCode = errorDict->getString("code", "") + switch errorCode->CommonAuthUtils.errorSubCodeMapper { + | HE_02 | UR_33 => + RescriptReactRouter.replace(GlobalVars.appendDashboardPath(~url="/home")) + | _ => () + } + } | 401 => if !sessionExpired.contents { showToast(~toastType=ToastWarning, ~message="Session Expired", ~autoClose=false) @@ -792,6 +797,13 @@ let responseHandler = async ( }, }) + | 404 => { + let errorCode = errorDict->getString("code", "") + switch errorCode->CommonAuthUtils.errorSubCodeMapper { + | HE_02 => RescriptReactRouter.replace(GlobalVars.appendDashboardPath(~url="/home")) + | _ => () + } + } | _ => showToast( ~toastType=ToastError, @@ -814,6 +826,7 @@ let catchHandler = ( ) => { switch Exn.message(err) { | Some(msg) => Exn.raiseError(msg) + | None => { if isPlayground { popUpCallBack()