diff --git a/apps/dashboard/components/navigation/sidebar/app-sidebar/components/nav-items/nested-nav-item.tsx b/apps/dashboard/components/navigation/sidebar/app-sidebar/components/nav-items/nested-nav-item.tsx index 2f5044968c..b9b00d7fa1 100644 --- a/apps/dashboard/components/navigation/sidebar/app-sidebar/components/nav-items/nested-nav-item.tsx +++ b/apps/dashboard/components/navigation/sidebar/app-sidebar/components/nav-items/nested-nav-item.tsx @@ -11,13 +11,12 @@ import { Collapsible, CollapsibleContent } from "@radix-ui/react-collapsible"; import { CaretRight } from "@unkey/icons"; import { usePathname, useRouter } from "next/navigation"; import { useLayoutEffect, useState, useTransition } from "react"; +import slugify from "slugify"; import type { NavItem } from "../../../workspace-navigations"; import { NavLink } from "../nav-link"; import { AnimatedLoadingSpinner } from "./animated-loading-spinner"; import { getButtonStyles } from "./utils"; -const paths = ["/apis", "/ratelimits"]; - export const NestedNavItem = ({ item, onLoadMore, @@ -55,10 +54,15 @@ export const NestedNavItem = ({ setIsChildrenOpen(!!hasMatchingChild); - if (paths.includes(pathname) && pathname.startsWith(item.href)) { + const itemPath = `/${slugify(item.label, { + lower: true, + replacement: "-", + })}`; + + if (pathname.startsWith(itemPath)) { setIsOpen(true); } - }, [pathname, item.items, item.href, hasChildren]); + }, [pathname, item.items, item.label, hasChildren]); const handleMenuItemClick = (e: React.MouseEvent) => { // If the item has children, toggle the open state diff --git a/apps/dashboard/package.json b/apps/dashboard/package.json index feb08669eb..8230d59780 100644 --- a/apps/dashboard/package.json +++ b/apps/dashboard/package.json @@ -86,6 +86,7 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.51.3", "recharts": "^2.12.7", + "slugify": "^1.6.6", "sonner": "^1.5.0", "stripe": "^14.23.0", "superjson": "^2.2.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9107ff8045..535f4b54d7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -366,6 +366,9 @@ importers: recharts: specifier: ^2.12.7 version: 2.12.7(react-dom@18.3.1)(react@18.3.1) + slugify: + specifier: ^1.6.6 + version: 1.6.6 sonner: specifier: ^1.5.0 version: 1.5.0(react-dom@18.3.1)(react@18.3.1) @@ -20029,6 +20032,11 @@ packages: is-fullwidth-code-point: 4.0.0 dev: false + /slugify@1.6.6: + resolution: {integrity: sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==} + engines: {node: '>=8.0.0'} + dev: false + /smart-buffer@4.2.0: resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==} engines: {node: '>= 6.0.0', npm: '>= 3.0.0'}