Skip to content
Snippets Groups Projects
nav.tsx 3.09 KiB
Newer Older
import { Icons, IconsType } from "@/components/icons";
import { buttonVariants } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { SidebarNavItem } from "@/types";
Yusuf Akgül's avatar
Yusuf Akgül committed
import { signIn, signOut, useSession } from "next-auth/react";
import Link from "next/link";
import { usePathname } from "next/navigation";
Yusuf Akgül's avatar
Yusuf Akgül committed
import { GameUnityLogo } from "./logo";
import { ModeToggle } from "./mode-toggle";

interface DashboardNavProps {
    items: SidebarNavItem[]
}

export default function DashboardNav({ items }: DashboardNavProps) {
    const path = usePathname()
Caner's avatar
Caner committed
    const { data: session } = useSession();
Yusuf Akgül's avatar
Yusuf Akgül committed

Yusuf Akgül's avatar
Yusuf Akgül committed
    const isLoaded = true
    const user = "test"

    return (
        <nav className="grid items-start gap-2">
            <div className="flex items-center">
                <Link href="/" className={cn("rounded-full p-3 hover:bg-accent")}>
Yusuf Akgül's avatar
Yusuf Akgül committed
                    <GameUnityLogo className="h-8 w-8" />
Caner's avatar
Caner committed
            {session?.user && isLoaded && user ?
                (items.map((item, index) => {
                    const Icon = Icons[item.icon as keyof IconsType || "arrowRight"];
                    if (item.title === "My Profile") {
Yusuf Akgül's avatar
Yusuf Akgül committed
                        item.href = `/${user}`
                    }
                    return (
                        item.href && (
                            <Link key={index} href={item.disabled ? "/" : item.href} className={index == 6 ? "mt-10" : ""}>
                                <span
                                    className={cn(
                                        "group flex items-center rounded-md px-3 py-2 font-medium hover:bg-accent hover:text-accent-foreground",
                                        path === item.href ? "bg-accent" : "transparent",
                                        item.disabled && "cursor-not-allowed opacity-80"
                                    )}
                                >
                                    <Icon className="mr-2 h-4 w-4" />
                                    <span>{item.title}</span>
                                </span>
                            </Link>
                        )
                    )
                }))
                :
                <div className="space-x-2 space-y-2 justify-center text-center">
                    <Link href="/login" className={cn(buttonVariants({ size: "lg" }))}>Log In</Link>
                    <Link href="/signup" className={cn(buttonVariants({ size: "lg", variant: "outline" }))}>Sign Up</Link>
                    <p>
Yusuf Akgül's avatar
Yusuf Akgül committed
                        Unlock endless possibilities - sign up or log in to unleash the full potential of our website.
Caner's avatar
Caner committed
            {session?.user &&
Yusuf Akgül's avatar
Yusuf Akgül committed
                <>
                    <p className="text-sky-600"> {session?.user.name}</p>
                    <button className=" text-red-500" onClick={() => signOut()}>
                        Sign Out
                    </button>
                </>
Caner's avatar
Caner committed
            }
Yusuf Akgül's avatar
Yusuf Akgül committed
            <ModeToggle />