pollo/app/_components/Header.tsx

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-08-27 23:57:17 -06:00
"use client";
2023-08-12 17:12:42 -06:00
import { UserButton, useUser } from "@clerk/nextjs";
2023-04-20 04:20:00 -06:00
import Image from "next/image";
2023-07-11 17:22:54 -06:00
import Link from "next/link";
2023-08-27 23:57:17 -06:00
import { useRouter, usePathname } from "next/navigation";
2023-09-24 23:49:24 -06:00
import { env } from "env.mjs";
2023-04-20 04:20:00 -06:00
interface NavbarProps {
title: string;
}
2023-08-08 22:36:43 -06:00
const Navbar = ({ title }: NavbarProps) => {
2023-09-01 23:32:24 -06:00
const { isSignedIn } = useUser();
const router = useRouter();
2023-08-27 23:57:17 -06:00
const pathname = usePathname();
const navigationMenu = () => {
2023-08-27 23:57:17 -06:00
if (pathname !== "/dashboard" && isSignedIn) {
return (
2023-09-01 20:38:27 -06:00
<Link className="btn btn-primary btn-outline mx-2" href="/dashboard">
2023-09-24 23:49:24 -06:00
Demo Dashboard
</Link>
);
2023-08-12 17:12:42 -06:00
} else if (!isSignedIn) {
return (
2023-08-12 17:12:42 -06:00
<button
2023-09-01 20:38:27 -06:00
className="btn btn-primary"
2023-08-12 17:12:42 -06:00
onClick={() => void router.push("/sign-in")}
>
2023-09-24 23:49:24 -06:00
Sign In to Demo
</button>
);
}
};
2023-04-20 04:20:00 -06:00
return (
<nav className="navbar bg-base-100 h-12">
2023-04-20 04:20:00 -06:00
<div className="flex-1">
<Link
about="Back to home."
href="/"
className="btn btn-ghost normal-case text-xl"
>
<Image
className="md:mr-2"
2023-04-20 04:20:00 -06:00
src="/logo.webp"
alt="Nav Logo"
2023-07-25 12:40:00 -06:00
width={32}
height={32}
2023-04-20 04:20:00 -06:00
priority
/>
<span className="hidden md:inline-flex">
2023-07-25 12:40:00 -06:00
{title}
{env.NEXT_PUBLIC_APP_ENV === "development" && " >> Staging"}
</span>
2023-04-20 04:20:00 -06:00
</Link>
</div>
2023-09-01 23:32:24 -06:00
{navigationMenu()}
2023-09-01 23:37:51 -06:00
<UserButton afterSignOutUrl="/" userProfileMode="modal" />
2023-04-20 04:20:00 -06:00
</nav>
);
};
export default Navbar;