diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx index 3098a60..9737747 100644 --- a/src/app/dashboard/layout.tsx +++ b/src/app/dashboard/layout.tsx @@ -6,10 +6,13 @@ import React, { useEffect, useState } from "react"; import type { User } from "@/types"; import { getAccessToken, getUser } from "@/lib/actions"; import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { cn } from "@/lib/utils"; export default function DashboardLayout({ children }: { children: React.ReactNode }) { const [user, setUser] = useState(); const [isAdmin, setIsAdmin] = useState(user?.role === "ADMIN"); + const [active, setActive] = useState<"dashboard" | "bookings" | "settings">("dashboard"); useEffect(() => { const fetchUser = async () => { @@ -27,6 +30,19 @@ export default function DashboardLayout({ children }: { children: React.ReactNod useEffect(() => { setIsAdmin(user?.role === "ADMIN"); }, [user]); + + const pathname = usePathname(); + + useEffect(() => { + // Derive the active state based on the current pathname + if (pathname.includes("/dashboard/bookings")) { + setActive("bookings"); + } else if (pathname.includes("/dashboard/settings")) { + setActive("settings"); + } else { + setActive("dashboard"); + } + }, [pathname]); return (