Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ let make = () => {
{IntelligentRoutingUtils.features
->Array.map(feature => {
<div key=feature.title className="flex flex-row gap-3 items-start">
<div className={`${feature.bgColor} rounded-xl w-12 h-12 flex-shrink-0 flex items-center justify-center`}>
<div
className={`${feature.bgColor} rounded-xl w-12 h-12 flex-shrink-0 flex items-center justify-center`}>
<Icon name=feature.icon size=28 className=feature.iconColor />
</div>
<div className="flex flex-col gap-0.5">
<p className={`${body.md.semibold} text-nd_gray-700`}>{feature.title->React.string}</p>
<p className={`${body.md.semibold} text-nd_gray-700`}>
{feature.title->React.string}
</p>
<p className={`${body.sm.regular} text-nd_gray-500`}>
{feature.description->React.string}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ module SwitchMerchantBody = {
open Typography
let internalSwitch = OMPSwitchHooks.useInternalSwitch(~setActiveProductValue)
let showToast = ToastState.useShowToast()
let isLiveMode = (HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom).isLiveMode

let switchMerch = async () => {
try {
let version = UserUtils.getVersion(selectedProduct)
let _ = await internalSwitch(~expectedMerchantId=Some(merchantDetails.id), ~version)
setActiveProductValue(selectedProduct)
let productUrl = ProductUtils.getProductUrl(~productType=selectedProduct, ~isLiveMode)
RescriptReactRouter.replace(productUrl)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Navigation executes even if internalSwitch fails. Move setActiveProductValue and RescriptReactRouter.replace inside the try block after internalSwitch succeeds, or add early return in catch.

} catch {
| _ => showToast(~message="Failed to switch merchant", ~toastType=ToastError)
}
Expand Down Expand Up @@ -45,6 +49,7 @@ module SelectMerchantBody = {
let showToast = ToastState.useShowToast()
let merchantDetailsTypedValue =
HyperswitchAtom.merchantDetailsValueAtom->Recoil.useRecoilValueFromAtom
let isLiveMode = (HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom).isLiveMode

let dropDownOptions =
merchantList
Expand Down Expand Up @@ -96,6 +101,9 @@ module SelectMerchantBody = {
let version = UserUtils.getVersion(selectedProduct)

let _ = await internalSwitch(~expectedMerchantId=Some(merchantid), ~version)
setActiveProductValue(selectedProduct)
let productUrl = ProductUtils.getProductUrl(~productType=selectedProduct, ~isLiveMode)
RescriptReactRouter.replace(productUrl)
} catch {
| _ => showToast(~message="Failed to switch merchant", ~toastType=ToastError)
}
Expand Down Expand Up @@ -174,6 +182,7 @@ module CreateNewMerchantBody = {
let merchantDetailsTypedValue =
HyperswitchAtom.merchantDetailsValueAtom->Recoil.useRecoilValueFromAtom
let merchantList = Recoil.useRecoilValueFromAtom(HyperswitchAtom.merchantListAtom)
let isLiveMode = (HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom).isLiveMode

let initialValues = React.useMemo(() => {
let dict = Dict.make()
Expand All @@ -189,6 +198,9 @@ module CreateNewMerchantBody = {
try {
let version = UserUtils.getVersion(selectedProduct)
let _ = await internalSwitch(~expectedMerchantId=Some(merchantid), ~version)
setActiveProductValue(selectedProduct)
let productUrl = ProductUtils.getProductUrl(~productType=selectedProduct, ~isLiveMode)
RescriptReactRouter.replace(productUrl)
} catch {
| _ => showToast(~message="Failed to switch merchant", ~toastType=ToastError)
}
Expand Down
10 changes: 1 addition & 9 deletions src/screens/DefaultHome/DefaultHome.res
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ let make = () => {
| Recovery =>
<RenderIf condition=devRecoveryV2Product>
<DefaultHomeCard
product=item.product
heading=item.heading
description=item.description
img=item.imgSrc
Expand All @@ -57,7 +56,6 @@ let make = () => {
| Vault =>
<RenderIf condition=devVaultV2Product>
<DefaultHomeCard
product=item.product
heading=item.heading
description=item.description
img=item.imgSrc
Expand All @@ -67,7 +65,6 @@ let make = () => {
| Recon(_) =>
<RenderIf condition=devReconv2Product>
<DefaultHomeCard
product=item.product
heading=item.heading
description=item.description
img=item.imgSrc
Expand All @@ -77,7 +74,6 @@ let make = () => {
| CostObservability =>
<RenderIf condition=devHypersenseV2Product>
<DefaultHomeCard
product=item.product
heading=item.heading
description=item.description
img=item.imgSrc
Expand All @@ -86,11 +82,7 @@ let make = () => {
</RenderIf>
| _ =>
<DefaultHomeCard
product=item.product
heading=item.heading
description=item.description
img=item.imgSrc
action=item.action
heading=item.heading description=item.description img=item.imgSrc action=item.action
/>
}}
</React.Fragment>
Expand Down
15 changes: 3 additions & 12 deletions src/screens/DefaultHome/DefaultHomeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ module DefaultActionItem = {
}
module DefaultHomeCard = {
@react.component
let make = (~product, ~heading, ~description, ~img, ~action) => {
let make = (~heading, ~description, ~img, ~action) => {
let mixpanelEvent = MixpanelHook.useSendEvent()
let {activeProduct, onProductSelectClick} = React.useContext(
ProductSelectionProvider.defaultContext,
)
let isLiveMode = (HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom).isLiveMode
let {onProductSelectClick} = React.useContext(ProductSelectionProvider.defaultContext)

<div
className="w-full p-3 gap-4 rounded-xl flex flex-col shadow-cardShadow border border-nd_br_gray-500">
Expand All @@ -52,13 +49,7 @@ module DefaultHomeCard = {
customButtonStyle="w-full"
onClick={_ => {
switch action {
| InternalRoute =>
if product === activeProduct {
let productUrl = ProductUtils.getProductUrl(~productType=product, ~isLiveMode)
RescriptReactRouter.replace(productUrl)
} else {
onProductSelectClick(heading)
}
| InternalRoute => onProductSelectClick(heading)
| ExternalLink({url, trackingEvent}) => {
mixpanelEvent(~eventName=trackingEvent)
url->Window._open
Expand Down
Loading