Skip to content

Commit

Permalink
fix: prod onboarding url issue (#614)
Browse files Browse the repository at this point in the history
Co-authored-by: Riddhiagrawal001 <[email protected]>
  • Loading branch information
JeevaRamu0104 and Riddhiagrawal001 authored Apr 29, 2024
1 parent 930a48c commit c915e58
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/entryPoints/HyperSwitchEntry.res
Original file line number Diff line number Diff line change
Expand Up @@ -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, ())
Expand Down
7 changes: 2 additions & 5 deletions src/entryPoints/WooCommerce/WooCommerceUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")

<QuickStartUIUtils.BaseComponent
headerText="Select Processor"
Expand All @@ -24,9 +23,7 @@ module SelectProcessor = {
}}
onClick={_ => {
setConnectorConfigureState(_ => Configure_keys)
RescriptReactRouter.replace(
HSwitchGlobalVars.appendDashboardPath(~url=`/${basePath}?name=${connectorName}`),
)
RescriptReactRouter.replace(`/${basePath}?name=${connectorName}`)
}}
buttonSize=Small
/>}>
Expand Down
3 changes: 1 addition & 2 deletions src/screens/Connectors/ConnectPayPalFlow/ConnectPayPal.res
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ let make = (~connectProcessorValue: connectProcessor) => {
/>}>
<TestPayment
initialValues={activeBusinessProfile->SDKPaymentUtils.initialValueForForm}
returnUrl={`${HSwitchGlobalVars.getHostURLFromVariant}/quick-start`}
returnUrl={`${HSwitchGlobalVars.getHostUrlWithBasePath}/quick-start`}
onProceed={updateTestPaymentEnum}
keyValue=key
sdkWidth="w-full"
Expand Down
7 changes: 2 additions & 5 deletions src/screens/Home/CommonConnectorFlow/SetupConnector.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
/>}
Expand Down
8 changes: 0 additions & 8 deletions src/screens/Home/QuickStart/QuickStartUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,3 @@ let getCurrentStep = dict => {
#GoLive
}
}

let filterDashboardFromUrlPath = urlPathArray => {
open HSwitchGlobalVars
switch dashboardBasePath {
| Some(_) => urlPathArray->Array.filter(value => value !== "dashboard")
| _ => urlPathArray
}
}
2 changes: 1 addition & 1 deletion src/screens/MixpanelHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
(),
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SDKPayment/SDKPage.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ let make = () => {
<div className="p-7 h-full bg-sidebar-blue">
<TestPayment
key
returnUrl={`${HSwitchGlobalVars.getHostURLFromVariant}/sdk`}
returnUrl={`${HSwitchGlobalVars.getHostUrlWithBasePath}/sdk`}
onProceed
sdkWidth="!w-[100%]"
isTestCredsNeeded=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ module SidebarChecklist = {
@react.component
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))
Expand All @@ -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}`)
Expand All @@ -195,7 +195,6 @@ let make = () => {
}

let getSetupProcessorEnum = (prodEnums: ProdOnboardingTypes.prodOnboading) => {
open LogicUtils
let connectorId = prodEnums.setupProcessor.connector_id
if connectorId->isNonEmptyString {
setConnectorID(_ => connectorId)
Expand All @@ -208,15 +207,14 @@ let make = () => {
}

let getConnectorDetails = async headerVariant => {
open LogicUtils
try {
let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Get, ~id=Some(connectorID), ())
let json = await fetchDetails(connectorUrl)
let connectorName = json->getDictFromJsonObject->getString("connector_name", "")
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(""))
Expand Down
2 changes: 1 addition & 1 deletion src/screens/StripePlusPaypal/StripePlusPaypalUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ module TestPayment = {
/>}>
<TestPayment
initialValues={defaultBusinessProfile->SDKPaymentUtils.initialValueForForm}
returnUrl={`${HSwitchGlobalVars.getHostURLFromVariant}/stripe-plus-paypal`}
returnUrl={`${HSwitchGlobalVars.getHostUrlWithBasePath}/stripe-plus-paypal`}
onProceed={sptestPaymentProceed}
keyValue={key}
sdkWidth="w-full"
Expand Down
4 changes: 2 additions & 2 deletions src/screens/login/HSwitchLoginFlow/HyperSwitchAuthUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/utils/HSwitchGlobalVars.res
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c915e58

Please sign in to comment.