diff --git a/src/entryPoints/HyperSwitchEntry.res b/src/entryPoints/HyperSwitchEntry.res index d89e54d66..0fcfa8927 100644 --- a/src/entryPoints/HyperSwitchEntry.res +++ b/src/entryPoints/HyperSwitchEntry.res @@ -96,7 +96,7 @@ module HyperSwitchEntryComponent = { let fetchFeatureFlags = async () => { try { - let url = `${HSwitchGlobalVars.getHostURLFromVariant}/config/merchant-access` + let url = `${HSwitchGlobalVars.getHostUrlWithBasePath}/config/merchant-access` let typedResponse = ( await postDetails(url, Dict.make()->JSON.Encode.object, Post, ()) diff --git a/src/entryPoints/WooCommerce/WooCommerceUIUtils.res b/src/entryPoints/WooCommerce/WooCommerceUIUtils.res index ee2631214..d66d2103d 100644 --- a/src/entryPoints/WooCommerce/WooCommerceUIUtils.res +++ b/src/entryPoints/WooCommerce/WooCommerceUIUtils.res @@ -9,8 +9,7 @@ module SelectProcessor = { ) => { let url = RescriptReactRouter.useUrl() let connectorName = selectedConnector->ConnectorUtils.getConnectorNameString - let basePath = - url.path->List.toArray->QuickStartUtils.filterDashboardFromUrlPath->Array.joinWith("/") + let basePath = url.path->List.toArray->Array.joinWith("/") { setConnectorConfigureState(_ => Configure_keys) - RescriptReactRouter.replace( - HSwitchGlobalVars.appendDashboardPath(~url=`/${basePath}?name=${connectorName}`), - ) + RescriptReactRouter.replace(`/${basePath}?name=${connectorName}`) }} buttonSize=Small />}> diff --git a/src/screens/Connectors/ConnectPayPalFlow/ConnectPayPal.res b/src/screens/Connectors/ConnectPayPalFlow/ConnectPayPal.res index 87fc856af..d4c91319c 100644 --- a/src/screens/Connectors/ConnectPayPalFlow/ConnectPayPal.res +++ b/src/screens/Connectors/ConnectPayPalFlow/ConnectPayPal.res @@ -166,8 +166,7 @@ module RedirectionToPayPalFlow = { open LogicUtils try { setScreenState(_ => PageLoaderWrapper.Loading) - let fePrefix = getHostURLFromVariant->String.replace(appendDashboardPath(~url=""), "") - let returnURL = `${fePrefix}/${path}?name=paypal&is_back=true&is_simplified_paypal=true&profile_id=${profileId}` + let returnURL = `${getHostUrl}/${path}?name=paypal&is_back=true&is_simplified_paypal=true&profile_id=${profileId}` let body = PayPalFlowUtils.generatePayPalBody( ~connectorId={connectorId}, ~returnUrl=Some(returnURL), diff --git a/src/screens/Home/CommonConnectorFlow/ConfigureConnector.res b/src/screens/Home/CommonConnectorFlow/ConfigureConnector.res index 097bd2291..443fef132 100644 --- a/src/screens/Home/CommonConnectorFlow/ConfigureConnector.res +++ b/src/screens/Home/CommonConnectorFlow/ConfigureConnector.res @@ -307,7 +307,7 @@ let make = (~connectProcessorValue: connectProcessor) => { />}> SDKPaymentUtils.initialValueForForm} - returnUrl={`${HSwitchGlobalVars.getHostURLFromVariant}/quick-start`} + returnUrl={`${HSwitchGlobalVars.getHostUrlWithBasePath}/quick-start`} onProceed={updateTestPaymentEnum} keyValue=key sdkWidth="w-full" diff --git a/src/screens/Home/CommonConnectorFlow/SetupConnector.res b/src/screens/Home/CommonConnectorFlow/SetupConnector.res index 8447aa1c0..842e2300f 100644 --- a/src/screens/Home/CommonConnectorFlow/SetupConnector.res +++ b/src/screens/Home/CommonConnectorFlow/SetupConnector.res @@ -9,8 +9,7 @@ module SelectProcessor = { ) => { open ConnectorUtils let url = RescriptReactRouter.useUrl() - let basePath = - url.path->List.toArray->QuickStartUtils.filterDashboardFromUrlPath->Array.joinWith("/") + let basePath = url.path->List.toArray->Array.joinWith("/") let mixpanelEvent = MixpanelHook.useSendEvent() let connectorName = selectedConnector->getConnectorNameString let {setQuickStartPageState} = React.useContext(GlobalProvider.defaultContext) @@ -36,9 +35,7 @@ module SelectProcessor = { onClick={_ => { setConnectorConfigureState(_ => Select_configuration_type) mixpanelEvent(~eventName=`quickstart_select_processor`, ()) - RescriptReactRouter.replace( - HSwitchGlobalVars.appendDashboardPath(~url=`/${basePath}?name=${connectorName}`), - ) + RescriptReactRouter.replace(`/${basePath}?name=${connectorName}`) }} buttonSize=Small />} diff --git a/src/screens/Home/QuickStart/QuickStartUtils.res b/src/screens/Home/QuickStart/QuickStartUtils.res index 482d93171..3e6633a1f 100644 --- a/src/screens/Home/QuickStart/QuickStartUtils.res +++ b/src/screens/Home/QuickStart/QuickStartUtils.res @@ -706,11 +706,3 @@ let getCurrentStep = dict => { #GoLive } } - -let filterDashboardFromUrlPath = urlPathArray => { - open HSwitchGlobalVars - switch dashboardBasePath { - | Some(_) => urlPathArray->Array.filter(value => value !== "dashboard") - | _ => urlPathArray - } -} diff --git a/src/screens/MixpanelHook.res b/src/screens/MixpanelHook.res index bbcb1533e..ec6aab579 100644 --- a/src/screens/MixpanelHook.res +++ b/src/screens/MixpanelHook.res @@ -56,7 +56,7 @@ let useSendEvent = () => { try { let _ = await fetchApi( - `${getHostURLFromVariant}/mixpanel/track`, + `${getHostUrl}/mixpanel/track`, ~method_=Fetch.Post, ~bodyStr=`data=${body->JSON.stringifyAny->Option.getOr("")->encodeURI}`, (), diff --git a/src/screens/SDKPayment/SDKPage.res b/src/screens/SDKPayment/SDKPage.res index 0aff0a575..272f5ddf7 100644 --- a/src/screens/SDKPayment/SDKPage.res +++ b/src/screens/SDKPayment/SDKPage.res @@ -150,7 +150,7 @@ let make = () => {
{ open ProdOnboardingTypes + open HSwitchGlobalVars open ConnectorTypes + open LogicUtils open APIUtils + let fetchDetails = useGetMethod() let (pageView, setPageView) = React.useState(_ => SELECT_PROCESSOR) let (selectedConnector, setSelectedConnector) = React.useState(_ => Processors(STRIPE)) @@ -163,17 +166,14 @@ let make = () => { let getCssOnView = "xl:w-77-rem mx-7 xl:ml-[7rem]" let centerItems = pageView === SETUP_COMPLETED ? "justify-center" : "" - let urlPush = HSwitchGlobalVars.appendDashboardPath(~url=`/prod-onboarding?${routerUrl.search}`) + let urlPush = appendDashboardPath(~url=`/prod-onboarding?${routerUrl.search}`) let userRole = HSLocalStorage.getFromUserDetails("user_role") let getSetupCompleteEnum = (prodEnums: ProdOnboardingTypes.prodOnboading) => { - open LogicUtils if prodEnums.setupComplete { setDashboardPageState(_ => #HOME) - let baseUrlPath = `${HSwitchGlobalVars.getHostURLFromVariant}/${routerUrl.path - ->List.toArray - ->Array.joinWith("/")}` + let baseUrlPath = `${getHostUrl}/${routerUrl.path->List.toArray->Array.joinWith("/")}` routerUrl.search->isNonEmptyString ? RescriptReactRouter.push(`${baseUrlPath}?${routerUrl.search}`) : RescriptReactRouter.push(`${baseUrlPath}`) @@ -195,7 +195,6 @@ let make = () => { } let getSetupProcessorEnum = (prodEnums: ProdOnboardingTypes.prodOnboading) => { - open LogicUtils let connectorId = prodEnums.setupProcessor.connector_id if connectorId->isNonEmptyString { setConnectorID(_ => connectorId) @@ -208,7 +207,6 @@ let make = () => { } let getConnectorDetails = async headerVariant => { - open LogicUtils try { let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Get, ~id=Some(connectorID), ()) let json = await fetchDetails(connectorUrl) @@ -216,7 +214,7 @@ let make = () => { setInitialValues(_ => json) setPreviewState(_ => Some(headerVariant->ProdOnboardingUtils.getPreviewState)) RescriptReactRouter.replace( - HSwitchGlobalVars.appendDashboardPath(~url=`/prod-onboarding?name=${connectorName}`), + appendDashboardPath(~url=`/prod-onboarding?name=${connectorName}`), ) } catch { | _ => setScreenState(_ => PageLoaderWrapper.Error("")) diff --git a/src/screens/StripePlusPaypal/StripePlusPaypalUIUtils.res b/src/screens/StripePlusPaypal/StripePlusPaypalUIUtils.res index b609a4806..a94f26039 100644 --- a/src/screens/StripePlusPaypal/StripePlusPaypalUIUtils.res +++ b/src/screens/StripePlusPaypal/StripePlusPaypalUIUtils.res @@ -192,7 +192,7 @@ module TestPayment = { />}> SDKPaymentUtils.initialValueForForm} - returnUrl={`${HSwitchGlobalVars.getHostURLFromVariant}/stripe-plus-paypal`} + returnUrl={`${HSwitchGlobalVars.getHostUrlWithBasePath}/stripe-plus-paypal`} onProceed={sptestPaymentProceed} keyValue={key} sdkWidth="w-full" diff --git a/src/screens/login/HSwitchLoginFlow/HyperSwitchAuthUtils.res b/src/screens/login/HSwitchLoginFlow/HyperSwitchAuthUtils.res index 8cb8609cc..232f27dfe 100644 --- a/src/screens/login/HSwitchLoginFlow/HyperSwitchAuthUtils.res +++ b/src/screens/login/HSwitchLoginFlow/HyperSwitchAuthUtils.res @@ -276,8 +276,8 @@ module ToggleLiveTestMode = { open HSwitchGlobalVars @react.component let make = (~authType, ~mode, ~setMode, ~setAuthType, ~customClass="") => { - let liveButtonRedirectUrl = getHostURLFromVariant - let testButtonRedirectUrl = getHostURLFromVariant + let liveButtonRedirectUrl = getHostUrlWithBasePath + let testButtonRedirectUrl = getHostUrlWithBasePath <> {switch authType { | LoginWithPassword diff --git a/src/utils/HSwitchGlobalVars.res b/src/utils/HSwitchGlobalVars.res index 65eff3aa7..18f98dab3 100644 --- a/src/utils/HSwitchGlobalVars.res +++ b/src/utils/HSwitchGlobalVars.res @@ -21,7 +21,9 @@ let hostType = switch hostName { | _ => hostName->String.includes("netlify") ? Netlify : Local } -let getHostURLFromVariant = `${Window.Location.origin}${appendDashboardPath(~url="")}` +let getHostUrlWithBasePath = `${Window.Location.origin}${appendDashboardPath(~url="")}` + +let getHostUrl = Window.Location.origin let isHyperSwitchDashboard = GlobalVars.dashboardAppName === #hyperswitch