../src/layout/MainLayout/MenuList/index.tsx
Copy import { Fragment , useLayoutEffect , useState } from 'react' ;
...
import menuItem from 'menu-items' ;
import { useGetMenu , useGetMenuMaster } from 'api/menu' ;
../src/layout/MainLayout/MenuList/index.tsx
Copy import { Fragment , useState } from 'react' ;
...
import menuItems from 'menu-items' ;
import { useGetMenuMaster } from 'api/menu' ;
../src/layout/MainLayout/MenuList/index.tsx
Copy import { Menu } from 'menu-items/widget'
const MenuList = () => {
...
const { menuLoading } = useGetMenu ();
...
const [ menuItems , setMenuItems ] = useState <{ items : NavItemType [] }>({ items : [] });
let widgetMenu = Menu ();
useLayoutEffect (() => {
const isFound = menuItem . items .some ((element) => {
if ( element .id === 'group-widget' ) {
return true ;
}
return false ;
});
if (menuLoading) {
menuItem . items .splice ( 1 , 0 , widgetMenu);
setMenuItems ({ items : [ ... menuItem .items] });
} else if ( ! menuLoading && widgetMenu ?.id !== undefined && ! isFound) {
menuItem . items .splice ( 1 , 1 , widgetMenu);
setMenuItems ({ items : [ ... menuItem .items] });
} else {
setMenuItems ({ items : [ ... menuItem .items] });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
} , [menuLoading]);
}
Copy import { MenuProps } from 'types/menu' ;
import { NavItemType } from 'types' ;
Copy import { MenuProps } from 'types/menu' ;
Copy import { fetcher } from 'utils/axios' ;
export const endpoints = {
...
widget: '/widget' // server URL
};
export function useGetMenu () {
const { data , isLoading , error , isValidating } = useSWR ( endpoints .key + endpoints .widget , fetcher , {
revalidateIfStale : false ,
revalidateOnFocus : false ,
revalidateOnReconnect : false
});
const memoizedValue = useMemo (
() => ({
menu : data ?.widgetas NavItemType ,
menuLoading : isLoading ,
menuError : error ,
menuValidating : isValidating ,
menuEmpty : ! isLoading && ! data ?. length
}) ,
[data , error , isLoading , isValidating]
);
return memoizedValue;
}