Skip to content

Commit

Permalink
fix: handle recon-iframe logout in dashboard (#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 authored Dec 16, 2024
1 parent 4693520 commit dc07d46
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 25 deletions.
14 changes: 8 additions & 6 deletions src/container/MerchantAccountContainer.res
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ let make = (~setAppScreenState) => {
authorization={userHasResourceAccess(~resourceAccess=ReconConfig)}>
<ReconModule urlList={url.path->urlPath} />
</AccessControl>
| list{"file-processor"} =>
<AccessControl
isEnabled={featureFlagDetails.recon && !checkUserEntity([#Profile])}
authorization={userHasResourceAccess(~resourceAccess=ReconFiles)}>
<ReconModule urlList={url.path->urlPath} />
</AccessControl>

// Commented as not needed now
// | list{"file-processor"} =>
// <AccessControl
// isEnabled={featureFlagDetails.recon && !checkUserEntity([#Profile])}
// authorization={userHasResourceAccess(~resourceAccess=ReconFiles)}>
// <ReconModule urlList={url.path->urlPath} />
// </AccessControl>
| list{"sdk"} =>
<AccessControl
isEnabled={!featureFlagDetails.isLiveMode}
Expand Down
4 changes: 3 additions & 1 deletion src/entryPoints/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ let make = () => {
| list{"recon-analytics"}
| list{"reports"}
| list{"config-settings"}
| list{"file-processor"}
| list{"sdk"} =>
<MerchantAccountContainer setAppScreenState=setScreenState />
// Commented as not needed now
// list{"file-processor"}

| list{"connectors", ..._}
| list{"payoutconnectors", ..._}
| list{"3ds-authenticators", ..._}
Expand Down
24 changes: 13 additions & 11 deletions src/entryPoints/SidebarValues.res
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,15 @@ let reconConfigurator = {
searchOptions: [("Recon configurator", "")],
})
}
let reconFileProcessor = {
SubLevelLink({
name: "File Processor",
link: `/file-processor`,
access: Access,
searchOptions: [("Recon file processor", "")],
})
}
// Commented as not needed now
// let reconFileProcessor = {
// SubLevelLink({
// name: "File Processor",
// link: `/file-processor`,
// access: Access,
// searchOptions: [("Recon file processor", "")],
// })
// }

let reconAndSettlement = (recon, isReconEnabled, checkUserEntity, userHasResourceAccess) => {
switch (recon, isReconEnabled, checkUserEntity([#Merchant, #Organization])) {
Expand All @@ -630,9 +631,10 @@ let reconAndSettlement = (recon, isReconEnabled, checkUserEntity, userHasResourc
if userHasResourceAccess(~resourceAccess=ReconConfig) == CommonAuthTypes.Access {
links->Array.push(reconConfigurator)
}
if userHasResourceAccess(~resourceAccess=ReconFiles) == CommonAuthTypes.Access {
links->Array.push(reconFileProcessor)
}
// Commented as not needed now
// if userHasResourceAccess(~resourceAccess=ReconFiles) == CommonAuthTypes.Access {
// links->Array.push(reconFileProcessor)
// }
Section({
name: "Recon And Settlement",
icon: "recon",
Expand Down
47 changes: 40 additions & 7 deletions src/screens/Recon/ReconModule.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let make = (~urlList) => {
open LogicUtils

let getURL = useGetURL()
let handleLogout = useHandleLogout()
let fetchDetails = useGetMethod()
let (redirectToken, setRedirectToken) = React.useState(_ => "")
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading)
Expand All @@ -23,21 +24,53 @@ let make = (~urlList) => {
}

let redirectUrl = switch urlList {
| list{"upload-files"}
| list{"run-recon"}
| list{"reports"}
| list{"config-settings"}
| list{"file-processor"} =>
urlList->List.toArray->Array.joinWith("/")
| list{"recon-analytics"} => "analytics"
| list{"upload-files"} => "upload-recon-files"
| list{"run-recon"} => "run-recon/home"
| list{"reports"} => "report/reconciliation"
| list{"config-settings"} => "reconcilation-config"

| list{"recon-analytics"} => "analytics-recon-and-settlement"
| _ => ""
// commented as not needed as of now
// | list{"file-processor"} => "file-processor"
}

React.useEffect(() => {
getReconToken()->ignore
None
}, (iframeLoaded, redirectUrl))

React.useEffect(() => {
// Event listner to check if the session is expired in iframe
let handleIframeMessage = event => {
let dictFromEvent = event->Identity.genericTypeToJson->getDictFromJsonObject

let eventType =
dictFromEvent
->getString("data", "")
->safeParse
->getDictFromJsonObject
->getString("event", "")
->ReconUtils.getEventTypeFromString

let status =
dictFromEvent
->getString("data", "")
->safeParse
->getDictFromJsonObject
->getString("AuthenticationStatus", "")
->ReconUtils.getAuthStatusFromMessage

if eventType == AuthenticationStatus && status == IframeLoggedOut {
handleLogout()->ignore
}
}

Window.addEventListener("message", handleIframeMessage)

Some(() => Window.removeEventListener("message", handleIframeMessage))
}, [])

<>
{
switch iframeRef.current->Js.Nullable.toOption {
Expand Down
3 changes: 3 additions & 0 deletions src/screens/Recon/ReconTypes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type authStatus = IframeLoggedIn | IframeLoggedOut

type eventType = AuthenticationStatus
13 changes: 13 additions & 0 deletions src/screens/Recon/ReconUtils.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open ReconTypes
let getAuthStatusFromMessage = authStatus =>
switch authStatus {
| "LoggedOut" => IframeLoggedOut
| _ => IframeLoggedIn
}

let getEventTypeFromString = eventTypeString =>
switch eventTypeString {
| "AuthenticationStatus"
| _ =>
AuthenticationStatus
}

0 comments on commit dc07d46

Please sign in to comment.