import { ArrowLeft } from 'lucide-react' import Link from 'next/link' import { PropsWithChildren, ReactNode } from 'react' import { useAppStateSnapshot } from 'state/app-state' import { cn, Menu } from 'ui' import MobileSheetNav from 'ui-patterns/MobileSheetNav/MobileSheetNav' import type { SidebarSection } from './AccountLayout.types' interface WithSidebarProps { title: string breadcrumbs: any[] sections: SidebarSection[] header?: ReactNode subitems?: any[] subitemsParentKey?: number hideSidebar?: boolean customSidebarContent?: ReactNode backToDashboardURL?: string } export const WithSidebar = ({ title, header, breadcrumbs = [], children, sections, subitems, subitemsParentKey, hideSidebar = false, customSidebarContent, backToDashboardURL, }: PropsWithChildren) => { const noContent = !sections && !customSidebarContent const { mobileMenuOpen, setMobileMenuOpen } = useAppStateSnapshot() return (
{!hideSidebar && !noContent && ( )}
{children}
) } export const SidebarContent = ({ title, header, sections, subitems, subitemsParentKey, customSidebarContent, backToDashboardURL, className, }: PropsWithChildren> & { className?: string }) => { return ( <>
{backToDashboardURL && (
Back to dashboard
)} {header && header}
{customSidebarContent} {sections.map((section, idx) => (
{Boolean(section.heading) ? ( ) : (
{section.links.map((link, i: number) => { const isActive = link.isActive && !subitems return (
{link.label}
) })}
)} {idx !== sections.length - 1 && (
)}
))}
) } interface SectionWithHeadersProps { section: SidebarSection subitems?: any[] subitemsParentKey?: number } const SectionWithHeaders = ({ section, subitems, subitemsParentKey }: SectionWithHeadersProps) => (
{section.heading && ( {section.heading}
} /> )}
{section.links.map((link, i: number) => { const isActive = link.isActive && !subitems return (
{link.label}
) })}
)