pollo/src/app/_components/Header.tsx

74 lines
1.7 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-07-11 17:22:54 -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-08-12 17:12:42 -06:00
const { isLoaded, 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 (
<Link className="btn btn-secondary btn-outline mx-2" href="/dashboard">
Dashboard
</Link>
);
2023-08-12 17:12:42 -06:00
} else if (!isSignedIn) {
return (
2023-08-12 17:12:42 -06:00
<button
className="btn btn-secondary"
onClick={() => void router.push("/sign-in")}
>
Sign In
</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-08-12 17:12:42 -06:00
{!isLoaded ? (
2023-06-19 16:39:05 -06:00
<div className="flex items-center justify-center">
2023-06-19 23:46:12 -06:00
<span className="loading loading-dots loading-lg"></span>
2023-06-19 16:39:05 -06:00
</div>
) : (
navigationMenu()
2023-07-25 12:40:00 -06:00
)}
2023-08-12 17:12:42 -06:00
<UserButton afterSignOutUrl="/" />
2023-04-20 04:20:00 -06:00
</nav>
);
};
export default Navbar;