committing summative
This commit is contained in:
1 parent
73ac8e85be
commit
95b138f29e
44 files changed
+5319
-755
No files matched your search
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import {Links} from "./navbarData";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useSession, signOut } from "next-auth/react";
|
||||
|
||||
export default function NavBar( { enforceAdmin } : { enforceAdmin: boolean; } ) {
|
||||
const pathname = usePathname();
|
||||
const { data: session} = useSession();
|
||||
const visibleLinks = Links.filter( // check each link
|
||||
(link) => (link.url !== "/dashboard" || session?.user) && (link.url !== "/users" || !enforceAdmin)
|
||||
// keep link if its not dashboard or if theres a session (logged in) (only keep dashboard if logged in)
|
||||
// and keep link if its not users or if enforceadmin is false
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="navbar bg-base-100 shadow-sm">
|
||||
<div className="navbar-start">
|
||||
<div className="dropdown">
|
||||
<div tabIndex={0} role="button" className="btn btn-ghost lg:hidden">
|
||||
<svg aria-label="Menu" xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4 6h16M4 12h8m-8 6h16" /> </svg>
|
||||
</div>
|
||||
<ul
|
||||
tabIndex={-1}
|
||||
className="menu menu-sm dropdown-content bg-base-100 rounded-box z-1 mt-3 w-52 p-2 shadow">
|
||||
{visibleLinks.map((link) => ( // below highlights the active link
|
||||
<li className={pathname === link.url ? "menu-active" : ""} key={link.id}>
|
||||
<Link href={link.url}>{link.text}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<a className="btn btn-ghost text-xl">Secure CMS</a>
|
||||
</div>
|
||||
<div className="navbar-center hidden lg:flex">
|
||||
<ul className="menu menu-horizontal px-1">
|
||||
{visibleLinks.map((link) => (
|
||||
<li className={pathname === link.url ? "menu-active" : ""} key={link.id}>
|
||||
<Link href={link.url}>{link.text}</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
<div className="navbar-end gap-2">
|
||||
{session?.user ? (
|
||||
<>
|
||||
<span>{session.user.name || session.user.email || "Account"}</span>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => signOut({ redirectTo: "/login" })}>
|
||||
Logout
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Link href="/login" className="btn btn-ghost">
|
||||
Login
|
||||
</Link>
|
||||
<Link href="/register" className="btn btn-primary">
|
||||
Sign Up
|
||||
</Link>
|
||||
</>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user