Skip to content

Commit

Permalink
feat: Routing back to Integration Fields if Error already exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Dec 12, 2023
1 parent 706a414 commit ce27880
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/screens/HyperSwitch/Connectors/ConnectorPaymentMethod.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ let make = (
~isUpdateFlow,
~isPayoutFlow,
) => {
let hyperswitchMixPanel = HSMixPanel.useSendEvent()
open ConnectorUtils
open APIUtils
open PageLoaderWrapper
open LogicUtils
let hyperswitchMixPanel = HSMixPanel.useSendEvent()
let url = RescriptReactRouter.useUrl()
let _showAdvancedConfiguration = false
let (paymentMethodsEnabled, setPaymentMethods) = React.useState(_ =>
Expand All @@ -22,7 +22,7 @@ let make = (
let showToast = ToastState.useShowToast()
let connectorID = initialValues->getDictFromJsonObject->getOptionString("merchant_connector_id")
let (screenState, setScreenState) = React.useState(_ => Loading)
let updateAPIHook = useUpdateMethod()
let updateAPIHook = useUpdateMethod(~showErrorToast=false, ())

let updateDetails = value => {
setPaymentMethods(_ => value->Js.Array2.copy)
Expand Down Expand Up @@ -77,7 +77,16 @@ let make = (
} catch {
| Js.Exn.Error(e) => {
let err = Js.Exn.message(e)->Belt.Option.getWithDefault("Something went wrong")
setScreenState(_ => PageLoaderWrapper.Error(err))
let errorCode = err->safeParse->getDictFromJsonObject->getString("code", "")
let errorMessage = err->safeParse->getDictFromJsonObject->getString("message", "")

if errorCode === "HE_01" {
showToast(~message="Connector label already exist!", ~toastType=ToastError, ())
setCurrentStep(_ => ConnectorTypes.IntegFields)
} else {
showToast(~message=errorMessage, ~toastType=ToastError, ())
setScreenState(_ => PageLoaderWrapper.Error(err))
}
}
}
}
Expand Down

0 comments on commit ce27880

Please sign in to comment.