"use client"; import React, { useEffect } from "react"; import Link from "next/link"; import { useParams, usePathname, useRouter } from "next/navigation"; import { cn } from "@/lib/utils"; import { buttonVariants } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; interface SidebarNavProps extends React.HTMLAttributes { items: { href: string; title: string; icon?: React.ReactNode; }[]; disabled?: boolean; } export function SidebarNav({ className, items, disabled = false, ...props }: SidebarNavProps) { const pathname = usePathname(); const params = useParams(); const orgId = params.orgId as string; const niceId = params.niceId as string; const resourceId = params.resourceId as string; const userId = params.userId as string; const [selectedValue, setSelectedValue] = React.useState(getSelectedValue()); useEffect(() => { setSelectedValue(getSelectedValue()); }, [usePathname()]); const router = useRouter(); const handleSelectChange = (value: string) => { if (!disabled) { router.push(value); } }; function getSelectedValue() { const item = items.find((item) => hydrateHref(item.href) === pathname); return hydrateHref(item?.href || ""); } function hydrateHref(val: string): string { return val .replace("{orgId}", orgId) .replace("{niceId}", niceId) .replace("{resourceId}", resourceId) .replace("{userId}", userId); } return (
); }