feat: hide statistics, work time, expenses and finances from regular users

This commit is contained in:
2024-12-09 20:17:32 +04:00
parent 2ee0ef3a52
commit d5598a10b8
4 changed files with 66 additions and 24 deletions

View File

@@ -15,10 +15,11 @@ import {
IconSun,
} from "@tabler/icons-react";
import classes from "./Navbar.module.css";
import { useAppDispatch } from "../../redux/store.ts";
import { RootState, useAppDispatch } from "../../redux/store.ts";
import { logout } from "../../features/authSlice.ts";
import { useNavigate, useRouterState } from "@tanstack/react-router";
import { setHideNavbar } from "../../features/uiSlice.ts";
import { useSelector } from "react-redux";
interface NavbarLinkProps {
icon: typeof IconHome2;
@@ -93,17 +94,21 @@ const mockdata = [
label: "Маркетплейсы",
href: "/marketplaces",
},
];
const adminMockdata = [
{
icon: IconChartDots,
label: "Статистика",
href: "/statistics",
}
},
];
export function Navbar() {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const router = useRouterState();
const role = useSelector((state: RootState) => state.auth.role);
const { colorScheme, toggleColorScheme } = useMantineColorScheme({
keepTransitions: true,
});
@@ -114,9 +119,17 @@ export function Navbar() {
const onNavlinkClick = (props: NavbarLinkProps) => {
navigate({ to: props.href });
};
const links = mockdata.map((link, index) => (
<NavbarLink
const getLinksData = () => {
let data = mockdata;
if (role === "admin") {
data = data.concat(adminMockdata);
}
return data;
}
const links = getLinksData().map((link, index) => (
<NavbarLink
{...link}
index={index}
key={link.label}