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

fix: Signout API removed. #116

Merged
merged 2 commits into from
Dec 20, 2023
Merged
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
14 changes: 9 additions & 5 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ let getURL = (
let sessionExpired = ref(false)

let handleLogout = async (
~fetchApi: (
~fetchApi as _: (
Js.String2.t,
~bodyStr: string=?,
~headers: Js.Dict.t<Js.String2.t>=?,
Expand All @@ -248,10 +248,12 @@ let handleLogout = async (
unit,
) => Promise.t<Fetch.Response.t>,
~setAuthStatus,
~setIsSidebarExpanded,
) => {
let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ())
let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ())
// let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ())
// let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ())
setAuthStatus(HyperSwitchAuthTypes.LoggedOut)
setIsSidebarExpanded(_ => false)
LocalStorage.clear()
RescriptReactRouter.push("/register")
}
Expand Down Expand Up @@ -376,6 +378,7 @@ let useGetMethod = (~showErrorToast=true, ()) => {
let showToast = ToastState.useShowToast()
let showPopUp = PopUpState.useShowPopUp()
let (_authStatus, setAuthStatus) = React.useContext(AuthInfoProvider.authStatusContext)
let {setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext)
let isPlayground = HSLocalStorage.getIsPlaygroundFromLocalStorage()
let url = RescriptReactRouter.useUrl()
let urlPath = url.path->Belt.List.toArray->Js.Array2.joinWith("_")
Expand All @@ -393,7 +396,7 @@ let useGetMethod = (~showErrorToast=true, ()) => {
_ => {
hyperswitchMixPanel(~eventName=Some(`${urlPath}_tryplayground_register`), ())
hyperswitchMixPanel(~eventName=Some(`global_tryplayground_register`), ())
let _ = handleLogout(~fetchApi, ~setAuthStatus)
let _ = handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded)
}
},
},
Expand Down Expand Up @@ -440,6 +443,7 @@ let useUpdateMethod = (~showErrorToast=true, ()) => {
let isPlayground = HSLocalStorage.getIsPlaygroundFromLocalStorage()
let url = RescriptReactRouter.useUrl()
let urlPath = url.path->Belt.List.toArray->Js.Array2.joinWith("_")
let {setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext)

let popUpCallBack = () =>
showPopUp({
Expand All @@ -454,7 +458,7 @@ let useUpdateMethod = (~showErrorToast=true, ()) => {
_ => {
hyperswitchMixPanel(~eventName=Some(`${urlPath}_tryplayground_register`), ())
hyperswitchMixPanel(~eventName=Some(`global_tryplayground_register`), ())
let _ = handleLogout(~fetchApi, ~setAuthStatus)
let _ = handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded)
}
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/screens/HyperSwitch/Home/HomeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ module CheckoutCard = {
let showPopUp = PopUpState.useShowPopUp()
let hyperswitchMixPanel = HSMixPanel.useSendEvent()
let (_authStatus, setAuthStatus) = React.useContext(AuthInfoProvider.authStatusContext)
let {setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext)
let isPlayground = HSLocalStorage.getIsPlaygroundFromLocalStorage()
let isConfigureConnector = ListHooks.useListCount(~entityName=CONNECTOR) > 0
let urlPath = url.path->Belt.List.toArray->Js.Array2.joinWith("_")
Expand All @@ -187,7 +188,7 @@ module CheckoutCard = {
_ => {
hyperswitchMixPanel(~eventName=Some(`${urlPath}_tryplayground_register`), ())
hyperswitchMixPanel(~eventName=Some(`global_tryplayground_register`), ())
let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus)
let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded)
}
},
},
Expand Down
21 changes: 2 additions & 19 deletions src/screens/HyperSwitch/Sidebar/Sidebar.res
Original file line number Diff line number Diff line change
Expand Up @@ -524,25 +524,8 @@ let make = (

let transformClass = "transform md:translate-x-0 transition"

let handleLogout = _ev => {
open Promise
fetchApi(
APIUtils.getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ()),
~bodyStr=Js.Json.stringify(Js.Json.object_(Js.Dict.empty())),
~method_=Fetch.Post,
(),
)
->then(Fetch.Response.text)
->then(_ => {
setIsSidebarExpanded(_ => false)
LocalStorage.clear()
setAuthStatus(LoggedOut)
resolve()
})
->catch(_err => {
resolve()
})
->ignore
let handleLogout = _ => {
let _ = APIUtils.handleLogout(~fetchApi, ~setAuthStatus, ~setIsSidebarExpanded)
}

<div className={`bg-sidebar-blue flex group border-r border-jp-gray-500 relative`}>
Expand Down
Loading