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

interface DashboardNavProps {
    items: SidebarNavItem[]
}

export default function DashboardNav({ items }: DashboardNavProps) {
    const path = usePathname()
Caner's avatar
Caner committed
    const { data: session } = useSession();
Caner's avatar
Caner 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")}>
                    <Icons.logo className="h-7 w-7 dark:hidden" />
                    <Icons.logoWhite className="h-7 w-7 hidden dark:block" />
                </Link>
            </div>
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 &&
            <>
            <p className="text-sky-600"> {session?.user.name}</p>
            <button className=" text-red-500" onClick={() => signOut()}>
                Sign Out
            </button>
            </>
            }
        <ModeToggle />