Skip to content

Commit

Permalink
chore: sidebar refactoring & permissions added (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja authored Jan 17, 2024
1 parent 1fc2789 commit f428679
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/components/EntityScaffold.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ let make = (
| list{"new"} =>
switch access {
| ReadWrite => renderNewForm()
| Checker => isAdminAccount ? renderNewForm() : <UnauthorizedPage entityName />
| _ => <UnauthorizedPage entityName />
}
| list{id, "clone"} =>
Expand All @@ -69,14 +68,11 @@ let make = (
| list{id, "edit"} =>
switch access {
| ReadWrite => renderEdit(id)
| Checker => isAdminAccount ? renderEdit(id) : <UnauthorizedPage entityName />
| _ => <UnauthorizedPage entityName />
}
| list{id1, id2, "edit"} =>
switch access {
| ReadWrite => renderEditWithMultiId(id1, id2)
| Checker =>
isAdminAccount ? renderEditWithMultiId(id1, id2) : <UnauthorizedPage entityName />
| _ => <UnauthorizedPage entityName />
}
| list{"order", id} =>
Expand Down
8 changes: 1 addition & 7 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ let make = () => {
->QuickStartUtils.getTypedValueFromDict

let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom

let getEnumDetails = EnumVariantHook.useFetchEnumDetails()
let verificationDays = getFromMerchantDetails("verification")->LogicUtils.getIntFromString(-1)
let userRole = getFromUserDetails("user_role")
Expand All @@ -55,12 +54,7 @@ let make = () => {
let isReconEnabled =
(merchantDetailsValue->MerchantAccountUtils.getMerchantDetails).recon_status === Active

let hyperSwitchAppSidebars = SidebarValues.getHyperSwitchAppSidebars(
~isReconEnabled,
~featureFlagDetails,
~userRole,
(),
)
let hyperSwitchAppSidebars = SidebarValues.useGetSidebarValues(~isReconEnabled)

let comingSoonPage =
<DefaultLandingPage
Expand Down
5 changes: 4 additions & 1 deletion src/entryPoints/hyperswitch/HyperswitchAtom.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ let featureFlagAtom: Recoil.recoilAtom<FeatureFlagUtils.featureFlag> = Recoil.at
"featureFlag",
Js.Json.null->FeatureFlagUtils.featureFlagType,
)

let paypalAccountStatusAtom: Recoil.recoilAtom<PayPalFlowTypes.setupAccountStatus> = Recoil.atom(.
"paypalAccountStatusAtom",
PayPalFlowTypes.Account_not_found,
)
let userPermissionAtom: Recoil.recoilAtom<array<PermissionUtils.permissionType>> = Recoil.atom(.
"userPermissionAtom",
[],
)
11 changes: 5 additions & 6 deletions src/entryPoints/hyperswitch/SidebarValues.res
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,10 @@ let reconTag = (recon, isReconEnabled) =>
})
: emptyComponent

let getHyperSwitchAppSidebars = (
~isReconEnabled: bool,
~featureFlagDetails: FeatureFlagUtils.featureFlag,
~userRole,
(),
) => {
let useGetSidebarValues = (~isReconEnabled: bool) => {
let userRole = HSLocalStorage.getFromUserDetails("user_role")
let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom

let {
productionAccess,
frm,
Expand All @@ -332,6 +330,7 @@ let getHyperSwitchAppSidebars = (
isLiveMode,
customersModule,
} = featureFlagDetails

let sidebar = [
productionAccess->productionAccessComponent,
default->home,
Expand Down
107 changes: 107 additions & 0 deletions src/screens/HyperSwitch/UserManagement/PermissionUtils.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
type permissionType =
| PaymentRead
| PaymentWrite
| RefundRead
| RefundWrite
| ApiKeyRead
| ApiKeyWrite
| MerchantAccountRead
| MerchantAccountWrite
| MerchantConnectorAccountRead
| MerchantConnectorAccountWrite
| ForexRead
| RoutingRead
| RoutingWrite
| DisputeRead
| DisputeWrite
| MandateRead
| MandateWrite
| CustomerRead
| CustomerWrite
| FileRead
| FileWrite
| Analytics
| ThreeDsDecisionManagerWrite
| ThreeDsDecisionManagerRead
| SurchargeDecisionManagerWrite
| SurchargeDecisionManagerRead
| UsersRead
| UsersWrite
| UnknownPermission(string)

let mapPermissionTypeToString = permissionType => {
switch permissionType {
| PaymentRead => "PaymentRead"
| PaymentWrite => "PaymentWrite"
| RefundRead => "RefundRead"
| RefundWrite => "RefundWrite"
| ApiKeyRead => "ApiKeyRead"
| ApiKeyWrite => "ApiKeyWrite"
| MerchantAccountRead => "MerchantAccountRead"
| MerchantAccountWrite => "MerchantAccountWrite"
| MerchantConnectorAccountRead => "MerchantConnectorAccountRead"
| MerchantConnectorAccountWrite => "MerchantConnectorAccountWrite"
| ForexRead => "ForexRead"
| RoutingRead => "RoutingRead"
| RoutingWrite => "RoutingWrite"
| DisputeRead => "DisputeRead"
| DisputeWrite => "DisputeWrite"
| MandateRead => "MandateRead"
| MandateWrite => "MandateWrite"
| CustomerRead => "CustomerRead"
| CustomerWrite => "CustomerWrite"
| FileRead => "FileRead"
| FileWrite => "FileWrite"
| Analytics => "Analytics"
| ThreeDsDecisionManagerWrite => "ThreeDsDecisionManagerWrite"
| ThreeDsDecisionManagerRead => "ThreeDsDecisionManagerRead"
| SurchargeDecisionManagerWrite => "SurchargeDecisionManagerWrite"
| SurchargeDecisionManagerRead => "SurchargeDecisionManagerRead"
| UsersRead => "UsersRead"
| UsersWrite => "UsersWrite"
| UnknownPermission(val) => val
}
}

let mapStringToPermissionType = val => {
switch val {
| "PaymentRead" => PaymentRead
| "PaymentWrite" => PaymentWrite
| "RefundRead" => RefundRead
| "RefundWrite" => RefundWrite
| "ApiKeyRead" => ApiKeyRead
| "ApiKeyWrite" => ApiKeyWrite
| "MerchantAccountRead" => MerchantAccountRead
| "MerchantAccountWrite" => MerchantAccountWrite
| "MerchantConnectorAccountRead" => MerchantConnectorAccountRead
| "MerchantConnectorAccountWrite" => MerchantConnectorAccountWrite
| "ForexRead" => ForexRead
| "RoutingRead" => RoutingRead
| "RoutingWrite" => RoutingWrite
| "DisputeRead" => DisputeRead
| "DisputeWrite" => DisputeWrite
| "MandateRead" => MandateRead
| "MandateWrite" => MandateWrite
| "CustomerRead" => CustomerRead
| "CustomerWrite" => CustomerWrite
| "FileRead" => FileRead
| "FileWrite" => FileWrite
| "Analytics" => Analytics
| "ThreeDsDecisionManagerWrite" => ThreeDsDecisionManagerWrite
| "ThreeDsDecisionManagerRead" => ThreeDsDecisionManagerRead
| "SurchargeDecisionManagerWrite" => SurchargeDecisionManagerWrite
| "SurchargeDecisionManagerRead" => SurchargeDecisionManagerRead
| "UsersRead" => UsersRead
| "UsersWrite" => UsersWrite
| val => UnknownPermission(val)
}
}

let getAccessValue = (~permissionValue: permissionType, permissionList) => {
open AuthTypes
let isPermissionFound = permissionList->Array.find(ele => {
ele === permissionValue
})

isPermissionFound->Option.isSome ? Read : NoAccess
}
9 changes: 1 addition & 8 deletions src/screens/HyperSwitch/Utils/HSwitchGlobalSearchBar.res
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,11 @@ let make = () => {
let (showModal, setShowModal) = React.useState(_ => false)
let (searchText, setSearchText) = React.useState(_ => "")
let (arr, setArr) = React.useState(_ => [])
let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let merchentDetails = HSwitchUtils.useMerchantDetailsValue()
let userRole = HSLocalStorage.getFromUserDetails("user_role")
let isReconEnabled =
(merchentDetails->MerchantAccountUtils.getMerchantDetails).recon_status === Active

let hswitchTabs = SidebarValues.getHyperSwitchAppSidebars(
~isReconEnabled,
~featureFlagDetails,
~userRole,
(),
)
let hswitchTabs = SidebarValues.useGetSidebarValues(~isReconEnabled)
let searchText = searchText->String.trim
React.useEffect1(_ => {
let matchedList = hswitchTabs->Array.reduce([], (acc, item) => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/login/AuthTypes.res
Original file line number Diff line number Diff line change
@@ -1 +1 @@
type authorization = NoAccess | Read | ReadWrite | Checker
type authorization = NoAccess | Read | ReadWrite

0 comments on commit f428679

Please sign in to comment.