From 2ab22821164f287932c2177c928355719ee45b34 Mon Sep 17 00:00:00 2001 From: "Arslan, Erdem" Date: Wed, 24 Jan 2024 22:12:00 +0100 Subject: [PATCH 1/3] implement dynamic routing within the sidebar --- pkgs/ui/src/components/sidebar/index.tsx | 47 +++++++++--------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/pkgs/ui/src/components/sidebar/index.tsx b/pkgs/ui/src/components/sidebar/index.tsx index 55bb214..341b183 100644 --- a/pkgs/ui/src/components/sidebar/index.tsx +++ b/pkgs/ui/src/components/sidebar/index.tsx @@ -9,10 +9,11 @@ import { Tooltip, useMediaQuery, } from "@mui/material"; +import {useGetAllEntities} from "@/api/entities/entities"; import Image from "next/image"; -import React, { ReactNode } from "react"; +import React, {ReactNode} from "react"; -import { tw } from "@/utils/tailwind"; +import {tw} from "@/utils/tailwind"; import Collapse from "@mui/material/Collapse"; import Link from "next/link"; import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; @@ -33,32 +34,7 @@ type MenuEntry = { subMenuEntries?: MenuEntry[]; }; -export const menuEntityEntries: MenuEntry[] = [ - { - icon: , - label: "C1", - to: "/client/C1", - disabled: false, - }, - { - icon: , - label: "C2", - to: "/client/C2", - disabled: false, - }, - { - icon: , - label: "C3", - to: "/client/C3", - disabled: false, - }, - { - icon: , - label: "C4", - to: "/client/C4", - disabled: false, - }, -]; +export let menuEntityEntries: MenuEntry[] = []; export const menuEntries: MenuEntry[] = [ { @@ -96,6 +72,7 @@ interface SidebarProps { } export function Sidebar(props: SidebarProps) { + const { data: entityData } = useGetAllEntities(); const { show, onClose } = props; const [activeMenuItem, setActiveMenuItem] = React.useState( typeof window !== "undefined" ? window.location.pathname : "", @@ -113,12 +90,22 @@ export function Sidebar(props: SidebarProps) { }; React.useEffect(() => { + if (entityData) { + menuEntityEntries=Array.isArray(entityData.data) + ? entityData.data.map((entity, index) => ({ + icon: , + label: entity.name, + to: `/client/${entity.name}`, + disabled: false, + })) + : []; + } if (isSmallerScreen) { setCollapseMenuOpen(false); } else { setCollapseMenuOpen(true); } - }, [isSmallerScreen]); + }, [isSmallerScreen, entityData]); return (