import React from 'react'; import { Menu, MenuDivider } from '@blueprintjs/core'; import { useHistory, useLocation } from 'react-router-dom'; import { Choose } from 'components'; import Icon from 'components/Icon'; import MenuItem from 'components/MenuItem'; import { MenuItemLabel } from 'components'; import classNames from 'classnames'; import SidebarOverlay from 'components/SidebarOverlay'; import { compose } from 'redux'; import withSubscriptions from '../../containers/Subscriptions/withSubscriptions'; const DEFAULT_ITEM = { text: '', href: '', }; function matchPath(pathname, path, matchExact) { return matchExact ? pathname === path : pathname.indexOf(path) !== -1; } function SidebarMenuItemSpace({ space }) { return
; } function SidebarMenu({ menu, isSubscriptionActive }) { const history = useHistory(); const location = useLocation(); const [isOpen, setIsOpen] = React.useState(false); const [currentItem, setCurrentItem] = React.useState(null); const menuItemsMapper = (list) => { return list.map((item, index) => { const hasChildren = Array.isArray(item.children); const isActive = (item.children ? item.children.some((c) => matchPath(location.pathname, c.href, item.matchExact), ) : item.href && matchPath(location.pathname, item.href, item.matchExact)) || currentItem === item; const handleItemClick = () => { if (item.href) { history.push(item.href); } if (item.children && item.children.length > 0) { setIsOpen(true); setCurrentItem(item); } else { setIsOpen(false); } }; return (