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

feat(Orgs): Update sidebar #5019

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/web/public/images/sidebar/bank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/web/public/images/sidebar/members.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion apps/web/src/components/common/PageLayout/SideDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import OrgsSidebar from '@/features/organizations/components/OrgsSidebar'
import { useIsOrganizationRoute } from '@/hooks/useIsOrganizationRoute'
import { useRouter } from 'next/router'
import { useEffect, type ReactElement } from 'react'
import { IconButton, Drawer, useMediaQuery } from '@mui/material'
Expand All @@ -20,6 +22,8 @@ const SideDrawer = ({ isOpen, onToggle }: SideDrawerProps): ReactElement => {
const { breakpoints } = useTheme()
const isSmallScreen = useMediaQuery(breakpoints.down('md'))
const [, isSafeAppRoute] = useIsSidebarRoute()
const isOrganizationRoute = useIsOrganizationRoute()

const showSidebarToggle = isSafeAppRoute && !isSmallScreen
// Keep the sidebar hidden on small screens via CSS until we collapse it via JS.
// With a small delay to avoid flickering.
Expand All @@ -41,6 +45,8 @@ const SideDrawer = ({ isOpen, onToggle }: SideDrawerProps): ReactElement => {
}
}, [onToggle, router, isSmallScreen])

const SidebarComponent = isOrganizationRoute ? OrgsSidebar : Sidebar

return (
<>
<Drawer
Expand All @@ -56,7 +62,7 @@ const SideDrawer = ({ isOpen, onToggle }: SideDrawerProps): ReactElement => {
className={smDrawerHidden ? css.smDrawerHidden : undefined}
>
<aside>
<Sidebar />
<SidebarComponent />
</aside>
</Drawer>

Expand Down
11 changes: 2 additions & 9 deletions apps/web/src/components/common/PageLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import SideDrawer from './SideDrawer'
import { useIsSidebarRoute } from '@/hooks/useIsSidebarRoute'
import { TxModalContext } from '@/components/tx-flow'
import BatchSidebar from '@/components/batch/BatchSidebar'
import { useIsOrganizationRoute } from '@/hooks/useIsOrganizationRoute'
import OrganizationSidebar from '@/features/organizations/components/OrgsSidebar'

const PageLayout = ({ pathname, children }: { pathname: string; children: ReactElement }): ReactElement => {
const [isSidebarRoute, isAnimated] = useIsSidebarRoute(pathname)
const isOrganizationRoute = useIsOrganizationRoute(pathname)
const [isSidebarOpen, setSidebarOpen] = useState<boolean>(true)
const [isBatchOpen, setBatchOpen] = useState<boolean>(false)
const { setFullWidth } = useContext(TxModalContext)
Expand All @@ -29,15 +26,11 @@ const PageLayout = ({ pathname, children }: { pathname: string; children: ReactE
<Header onMenuToggle={isSidebarRoute ? setSidebarOpen : undefined} onBatchToggle={setBatchOpen} />
</header>

{isSidebarRoute ? (
<SideDrawer isOpen={isSidebarOpen} onToggle={setSidebarOpen} />
) : isOrganizationRoute ? (
<OrganizationSidebar />
) : null}
{isSidebarRoute ? <SideDrawer isOpen={isSidebarOpen} onToggle={setSidebarOpen} /> : null}

<div
className={classnames(css.main, {
[css.mainNoSidebar]: (!isSidebarOpen || !isSidebarRoute) && !isOrganizationRoute,
[css.mainNoSidebar]: !isSidebarOpen || !isSidebarRoute,
[css.mainAnimated]: isSidebarRoute && isAnimated,
})}
>
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/components/sidebar/Sidebar/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
overflow: hidden;
flex-direction: column;
background-color: var(--color-background-paper);
}

.container {
width: 230px;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { type ReactElement } from 'react'

import css from './styles.module.css'
import { Drawer } from '@mui/material'
import OrgsSidebarNavigation from '@/features/organizations/components/OrgsSidebarNavigation'
import OrgsSidebarSelector from '../OrgsSidebarSelector'

const OrgsSidebar = (): ReactElement => {
return (
<Drawer variant="permanent" anchor="left">
<div className={css.container}>
<OrgsSidebarSelector />
<OrgsSidebarNavigation />
</div>
</Drawer>
<div className={css.container}>
<OrgsSidebarSelector />
<OrgsSidebarNavigation />
</div>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { type ReactElement } from 'react'
import { AppRoutes } from '@/config/routes'
import HomeIcon from '@/public/images/sidebar/home.svg'
import SettingsIcon from '@/public/images/sidebar/settings.svg'
import MembersIcon from '@/public/images/sidebar/members.svg'
import AccountsIcon from '@/public/images/sidebar/bank.svg'
import { SvgIcon } from '@mui/material'

export type DynamicNavItem = {
Expand All @@ -19,17 +22,17 @@ export const navItems: DynamicNavItem[] = [
},
{
label: 'Safe Accounts',
icon: <SvgIcon component={HomeIcon} inheritViewBox />,
icon: <SvgIcon component={AccountsIcon} inheritViewBox sx={{ '& path': { fill: 'none !important' } }} />,
href: AppRoutes.organizations.safeAccounts,
},
{
label: 'Members',
icon: <SvgIcon component={HomeIcon} inheritViewBox />,
icon: <SvgIcon component={MembersIcon} inheritViewBox />,
href: AppRoutes.organizations.members,
},
{
label: 'Settings',
icon: <SvgIcon component={HomeIcon} inheritViewBox />,
icon: <SvgIcon component={SettingsIcon} inheritViewBox />,
href: AppRoutes.organizations.settings,
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Navigation = (): ReactElement => {
<SidebarList>
{navItems.map((item) => {
const itemPath = item.href(orgId)
const isSelected = router.pathname === itemPath
const isSelected = router.asPath === itemPath

return (
<div key={itemPath}>
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/hooks/useIsOrganizationRoute.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AppRoutes } from '@/config/routes'
import { usePathname } from 'next/navigation'

export const useIsOrganizationRoute = (pathname: string): boolean => {
export const useIsOrganizationRoute = (): boolean => {
const clientPathname = usePathname()
const route = pathname || clientPathname || ''
const route = clientPathname || ''

return route.startsWith(AppRoutes.organizations.index('')) // This will check against /organizations/
}
7 changes: 6 additions & 1 deletion apps/web/src/hooks/useIsSidebarRoute.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppRoutes } from '@/config/routes'
import { useIsOrganizationRoute } from '@/hooks/useIsOrganizationRoute'
import { usePathname } from 'next/navigation'
import { useRouter } from 'next/router'

Expand Down Expand Up @@ -26,10 +27,14 @@ const TOGGLE_SIDEBAR_ROUTES = [AppRoutes.apps.open]
*/
export function useIsSidebarRoute(pathname?: string): [boolean, boolean] {
const clientPathname = usePathname()
const isOrganizationRoute = useIsOrganizationRoute()
const route = pathname || clientPathname || ''
const noSidebar = NO_SIDEBAR_ROUTES.includes(route)
const toggledSidebar = TOGGLE_SIDEBAR_ROUTES.includes(route)
const router = useRouter()
const hasSafe = !router.isReady || !!router.query.safe
return [!noSidebar && hasSafe, toggledSidebar]

const displaySidebar = (!noSidebar && hasSafe) || isOrganizationRoute

return [displaySidebar, toggledSidebar]
}
Loading