Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: url path after OMP switch #1770

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions src/screens/OMPSwitch/MerchantSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ let make = () => {
let fetchDetails = useGetMethod()
let showToast = ToastState.useShowToast()
let merchSwitch = OMPSwitchHooks.useMerchantSwitch()
let url = RescriptReactRouter.useUrl()
let {userInfo: {merchantId}} = React.useContext(UserInfoProvider.defaultContext)
let (showModal, setShowModal) = React.useState(_ => false)
let (merchantList, setMerchantList) = Recoil.useRecoilState(HyperswitchAtom.merchantListAtom)
Expand All @@ -152,6 +153,7 @@ let make = () => {
try {
setShowSwitchingMerch(_ => true)
let _ = await merchSwitch(~expectedMerchantId=value, ~currentMerchantId=merchantId)
RescriptReactRouter.replace(GlobalVars.extractModulePath(url))
setShowSwitchingMerch(_ => false)
} catch {
| _ => {
Expand Down
2 changes: 2 additions & 0 deletions src/screens/OMPSwitch/OrgSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let make = () => {
let fetchDetails = useGetMethod()
let showToast = ToastState.useShowToast()
let orgSwitch = OMPSwitchHooks.useOrgSwitch()
let url = RescriptReactRouter.useUrl()
let {userHasAccess} = GroupACLHooks.useUserGroupACLHook()
let {userInfo: {orgId}} = React.useContext(UserInfoProvider.defaultContext)
let (orgList, setOrgList) = Recoil.useRecoilState(HyperswitchAtom.orgListAtom)
Expand Down Expand Up @@ -37,6 +38,7 @@ let make = () => {
try {
setShowSwitchingOrg(_ => true)
let _ = await orgSwitch(~expectedOrgId=value, ~currentOrgId=orgId)
RescriptReactRouter.replace(GlobalVars.extractModulePath(url))
setShowSwitchingOrg(_ => false)
} catch {
| _ => {
Expand Down
4 changes: 3 additions & 1 deletion src/screens/OMPSwitch/ProfileSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ let make = () => {
let fetchDetails = useGetMethod()
let showToast = ToastState.useShowToast()
let profileSwitch = OMPSwitchHooks.useProfileSwitch()
let url = RescriptReactRouter.useUrl()
let (showModal, setShowModal) = React.useState(_ => false)
let {userInfo: {profileId}} = React.useContext(UserInfoProvider.defaultContext)
let (profileList, setProfileList) = Recoil.useRecoilState(HyperswitchAtom.profileListAtom)
Expand All @@ -175,11 +176,12 @@ let make = () => {
let addItemBtnStyle = "border border-t-0 w-full"
let customScrollStyle = "max-h-72 overflow-scroll px-1 pt-1 border border-b-0"
let dropdownContainerStyle = "min-w-[15rem] rounded-md border border-1"

let profileSwitch = async value => {
try {
setShowSwitchingProfile(_ => true)
let _ = await profileSwitch(~expectedProfileId=value, ~currentProfileId=profileId)
RescriptReactRouter.replace(GlobalVars.appendDashboardPath(~url="/home"))
RescriptReactRouter.replace(GlobalVars.extractModulePath(url))
setShowSwitchingProfile(_ => false)
} catch {
| _ => {
Expand Down
9 changes: 9 additions & 0 deletions src/utils/GlobalVars.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ let appendDashboardPath = (~url) => {
}
}

let extractModulePath = (url: RescriptReactRouter.url) => {
let currentPathList = url.path->List.toArray
let path = switch currentPathList->Array.get(0) {
| Some("dashboard") => currentPathList->Array.slice(~start=0, ~end=2)->Array.joinWith("/")
| _ => currentPathList->LogicUtils.getValueFromArray(0, "home")
}
appendTrailingSlash(path)
}

type hostType = Live | Sandbox | Local | Integ

let hostName = Window.Location.hostname
Expand Down
Loading