import React from 'react'; import Hook from '../../hook'; import { Button } from '@mui/material'; import { NoData } from '../../services'; type ShortcutMenu = Hook.RouteMenu & { label: string, path: string, module: string, } export interface ShortcutProps { routes: Hook.Routes, path: string, } export const Shortcut: React.FC = ({ routes, path }) => { const [theme] = Hook.useTheme(); const [language] = Hook.useLanguage(); const [, navigate] = Hook.useRouter(); const [shortcutMenu, setShortcutMenu] = React.useState(); React.useEffect(() => { if (routes && routes.children) { const getSideMenu = (paths: Hook.Route): ShortcutMenu => { if (paths && routes.labels && routes.labels[language]) { const splitPath = path.split('/').map(x => x.trim()).filter(x => x); const currentPath = `/${splitPath.join('/')}`; let route = paths; for (let i = 0; !!route && i < splitPath.length; i++) { const splitKey = `/${splitPath[i]}`; if (route.children) { route = route.children[splitKey]; } } if (route) { if (route.menu && routes.labels[language][currentPath]) { const label = routes.labels[language][currentPath]; const crumbroad: string[] = []; do { splitPath.pop(); const parentPath = `/${splitPath.join('/')}`; crumbroad.push(`${routes.labels[language][parentPath]}`); } while (splitPath.length > 1) return { ...route.menu, label, module: crumbroad.filter(x => x).join('/'), path: currentPath, } } } } return NoData; } setShortcutMenu( getSideMenu({ children: !!routes.children && routes.children['/'] ? routes.children['/'].children : routes.children, component: NoData }) ); } }, [routes, path, language]) const handleClick = (path: string) => () => { if (path) { navigate(path) } } return ( <> { shortcutMenu &&
} ); }