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: sidebar refactoring & permissions added #264

Merged
merged 10 commits into from
Jan 17, 2024
4 changes: 0 additions & 4 deletions src/components/EntityScaffold.res
Original file line number Diff line number Diff line change
@@ -52,7 +52,6 @@ let make = (
| list{"new"} =>
switch access {
| ReadWrite => renderNewForm()
| Checker => isAdminAccount ? renderNewForm() : <UnauthorizedPage entityName />
| _ => <UnauthorizedPage entityName />
}
| list{id, "clone"} =>
@@ -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} =>
8 changes: 1 addition & 7 deletions src/entryPoints/hyperswitch/HyperSwitchApp.res
Original file line number Diff line number Diff line change
@@ -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")
@@ -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
5 changes: 4 additions & 1 deletion src/entryPoints/hyperswitch/HyperswitchAtom.res
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
@@ -332,6 +330,7 @@ let getHyperSwitchAppSidebars = (
isLiveMode,
customersModule,
} = featureFlagDetails

let sidebar = [
productionAccess->productionAccessComponent,
default->home,
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
@@ -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) => {
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