Skip to content

Commit

Permalink
Merge branch 'main' into refactor/tableActionsUI
Browse files Browse the repository at this point in the history
  • Loading branch information
jainlokesh318 authored Jan 23, 2024
2 parents 003e483 + f35bcc5 commit eb5ea3b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 46 deletions.
7 changes: 4 additions & 3 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ let make = () => {
/>
</AccessControl>
| list{"recon"} =>
<AccessControl isEnabled=featureFlagDetails.recon>
<AccessControl isEnabled=featureFlagDetails.recon permission=Access>
<Recon />
</AccessControl>
| list{"sdk"} =>
<AccessControl isEnabled={!featureFlagDetails.isLiveMode}>
<AccessControl isEnabled={!featureFlagDetails.isLiveMode} permission=Access>
<SDKPage />
</AccessControl>
| list{"3ds"} =>
Expand Down Expand Up @@ -397,7 +397,8 @@ let make = () => {
<BusinessDetails />
</AccessControl>
| list{"business-profiles"} =>
<AccessControl isEnabled=featureFlagDetails.businessProfile>
<AccessControl
isEnabled=featureFlagDetails.businessProfile permission=Access>
<BusinessProfile />
</AccessControl>
| list{"quick-start"} => determineQuickStartPageState()
Expand Down
57 changes: 19 additions & 38 deletions src/hooks/AuthHooks.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,23 @@ let getHeaders = (~uri, ~headers, ()) => {
let hyperSwitchToken = LocalStorage.getItem("login")->Js.Nullable.toOption
let isMixpanel = uri->String.includes("mixpanel")

if isMixpanel {
let headerObj = {
"Content-Type": "application/x-www-form-urlencoded",
"accept": "application/json",
}
Fetch.HeadersInit.make(headerObj)
let headerObj = if isMixpanel {
[
("Content-Type", "application/x-www-form-urlencoded"),
("accept", "application/json"),
]->Dict.fromArray
} else {
let headerObj = headers->Dict.get("api-key")->Option.getWithDefault("")->String.length > 0

if headerObj {
let headerObj = {
"Content-Type": "application/json",
"api-key": headers->Dict.get("api-key")->Option.getWithDefault(""),
let res = switch hyperSwitchToken {
| Some(token) => {
headers->Dict.set("authorization", `Bearer ${token}`)
headers
}
Fetch.HeadersInit.make(headerObj)
} else {
switch hyperSwitchToken {
| Some(token) =>
if token !== "" {
let headerObj = {
"Content-Type": "application/json",
"Authorization": `Bearer ${hyperSwitchToken->Option.getWithDefault("")}`,
"api-key": "hyperswitch",
}

Fetch.HeadersInit.make(headerObj)
} else {
let headerObj = {
"Content-Type": "application/json",
}
Fetch.HeadersInit.make(headerObj)
}

| None =>
let headerObj = {
"Content-Type": "application/json",
}
Fetch.HeadersInit.make(headerObj)
}
| None => headers
}
res
}
Fetch.HeadersInit.make(headerObj->dictToObj)
}

@val @scope(("window", "location"))
Expand All @@ -81,7 +57,8 @@ let useApiFetcher = () => {
(
uri,
~bodyStr: string="",
~headers=Dict.make(),
~bodyFormData=None,
~headers=[("Content-Type", "application/json")]->Dict.fromArray,
~bodyHeader as _=?,
~method_: Fetch.requestMethod,
~authToken as _=?,
Expand All @@ -98,7 +75,11 @@ let useApiFetcher = () => {

let body = switch method_ {
| Get => resolve(None)
| _ => resolve(Some(Fetch.BodyInit.make(bodyStr)))
| _ =>
switch bodyFormData {
| Some(formDataVal) => resolve(Some(Fetch.BodyInit.makeWithFormData(formDataVal)))
| None => resolve(Some(Fetch.BodyInit.make(bodyStr)))
}
}

body->then(body => {
Expand Down
19 changes: 17 additions & 2 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ let handleLogout = async (
~fetchApi as _: (
Js.String2.t,
~bodyStr: string=?,
~bodyFormData: option<Fetch.formData>=?,
~headers: Js.Dict.t<Js.String2.t>=?,
~bodyHeader: Js.Dict.t<Js.Json.t>=?,
~method_: Fetch.requestMethod,
Expand Down Expand Up @@ -387,9 +388,23 @@ let useUpdateMethod = (~showErrorToast=true, ()) => {
},
})

async (url, body, method, ()) => {
async (
url,
body,
method,
~bodyFormData=?,
~headers=[("Content-Type", "application/json")]->Dict.fromArray,
(),
) => {
try {
let res = await fetchApi(url, ~method_=method, ~bodyStr=body->Js.Json.stringify, ())
let res = await fetchApi(
url,
~method_=method,
~bodyStr=body->Js.Json.stringify,
~bodyFormData,
~headers,
(),
)
await responseHandler(
~res,
~showErrorToast,
Expand Down
9 changes: 8 additions & 1 deletion src/screens/HyperSwitch/Order/OrderUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,14 @@ let setData = (

let getOrdersList = async (
filterValueJson,
~updateDetails: (string, Js.Json.t, Fetch.requestMethod, unit) => promise<Js.Json.t>,
~updateDetails: (
string,
Js.Json.t,
Fetch.requestMethod,
~bodyFormData: Fetch.formData=?,
~headers: Js.Dict.t<'a>=?,
unit,
) => promise<Js.Json.t>,
~setOrdersData,
~previewOnly,
~setScreenState,
Expand Down
9 changes: 8 additions & 1 deletion src/screens/HyperSwitch/Refunds/RefundUtils.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
let getRefundsList = async (
filterValueJson,
~updateDetails: (string, Js.Json.t, Fetch.requestMethod, unit) => promise<Js.Json.t>,
~updateDetails: (
string,
Js.Json.t,
Fetch.requestMethod,
~bodyFormData: Fetch.formData=?,
~headers: Js.Dict.t<'a>=?,
unit,
) => promise<Js.Json.t>,
~setRefundsData,
~setScreenState,
~offset,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/AccessControl.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open AuthTypes
@react.component
let make = (~isEnabled=true, ~permission=NoAccess, ~children) => {
let make = (~isEnabled=true, ~permission, ~children) => {
let isAccessAllowed = permission === Access
isEnabled && isAccessAllowed ? children : <UnauthorizedPage />
}

0 comments on commit eb5ea3b

Please sign in to comment.