From 0aafec4579aa3655807696ac23d570c301567f0f Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja Date: Fri, 6 Sep 2024 15:29:38 +0530 Subject: [PATCH] chore: pin functionality removed (#1297) Co-authored-by: Jeeva Ramachandran <120017870+JeevaRamu0104@users.noreply.github.com> Co-authored-by: Jeeva Ramachandran --- src/container/UserManagementContainer.res | 28 ++-- src/entryPoints/AuthModule/UserInfoScreen.res | 2 - src/entryPoints/Provider/ProviderTypes.res | 2 - src/screens/APIUtils/APIUtils.res | 2 - src/screens/Sidebar/Sidebar.res | 142 +++++------------- src/screens/Sidebar/SidebarProvider.res | 14 -- src/screens/Sidebar/SidebarSwitch.res | 6 +- 7 files changed, 56 insertions(+), 140 deletions(-) diff --git a/src/container/UserManagementContainer.res b/src/container/UserManagementContainer.res index e756059ac..f0c66b141 100644 --- a/src/container/UserManagementContainer.res +++ b/src/container/UserManagementContainer.res @@ -21,16 +21,18 @@ let make = () => { let fetchModuleList = async () => { try { - setScreenState(_ => PageLoaderWrapper.Loading) - let url = getURL( - ~entityName=USERS, - ~userType=#ROLE_INFO, - ~methodType=Get, - ~queryParamerters=Some(`groups=true`), - ) - let res = await fetchDetails(url) - let roleInfo = res->LogicUtils.getArrayDataFromJson(UserUtils.itemToObjMapperForGetRoleInfro) - setRoleInfo(_ => roleInfo) + if userPermissionJson.usersManage === Access { + let url = getURL( + ~entityName=USERS, + ~userType=#ROLE_INFO, + ~methodType=Get, + ~queryParamerters=Some(`groups=true`), + ) + let res = await fetchDetails(url) + let roleInfo = + res->LogicUtils.getArrayDataFromJson(UserUtils.itemToObjMapperForGetRoleInfro) + setRoleInfo(_ => roleInfo) + } setScreenState(_ => PageLoaderWrapper.Success) } catch { | _ => setScreenState(_ => PageLoaderWrapper.Error("")) @@ -38,9 +40,7 @@ let make = () => { } React.useEffect(() => { - if userPermissionJson.usersManage === Access { - fetchModuleList()->ignore - } + fetchModuleList()->ignore None }, []) @@ -69,7 +69,7 @@ let make = () => { /> | list{"unauthorized"} => - | _ => <> + | _ => }} } diff --git a/src/entryPoints/AuthModule/UserInfoScreen.res b/src/entryPoints/AuthModule/UserInfoScreen.res index 618c3cfcb..00276cdf0 100644 --- a/src/entryPoints/AuthModule/UserInfoScreen.res +++ b/src/entryPoints/AuthModule/UserInfoScreen.res @@ -2,7 +2,6 @@ let make = (~onClick) => { let (errorMessage, setErrorMessage) = React.useState(_ => "") let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) - let {setIsSidebarDetails} = React.useContext(SidebarProvider.defaultContext) let {setAuthStatus, authStatus} = React.useContext(AuthInfoProvider.authStatusContext) let token = switch authStatus { @@ -15,7 +14,6 @@ let make = (~onClick) => { let dict = [("token", token->Option.getOr("")->JSON.Encode.string)]->Dict.fromArray let info = AuthUtils.getAuthInfo(dict->JSON.Encode.object) setAuthStatus(LoggedIn(Auth(info))) - setIsSidebarDetails("isPinned", false->JSON.Encode.bool) removeItemFromLocalStorage(~key="PRE_LOGIN_INFO") removeItemFromLocalStorage(~key="email_token") removeItemFromLocalStorage(~key="code") diff --git a/src/entryPoints/Provider/ProviderTypes.res b/src/entryPoints/Provider/ProviderTypes.res index a97602d38..f94294f7d 100644 --- a/src/entryPoints/Provider/ProviderTypes.res +++ b/src/entryPoints/Provider/ProviderTypes.res @@ -44,6 +44,4 @@ type contextType = { type sidebarContextType = { isSidebarExpanded: bool, setIsSidebarExpanded: (bool => bool) => unit, - getFromSidebarDetails: string => bool, - setIsSidebarDetails: (string, JSON.t) => unit, } diff --git a/src/screens/APIUtils/APIUtils.res b/src/screens/APIUtils/APIUtils.res index 29d96dade..82628ba2a 100644 --- a/src/screens/APIUtils/APIUtils.res +++ b/src/screens/APIUtils/APIUtils.res @@ -693,7 +693,6 @@ let useGetURL = () => { let useHandleLogout = () => { let getURL = useGetURL() let {setAuthStateToLogout} = React.useContext(AuthInfoProvider.authStatusContext) - let {setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext) let clearRecoilValue = ClearRecoilValueHook.useClearRecoilValue() let fetchApi = AuthHooks.useApiFetcher() @@ -711,7 +710,6 @@ let useHandleLogout = () => { JSON.Encode.null->resolve }) setAuthStateToLogout() - setIsSidebarExpanded(_ => false) clearRecoilValue() AuthUtils.redirectToLogin() LocalStorage.clear() diff --git a/src/screens/Sidebar/Sidebar.res b/src/screens/Sidebar/Sidebar.res index 01e91cdda..0f6162a6c 100644 --- a/src/screens/Sidebar/Sidebar.res +++ b/src/screens/Sidebar/Sidebar.res @@ -33,11 +33,11 @@ module MenuOption = { module SidebarOption = { @react.component - let make = (~isExpanded, ~name, ~icon, ~isSelected) => { + let make = (~isSidebarExpanded, ~name, ~icon, ~isSelected) => { let textBoldStyles = isSelected ? "font-bold" : "font-semibold opacity-60" let iconColor = isSelected ? "text-white" : "text-white opacity-60" - if isExpanded { + if isSidebarExpanded {
@@ -74,7 +74,7 @@ module SidebarSubOption = { module SidebarItem = { @react.component - let make = (~tabInfo, ~isSelected, ~isExpanded, ~setOpenItem=_ => ()) => { + let make = (~tabInfo, ~isSelected, ~isSidebarExpanded, ~setOpenItem=_ => ()) => { let sidebarItemRef = React.useRef(Nullable.null) let {getSearchParamByLink} = React.useContext(UserPrefContext.userPrefContext) let getSearchParamByLink = link => getSearchParamByLink(String.substringToEnd(link, ~start=0)) @@ -114,10 +114,10 @@ module SidebarItem = {
ReactDOM.Ref.domRef} onClick={onSidebarItemClick} - className={`${textColor} relative overflow-hidden flex flex-row items-center rounded-lg cursor-pointer ${selectedClass} p-3 ${isExpanded + className={`${textColor} relative overflow-hidden flex flex-row items-center rounded-lg cursor-pointer ${selectedClass} p-3 ${isSidebarExpanded ? "mx-2" : "mx-1"} hover:bg-light_white my-0.5`}> - +
@@ -136,7 +136,7 @@ module SidebarItem = { href={link} target="_blank" className={`${textColor} flex flex-row items-center cursor-pointer ${selectedClass} p-3`}> - + remoteUi @@ -149,11 +149,11 @@ module SidebarItem = {
isMobileView ? setIsSidebarExpanded(_ => false) : ()} - className={`${textColor} flex flex-row items-center cursor-pointer transition duration-300 ${selectedClass} p-3 ${isExpanded + className={`${textColor} flex flex-row items-center cursor-pointer transition duration-300 ${selectedClass} p-3 ${isSidebarExpanded ? "mx-2" : "mx-1"} hover:bg-light_white my-0.5`}> - - + + Option.getOr(26)} name=iconTag @@ -333,7 +333,6 @@ module SidebarNestedSection = { ~linkSelectionCheck, ~firstPart, ~isSideBarExpanded, - ~setIsSidebarExpanded, ~openItem="", ~setOpenItem=_ => (), ~isSectionAutoCollapseEnabled=false, @@ -369,9 +368,8 @@ module SidebarNestedSection = { None }, (isSideBarExpanded, isAnySubItemSelected)) - let toggleSectionExpansion = React.useCallback(_ev => { + let toggleSectionExpansion = React.useCallback(_ => { if !isSideBarExpanded { - setIsSidebarExpanded(_ => true) setTimeout(() => { setIsSectionExpanded(_ => true) }, 200)->ignore @@ -380,7 +378,7 @@ module SidebarNestedSection = { } else { setIsSectionExpanded(p => !p) } - }, (setIsSectionExpanded, isSideBarExpanded, setIsSidebarExpanded, isAnySubItemSelected)) + }, (setIsSectionExpanded, isSideBarExpanded, isAnySubItemSelected)) let textColor = { if isSideBarExpanded { @@ -444,45 +442,6 @@ module SidebarNestedSection = { } } -module PinIconComponentStates = { - @react.component - let make = (~isHSSidebarPinned, ~setIsSidebarExpanded, ~isSidebarExpanded) => { - let isMobileView = MatchMedia.useMobileChecker() - let {setIsSidebarDetails} = React.useContext(SidebarProvider.defaultContext) - - let toggleExpand = React.useCallback(_ => { - setIsSidebarExpanded(x => !x) - }, []) - - let onClick = ev => { - ev->ReactEvent.Mouse.preventDefault - ev->ReactEvent.Mouse.stopPropagation - ev->toggleExpand - setIsSidebarDetails("isPinned", !isHSSidebarPinned->JSON.Encode.bool) - } - - <> - - - - - - - -
- setIsSidebarExpanded(_ => false)} - /> -
-
- - } -} - @react.component let make = ( ~sidebars: array, @@ -502,36 +461,21 @@ let make = ( let {email} = useCommonAuthInfo()->Option.getOr(defaultAuthInfo) let (openItem, setOpenItem) = React.useState(_ => "") - let {getFromSidebarDetails} = React.useContext(SidebarProvider.defaultContext) let {isSidebarExpanded, setIsSidebarExpanded} = React.useContext(SidebarProvider.defaultContext) - let {setIsSidebarDetails} = React.useContext(SidebarProvider.defaultContext) - - let minWidthForPinnedState = MatchMedia.useMatchMedia("(min-width: 1280px)") - // let clearRecoilValue = ClearRecoilValueHook.useClearRecoilValue() React.useEffect(() => { - if minWidthForPinnedState { - setIsSidebarDetails("isPinned", true->JSON.Encode.bool) - setIsSidebarExpanded(_ => true) - } else { - setIsSidebarDetails("isPinned", false->JSON.Encode.bool) - setIsSidebarExpanded(_ => false) - } - + setIsSidebarExpanded(_ => !isMobileView) None - }, [minWidthForPinnedState]) - - let isHSSidebarPinned = getFromSidebarDetails("isPinned") - let isExpanded = isSidebarExpanded || isHSSidebarPinned + }, [isMobileView]) let sidebarWidth = { - switch isExpanded { + switch isSidebarExpanded { | true => switch isMobileView { | true => "100%" - | false => "270px" + | false => "275px" } - | false => "55px" + | false => "275px" } } let profileMaxWidth = "145px" @@ -541,27 +485,12 @@ let make = ( | None => "/" } - let expansionClass = !isExpanded ? "-translate-x-full" : "" + let expansionClass = !isSidebarExpanded ? "-translate-x-full" : "" let sidebarClass = "shadow-md" let sidebarMaxWidth = isMobileView ? "w-screen" : "w-max" - let onMouseHoverEvent = () => { - if !isHSSidebarPinned { - setIsSidebarExpanded(_ => true) - } else { - () - } - } - - let onMouseHoverLeaveEvent = () => { - if !isHSSidebarPinned { - setIsSidebarExpanded(_ => false) - } else { - () - } - } - let sidebarContainerClassWidth = isMobileView ? "0px" : isHSSidebarPinned ? "275px" : "50px" + let sidebarContainerClassWidth = isMobileView ? "0px" : "275px" let transformClass = "transform md:translate-x-0 transition" @@ -598,9 +527,7 @@ let make = ( style={width: sidebarContainerClassWidth} />
onMouseHoverEvent()} - onMouseLeave={_ => onMouseHoverLeaveEvent()}> + className={`absolute z-40 h-screen flex ${transformClass} duration-300 ease-in-out ${sidebarMaxWidth} ${expansionClass}`}>
ReactDOM.Ref.domRef} className={`${backgroundColor.primaryNormal} flex h-full flex-col transition-all duration-100 ${sidebarClass} relative inset-0`} @@ -614,10 +541,20 @@ let make = ( }}>
- + +
+ setIsSidebarExpanded(_ => false)} + /> +
+
- +
{ let isSelected = linkSelectionCheck(firstPart, record.link) } | LinkWithTag(record) => { let isSelected = linkSelectionCheck(firstPart, record.link) - + } | Section(section) => @@ -646,8 +583,7 @@ let make = ( section linkSelectionCheck firstPart - isSideBarExpanded={isExpanded} - setIsSidebarExpanded + isSideBarExpanded={isSidebarExpanded} openItem setOpenItem isSectionAutoCollapseEnabled=true @@ -656,14 +592,14 @@ let make = ( | Heading(headingOptions) =>
- {{isExpanded ? headingOptions.name : ""}->React.string} + {{isSidebarExpanded ? headingOptions.name : ""}->React.string}
| CustomComponent(customComponentOptions) => - + customComponentOptions.component } @@ -671,7 +607,7 @@ let make = ( ->React.array}
- + {popoverProps => <> + toolTipFor={
{email->React.string} diff --git a/src/screens/Sidebar/SidebarProvider.res b/src/screens/Sidebar/SidebarProvider.res index fd0cf74d1..8572e158a 100644 --- a/src/screens/Sidebar/SidebarProvider.res +++ b/src/screens/Sidebar/SidebarProvider.res @@ -1,20 +1,8 @@ open ProviderTypes -let setIsSidebarDetails = (key, value) => { - let localStorageData = HSLocalStorage.getInfoFromLocalStorage(~lStorageKey="sidebar") - localStorageData->Dict.set(key, value) - "sidebar"->LocalStorage.setItem(localStorageData->JSON.stringifyAny->Option.getOr("")) -} - -let getFromSidebarDetails = key => { - HSLocalStorage.getInfoFromLocalStorage(~lStorageKey="sidebar")->LogicUtils.getBool(key, false) -} - let defaultValue = { isSidebarExpanded: false, setIsSidebarExpanded: _ => (), - getFromSidebarDetails, - setIsSidebarDetails, } let defaultContext = React.createContext(defaultValue) @@ -31,8 +19,6 @@ let make = (~children) => { value={ isSidebarExpanded, setIsSidebarExpanded, - getFromSidebarDetails, - setIsSidebarDetails, }> children diff --git a/src/screens/Sidebar/SidebarSwitch.res b/src/screens/Sidebar/SidebarSwitch.res index 4b0b77109..0d3bb30e4 100644 --- a/src/screens/Sidebar/SidebarSwitch.res +++ b/src/screens/Sidebar/SidebarSwitch.res @@ -12,7 +12,7 @@ module OrgMerchantSwitchCollapsed = { } @react.component -let make = (~isExpanded=false) => { +let make = (~isSidebarExpanded=false) => { let expandedContent =
@@ -25,8 +25,8 @@ let make = (~isExpanded=false) => {
<> - expandedContent - + expandedContent +