From 49e3eaeb9bd14a3c788649b81cf561386a5ce006 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Thu, 18 Jan 2024 14:57:47 +0530 Subject: [PATCH 1/6] chore: Added Access Type & Remove the Read & ReadWrite Type (#267) --- src/components/EntityScaffold.res | 75 +++---------------- src/components/UnauthorizedPage.res | 19 +++++ src/components/form/BoolInput.res | 11 +-- src/context/FormAuthContext.res | 2 +- .../hyperswitch/HyperSwitchApp.res | 12 +-- src/entryPoints/hyperswitch/SidebarValues.res | 44 +++++------ .../UserManagement/PermissionUtils.res | 2 +- src/screens/login/AuthTypes.res | 2 +- 8 files changed, 63 insertions(+), 104 deletions(-) create mode 100644 src/components/UnauthorizedPage.res diff --git a/src/components/EntityScaffold.res b/src/components/EntityScaffold.res index d9d048b33..68afbe809 100644 --- a/src/components/EntityScaffold.res +++ b/src/components/EntityScaffold.res @@ -1,85 +1,32 @@ -module ComingSoon = { - @react.component - let make = (~title) => { -
-
{React.string(title)}
-
{React.string("Coming soon...")}
-
- } -} - -module ShowPage = { - @react.component - let make = (~entityName, ~id) => { -
-
- {React.string(`Show ${entityName} `)} - {React.string(`#${id}`)} -
-
{React.string("Coming soon...")}
-
- } -} - -module UnauthorizedPage = { - @react.component - let make = (~entityName) => { -
-
{React.string(entityName)}
-
{React.string("You don't have access to this module. Contact admin for access")}
-
- } -} - @react.component let make = ( ~entityName="", ~remainingPath, ~isAdminAccount=false, - ~access: AuthTypes.authorization=ReadWrite, - ~renderList=() => , - ~renderNewForm=() => , + ~access: AuthTypes.authorization=Access, + ~renderList, + ~renderNewForm=?, ~renderShow=?, - ~renderOrder=?, - ~renderEdit=_id => , - ~renderEditWithMultiId=(_id1, _id2) => , - ~renderClone=_id => , ) => { if access === NoAccess { - + } else { switch remainingPath { | list{"new"} => switch access { - | ReadWrite => renderNewForm() - | _ => - } - | list{id, "clone"} => - switch access { - | ReadWrite => renderClone(id) - | _ => + | Access => + switch renderNewForm { + | Some(element) => element() + | None => React.null + } + | NoAccess => } | list{id} => let page = switch renderShow { | Some(fn) => fn(id) - | None => + | None => React.null } page - | list{id, "edit"} => - switch access { - | ReadWrite => renderEdit(id) - | _ => - } - | list{id1, id2, "edit"} => - switch access { - | ReadWrite => renderEditWithMultiId(id1, id2) - | _ => - } - | list{"order", id} => - switch renderOrder { - | Some(fn) => fn(id) - | None => - } | list{} => renderList() | _ => } diff --git a/src/components/UnauthorizedPage.res b/src/components/UnauthorizedPage.res new file mode 100644 index 000000000..55bddadc9 --- /dev/null +++ b/src/components/UnauthorizedPage.res @@ -0,0 +1,19 @@ +@react.component +let make = (~message="You don't have access to this module. Contact admin for access") => { + let {setDashboardPageState} = React.useContext(GlobalProvider.defaultContext) + React.useEffect0(() => { + RescriptReactRouter.replace("/unauthorized") + None + }) + + - + }} + + + } diff --git a/src/components/Button.resi b/src/components/Button.resi index 53bb21c2f..5d9c12918 100644 --- a/src/components/Button.resi +++ b/src/components/Button.resi @@ -75,7 +75,7 @@ let useGetTextColor: ( ) => string @react.component let make: ( - ~buttonFor: Js.String2.t=?, + ~buttonFor: string=?, ~loadingText: string=?, ~buttonState: buttonState=?, ~text: Js.String2.t=?, @@ -101,7 +101,7 @@ let make: ( ~textWeight: string=?, ~fullLength: bool=?, ~disableRipple: bool=?, - ~customButtonStyle: Js.String2.t=?, + ~customButtonStyle: string=?, ~textStyleClass: string=?, ~customTextPaddingClass: string=?, ~allowButtonTextMinWidth: bool=?, @@ -115,4 +115,5 @@ let make: ( ~customBackColor: string=?, ~isPhoneDropdown: bool=?, ~showBtnTextToolTip: bool=?, + ~access: AuthTypes.authorization=?, ) => React.element diff --git a/src/components/HyperSwitchAuthWrapper.res b/src/components/HyperSwitchAuthWrapper.res index ee0d30017..9f0c21dbd 100644 --- a/src/components/HyperSwitchAuthWrapper.res +++ b/src/components/HyperSwitchAuthWrapper.res @@ -23,7 +23,7 @@ let make = (~children) => { | _ => switch LocalStorage.getItem("login")->Js.Nullable.toOption { | Some(token) => - if !(token->HSwitchUtils.isEmptyString) { + if !(token->LogicUtils.isEmptyString) { setAuthStatus(LoggedIn(HyperSwitchAuthTypes.getDummyAuthInfoForToken(token))) } else { setAuthStatus(LoggedOut) diff --git a/src/context/FilterContext.res b/src/context/FilterContext.res index 355099271..03c1d5646 100644 --- a/src/context/FilterContext.res +++ b/src/context/FilterContext.res @@ -33,7 +33,7 @@ module Provider = { @react.component let make = (~index: string, ~children, ~disableSessionStorage=false) => { open FilterUtils - open HSwitchUtils + open LogicUtils let query = React.useMemo0(() => {ref("")}) let searcParamsToDict = query.contents->parseFilterString let (filterDict, setfilterDict) = React.useState(_ => searcParamsToDict) diff --git a/src/screens/HyperSwitch/HSwitchUtils.res b/src/screens/HyperSwitch/HSwitchUtils.res index deb4836e0..41963eec0 100644 --- a/src/screens/HyperSwitch/HSwitchUtils.res +++ b/src/screens/HyperSwitch/HSwitchUtils.res @@ -272,8 +272,6 @@ let constructOnboardingBody = ( ])->Js.Json.object_ } -let isEmptyString = str => str->String.length <= 0 - type textVariantType = | H1 | H2 diff --git a/src/screens/HyperSwitch/Order/Orders.res b/src/screens/HyperSwitch/Order/Orders.res index 57adea0d9..db76eca36 100644 --- a/src/screens/HyperSwitch/Order/Orders.res +++ b/src/screens/HyperSwitch/Order/Orders.res @@ -2,8 +2,8 @@ let make = (~previewOnly=false) => { open APIUtils open HSwitchRemoteFilter - open HSwitchUtils open OrderUIUtils + open LogicUtils let updateDetails = useUpdateMethod() let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) let (orderData, setOrdersData) = React.useState(_ => []) @@ -14,8 +14,8 @@ let make = (~previewOnly=false) => { let connectorList = HyperswitchAtom.connectorListAtom ->Recoil.useRecoilValueFromAtom - ->LogicUtils.safeParse - ->LogicUtils.getObjectArrayFromJson + ->safeParse + ->getObjectArrayFromJson let isConfigureConnector = connectorList->Array.length > 0 let (widthClass, heightClass) = React.useMemo1(() => { diff --git a/src/screens/HyperSwitch/Refunds/Refund.res b/src/screens/HyperSwitch/Refunds/Refund.res index 88f575dc4..5ee0b3d02 100644 --- a/src/screens/HyperSwitch/Refunds/Refund.res +++ b/src/screens/HyperSwitch/Refunds/Refund.res @@ -2,7 +2,7 @@ let make = () => { open APIUtils open HSwitchRemoteFilter - open HSwitchUtils + open LogicUtils open RefundUtils let updateDetails = useUpdateMethod() let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) diff --git a/src/screens/login/HSwitchLoginFlow/HyperSwitchAuth.res b/src/screens/login/HSwitchLoginFlow/HyperSwitchAuth.res index 84c29b58e..edb0b3520 100644 --- a/src/screens/login/HSwitchLoginFlow/HyperSwitchAuth.res +++ b/src/screens/login/HSwitchLoginFlow/HyperSwitchAuth.res @@ -57,7 +57,7 @@ let make = (~setAuthStatus: HyperSwitchAuthTypes.authStatus => unit, ~authType, let token = parseResponseJson(~json=res, ~email) // home - if !(token->HSwitchUtils.isEmptyString) { + if !(token->isEmptyString) { setAuthStatus(LoggedIn(HyperSwitchAuthTypes.getDummyAuthInfoForToken(token))) } else { showToast(~message="Failed to sign in, Try again", ~toastType=ToastError, ()) diff --git a/src/screens/login/HSwitchLoginFlow/HyperSwitchEmailVerifyScreen.res b/src/screens/login/HSwitchLoginFlow/HyperSwitchEmailVerifyScreen.res index dc412e9b3..be70ff263 100644 --- a/src/screens/login/HSwitchLoginFlow/HyperSwitchEmailVerifyScreen.res +++ b/src/screens/login/HSwitchLoginFlow/HyperSwitchEmailVerifyScreen.res @@ -14,7 +14,7 @@ let generateBody = (url: RescriptReactRouter.url) => { let make = (~setAuthType, ~setAuthStatus, ~authType) => { open HyperSwitchAuthTypes open APIUtils - open HSwitchUtils + open LogicUtils let url = RescriptReactRouter.useUrl() let updateDetails = useUpdateMethod() let (errorMessage, setErrorMessage) = React.useState(_ => "") @@ -26,10 +26,7 @@ let make = (~setAuthType, ~setAuthStatus, ~authType) => { let url = getURL(~entityName=USERS, ~methodType=Post, ~userType, ()) let res = await updateDetails(url, body, Post) let email = - res - ->Js.Json.decodeObject - ->Belt.Option.getWithDefault(Dict.make()) - ->LogicUtils.getString("email", "") + res->Js.Json.decodeObject->Belt.Option.getWithDefault(Dict.make())->getString("email", "") let token = HyperSwitchAuthUtils.parseResponseJson(~json=res, ~email) if !(token->isEmptyString) && !(email->isEmptyString) { setAuthStatus(LoggedIn(HyperSwitchAuthTypes.getDummyAuthInfoForToken(token))) diff --git a/src/utils/LogicUtils.res b/src/utils/LogicUtils.res index a90dfe236..c22aa8f68 100644 --- a/src/utils/LogicUtils.res +++ b/src/utils/LogicUtils.res @@ -498,6 +498,9 @@ let numericArraySortComperator = (a, b) => { let isEmptyDict = dict => { dict->Dict.keysToArray->Array.length === 0 } + +let isEmptyString = str => str->String.length === 0 + let stringReplaceAll = (str, old, new) => { str->String.split(old)->Array.joinWith(new) } From 23c1ecb046bea3dcb4788938657db1ed925427d9 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:34:12 +0000 Subject: [PATCH 6/6] chore(version): v1.26.0 --- CHANGELOG.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc051fa9..3555b2371 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,31 @@ All notable changes to this project will be documented in this file. See [conven - - - +## 1.26.0 (2024-01-18) + +### Features + +- Add new user ([#237](https://github.com/juspay/hyperswitch-control-center/pull/237)) ([`3749e32`](https://github.com/juspay/hyperswitch-control-center/commit/3749e3278602c2ad514079db3d6d78226cfa9391)) +- Access added for Button ([#274](https://github.com/juspay/hyperswitch-control-center/pull/274)) ([`d5ecee6`](https://github.com/juspay/hyperswitch-control-center/commit/d5ecee626d3da87f6bda8495b7539ba8660a7618)) + +### Bug Fixes + +- Floating point value fix for test payment ([#270](https://github.com/juspay/hyperswitch-control-center/pull/270)) ([`038a714`](https://github.com/juspay/hyperswitch-control-center/commit/038a71492de22f1a1a51b6de9f68f010bf872268)) + +### Refactors + +- Routing types and utils ([#254](https://github.com/juspay/hyperswitch-control-center/pull/254)) ([`b8b5034`](https://github.com/juspay/hyperswitch-control-center/commit/b8b5034fbae6974e34c799e6f9333e3663247f7f)) + +### Miscellaneous Tasks + +- Added Access Type & Remove the Read & ReadWrite Type ([#267](https://github.com/juspay/hyperswitch-control-center/pull/267)) ([`49e3eae`](https://github.com/juspay/hyperswitch-control-center/commit/49e3eaeb9bd14a3c788649b81cf561386a5ce006)) +- Refactor invite users ([#273](https://github.com/juspay/hyperswitch-control-center/pull/273)) ([`85b07d0`](https://github.com/juspay/hyperswitch-control-center/commit/85b07d0cf058dd0842b11acb7714cd85f8d9d6c6)) + +**Full Changelog:** [`v1.25.1...v1.26.0`](https://github.com/juspay/hyperswitch-control-center/compare/v1.25.1...v1.26.0) + +- - - + + ## 1.25.1 (2024-01-17) ### Miscellaneous Tasks