From ce278804972ecc3d377b8db747fd7e02bf956d0b Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Tue, 12 Dec 2023 12:22:24 +0530 Subject: [PATCH] feat: Routing back to Integration Fields if Error already exist. --- .../Connectors/ConnectorPaymentMethod.res | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/screens/HyperSwitch/Connectors/ConnectorPaymentMethod.res b/src/screens/HyperSwitch/Connectors/ConnectorPaymentMethod.res index be2e23d32..768f8ca69 100644 --- a/src/screens/HyperSwitch/Connectors/ConnectorPaymentMethod.res +++ b/src/screens/HyperSwitch/Connectors/ConnectorPaymentMethod.res @@ -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(_ => @@ -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) @@ -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)) + } } } }