Filter navigation items based on user role in DashboardLayout component

This commit is contained in:
Swapnil Bendal
2025-01-17 18:29:10 +05:30
parent 9f93993938
commit 5e86a72700

View File

@@ -1,6 +1,5 @@
import React, { useContext, useEffect, useState } from "react";
import { CgProfile } from "react-icons/cg";
import { useDispatch } from "react-redux";
import logoMiniDark from "../assets/favicon.png";
import logoMini from "../assets/logo-min.png";
import logoDark from "../assets/logo.png";
@@ -29,6 +28,7 @@ import {
import Cookies from "js-cookie"; // Import the Cookies library
import { GrManual } from "react-icons/gr";
import { HiOutlineChartSquareBar } from "react-icons/hi";
import { HiOutlineBanknotes } from "react-icons/hi2";
import { LuContact } from "react-icons/lu";
import { MdNotificationsNone, MdOutlineAddChart } from "react-icons/md";
import {
@@ -54,6 +54,7 @@ import {
useNavigate,
} from "react-router-dom";
import HeaderMain from "../Components/HeaderMain";
import { isMaker } from "../Constants/Constants";
import GlobalStateContext from "../Contexts/GlobalStateContext";
import CreateRequest from "../Pages/Fawateer/CreateRequest";
import ApproveHistory from "../Pages/FawateerChecker/ApproveHistory/ApproveHistoryChecker";
@@ -65,7 +66,6 @@ import { nav } from "../Routes/Nav";
import { RouteLink } from "../Routes/Routes";
import { useProfileQuery } from "../Services/io.service";
import { useLogoutMutation } from "../Services/token.serivce";
import { HiOutlineBanknotes } from "react-icons/hi2";
const DashboardLayout = ({ isOnline }) => {
const navigate = useNavigate();
@@ -426,7 +426,17 @@ const DashboardLayout = ({ isOnline }) => {
return <SplashScreen />;
}
const filteredNav = nav.map((item) => {
const _filteredNav = isMaker()
? nav.filter(
(item) =>
item.title !== "REVERSAL TRANSACTION" &&
item.path !== "/bank-deposit-request" &&
item.path !== "/reversal-fawateer-deposit" &&
item.path !== "/account-deletion-request"
)
: nav;
const filteredNav = _filteredNav.map((item) => {
if (item.submenu) {
return {
...item,
@@ -436,6 +446,9 @@ const DashboardLayout = ({ isOnline }) => {
),
};
}
// if (item.title === "REVERSAL TRANSACTION" && item.type === "title") {
// }
return item;
});
@@ -738,7 +751,7 @@ const DashboardLayout = ({ isOnline }) => {
to={path}
>
{Icon && <Icon className="web-text-large ms-2" />}
<Text
<Text
as={"span"}
display={
isDrawerOpen || openDrawerClick ? "flex" : "none"