-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from kv8gh/main
basic navbar
- Loading branch information
Showing
2 changed files
with
136 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,127 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
// import Link from "next/link"; | ||
import { signIn, signOut, useSession } from "next-auth/react"; | ||
|
||
export default function Navbar() { | ||
const { status } = useSession(); | ||
// export default function Navbar() { | ||
// const { status } = useSession(); | ||
// return ( | ||
// <div className="flex"> | ||
// <div className="m-3">Nav</div> | ||
// {status === "authenticated" ? ( | ||
// <button | ||
// onClick={() => signOut()} > | ||
// Sign Out | ||
// </button> | ||
// ) : ( | ||
// <button | ||
// onClick={() => signIn("google")} > | ||
// Sign In | ||
// </button> | ||
// )} | ||
// </div> | ||
// ); | ||
// } | ||
|
||
// import { useSession } from 'next-auth/react'; | ||
import Image from "next/image"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/navigation"; | ||
import logo from "@/public/assets/logos/FP LOGO.svg"; | ||
import { useEffect, useState } from "react"; | ||
import SignInBtn from "./SignInBtn"; | ||
// import LoginButton from './Landing Page/Loginbutton'; | ||
|
||
const Navbar = () => { | ||
const router = useRouter(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [dashboardLink, setDashboardLink] = useState("/"); | ||
const { data: session, status } = useSession(); | ||
|
||
const toggleMenu = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
useEffect(() => { | ||
if (router.isReady) { | ||
if (status === "unauthenticated") { | ||
router.push("/"); | ||
} else if (status === "authenticated") { | ||
getData(); | ||
} | ||
} | ||
}, [status, router]); | ||
|
||
const getData = () => { | ||
fetch(`${process.env.NEXT_PUBLIC_SERVER}/user/userDetails`, { | ||
content: "application/json", | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${session.accessTokenBackend}`, | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
}) | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const user = data.user; | ||
if (user.teamRole === "0") { | ||
setDashboardLink("/leaderDashboard"); | ||
} else { | ||
setDashboardLink("/memberDashboard"); | ||
} | ||
}) | ||
.catch((error) => {}); | ||
}; | ||
|
||
return ( | ||
<div className="flex"> | ||
<div className="m-3">Nav</div> | ||
{status === "authenticated" ? ( | ||
<button | ||
onClick={() => signOut()} > | ||
Sign Out | ||
</button> | ||
) : ( | ||
<button | ||
onClick={() => signIn("google")} > | ||
Sign In | ||
</button> | ||
)} | ||
</div> | ||
<nav className="top-0 flex text-white w-full justify-around h-[84px] py-4"> | ||
<div> | ||
<Image | ||
src={logo} | ||
alt="FP" | ||
className="h-full w-auto" | ||
onClick={() => { | ||
router.push("/"); | ||
}} | ||
/> | ||
</div> | ||
<div className="hidden gap-3 sm:gap-10 items-center font-medium md:flex"> | ||
<Link href="/">Home</Link> | ||
<Link href={dashboardLink}>Dashboard</Link> | ||
<SignInBtn /> | ||
{/* <LoginButton /> */} | ||
</div> | ||
<div className="flex flex-col justify-around md:hidden"> | ||
{/* Hamburger menu icon */} | ||
<div | ||
className="cursor-pointer text-white md:hidden" | ||
onClick={toggleMenu} | ||
> | ||
☰ | ||
</div> | ||
|
||
{/* Navbar links */} | ||
<div | ||
className={`md:flex flex-col z-10 bg-gray-800 bg-opacity-75 p-4 rounded-md top-[6vh] h-[20vh] ${ | ||
isOpen ? "absolute right-0" : "hidden" | ||
} `} | ||
> | ||
<ul className="flex flex-col justify-around items-center space-x-4 h-full"> | ||
<li> | ||
<Link href="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link href="/memberDashboard">Dashboard</Link> | ||
</li> | ||
<li> | ||
<SignInBtn /> | ||
{/* <LoginButton /> */} | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
); | ||
} | ||
}; | ||
|
||
export default Navbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
"use client"; | ||
|
||
import Image from "next/image"; | ||
import { signIn } from "next-auth/react"; | ||
import { signIn,signOut,useSession } from "next-auth/react"; | ||
|
||
export default function SignInBtn() { | ||
const { status } = useSession(); | ||
return ( | ||
<button | ||
onClick={() => signIn("google")} | ||
className="flex items-center gap-4 shadow-xl rounded-lg pl-3" | ||
> | ||
|
||
<span className="bg-blue-500 text-white px-4 py-3"> | ||
Sign in with Google | ||
</span> | ||
</button> | ||
); | ||
<div className="flex bg-blue-500 p-2 border border-black rounded-lg"> | ||
{status === "authenticated" ? ( | ||
<button | ||
onClick={() => signOut()} > | ||
Sign Out | ||
</button> | ||
) : ( | ||
<button | ||
onClick={() => signIn("google")} > | ||
Sign In | ||
</button> | ||
)} | ||
</div>) | ||
} |