Mantis MUI React
v3.2.0
v3.2.0
  • Documentation
  • Pre-requisites
  • Quick Start
  • Folder Structure
  • State Management
  • Internationalization
  • Authentication
    • Switch to Auth0
    • Switch to Firebase
    • Switch to AWS Cognito
  • Axios API Calls
  • Routing
  • Project Configuration
  • Color Presets
  • Theme/Style Configuration
  • How to
    • Login as First Page
    • Remove menu render from Backend
    • Remove Authentication
      • Vite
      • NextJS
  • Figma
  • Integration
    • Seed
    • To Existing Project
    • Comparison
  • Components
    • Avatar
    • BreadCrumb
    • Button
    • Dot
    • Main Card
    • Progress
    • SnackBar
    • Tooltip
    • Transitions
  • Dependencies
    • Vite js
    • Next js
  • Roadmap
  • Support
  • Changelog
  • Mantis Eco System
  • FAQ
Powered by GitBook
On this page
  1. How to

Remove menu render from Backend

PreviousLogin as First PageNextRemove Authentication

Last updated 8 months ago

In the Able Pro React admin, a few dashboard menus (i.e. Default, Analytics, Components) load from our mock API (). If you want to remove it from your admin panel, follow the steps below and remove/edit the suggested line of code.

  1. Delete menu-items file dashboard.tsx [../src/menu-items/dashboard.tsx]

  2. Open file ../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.tsx and edit the below line of code.

Form:

import { Fragment, useLayoutEffect, useState } from 'react';
...
import menuItem from 'menu-items';
import { useGetMenu, useGetMenuMaster } from 'api/menu';

To:

../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.tsx
import { Fragment, useState } from 'react';
...
import menuItems from 'menu-items';
import { useGetMenuMaster } from 'api/menu';
  1. Open file ../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.tsx and remove the below line of code.

import { MenuFromAPI } from 'menu-items/dashboard';

function isFound(arr: any, str: string) {
  return arr.items.some((element: any) => {
	if (element.id === str) {
	  return true;
	}
	return false;
  });
}
	
export default function Navigation() {
	...		
	const { menuLoading } = useGetMenu();		
	...		
	const [menuItems, setMenuItems] = useState<{ items: NavItemType[] }>({ items: [] });

	let dashboardMenu = MenuFromAPI();
	useLayoutEffect(() => {
		if (menuLoading && !isFound(menuItem, 'group-dashboard-loading')) {
		  menuItem.items.splice(0, 0, dashboardMenu);
		  setMenuItems({ items: [...menuItem.items] });
		} else if (!menuLoading && dashboardMenu?.id !== undefined && !isFound(menuItem, 'group-dashboard')) {
		  menuItem.items.splice(0, 1, dashboardMenu);
		  setMenuItems({ items: [...menuItem.items] });
		} else {
		  setMenuItems({ items: [...menuItem.items] });
		}
	// eslint-disable-next-line
	}, [menuLoading]);
}
  1. Open file src\api\menu.ts and edit the below line of code.

Form:

src\api\menu.ts
import { MenuProps, NavItemType } from 'types/menu';

To:

src\api\menu.ts
import { MenuProps } from 'types/menu';
  1. Open the file src\api\menu.ts and remove the code below.

src\api\menu.ts
import { fetcher } from 'utils/axios';
	
export const endpoints = {
  ...
  dashboard: '/dashboard' // server URL
};
	
export function useGetMenu() {
  const { data, isLoading, error, isValidating } = useSWR(endpoints.key + endpoints.dashboard, fetcher, {
	revalidateIfStale: false,
	revalidateOnFocus: false,
	revalidateOnReconnect: false
  });

  const memoizedValue = useMemo(
	() => ({
	  menu: data?.dashboard as NavItemType,
	  menuLoading: isLoading,
	  menuError: error,
	  menuValidating: isValidating,
	  menuEmpty: !isLoading && !data?.length
	}),
	[data, error, isLoading, isValidating]
  );

  return memoizedValue;
}
  1. Delete menu-items file dashboard.jsx [../src/menu-items/dashboard.jsx]

  2. Open file ../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.jsx and edit the below line of code.

../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.jsx
import { useState } from 'react';
...
import menuItems from 'menu-items';
import { useGetMenuMaster } from 'api/menu'; // Removed useGetMenu
  1. Open file ../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.jsx and remove the below line of code.

../src/layout/Dashboard/Drawer/DrawerContent/Navigation/index.jsx
import { MenuFromAPI } from 'menu-items/dashboard';
	
export default function Navigation() {
	...		
	const { menuLoading } = useGetMenu();		
	...		
        const [menuItems, setMenuItems] = useState({ items: [] })

	let dashboardMenu = MenuFromAPI();
	
        useLayoutEffect(() => {
            const isFound = menuItem.items.some((element) => {
              if (element.id === 'group-dashboard') {
                return true;
              }
              return false;
            });
        
            if (menuLoading) {
              menuItem.items.splice(0, 0, dashboardMenu);
              setMenuItems({ items: [...menuItem.items] });
            } else if (!menuLoading && dashboardMenu?.id !== undefined && !isFound) {
              menuItem.items.splice(0, 1, dashboardMenu);
              setMenuItems({ items: [...menuItem.items] });
            } else {
              setMenuItems({ items: [...menuItem.items] });
            }
            // eslint-disable-next-line
  }, [menuLoading]);
}
  1. Open the file src\api\menu.js and remove the code below.

src\api\menu.js
import { fetcher } from 'utils/axios';
	
export const endpoints = {
  ...
  dashboard: '/dashboard' // server URL
};
	
export function useGetMenu() {
  const { data, isLoading, error, isValidating } = useSWR(endpoints.key + endpoints.dashboard, fetcher, {
    revalidateIfStale: false,
    revalidateOnFocus: false,
    revalidateOnReconnect: false
  });

  const memoizedValue = useMemo(() => {
    let updatedMenu = data?.dashboard;

    if (updatedMenu && Array.isArray(updatedMenu.children) && updatedMenu.children.length > 0) {
      updatedMenu = {
        ...updatedMenu,
        children: updatedMenu.children.map((group) => {
          if (Array.isArray(group.children)) {
            return {
              ...group,
              children: [...group.children, staticMenuItem]
            };
          }
          return group;
        })
      };
    }

    return {
      menu: updatedMenu,
      menuLoading: isLoading,
      menuError: error,
      menuValidating: isValidating,
      menuEmpty: !isLoading && !data?.length
    };
  }, [data, error, isLoading, isValidating]);

  return memoizedValue;
}
GitHub repository