2025-03-19 19:20:18 +00:00
|
|
|
"use client";
|
2025-05-04 16:04:44 +01:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import Link from "next/link";
|
2025-05-12 13:52:47 +01:00
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
2025-05-04 16:04:44 +01:00
|
|
|
import { Dispatch, SetStateAction, useMemo, useState } from "react";
|
|
|
|
|
import { FaRegUserCircle } from "react-icons/fa";
|
2025-03-17 13:21:02 +00:00
|
|
|
|
2025-05-04 16:04:44 +01:00
|
|
|
import { Currency } from "@appTypes/StoreModel";
|
|
|
|
|
import AuthModal from "@components/AuthModal";
|
|
|
|
|
import { useStoreActions, useStoreState } from "@hooks/store";
|
2025-03-10 13:27:47 +00:00
|
|
|
|
2025-04-28 19:03:29 +01:00
|
|
|
export default function Navbar({}: // currencySelector,
|
|
|
|
|
{
|
|
|
|
|
// currencySelector?: { selectedCurrency: string; setSelectedCurrency: Dispatch<SetStateAction<"GBP" | "USD" | "EUR">> };
|
|
|
|
|
}) {
|
|
|
|
|
const pathname = usePathname();
|
2025-05-09 10:30:12 +01:00
|
|
|
const user = useStoreState((state) => state.user);
|
2025-04-28 19:03:29 +01:00
|
|
|
const selectedCurrency = useStoreState((state) => state.currency.selectedCurrency);
|
|
|
|
|
const setSelectedCurrency = useStoreActions((actions) => actions.currency.setSelectedCurrency);
|
2025-05-12 13:52:47 +01:00
|
|
|
const navOptions = useMemo(() => ["Earthquakes", "Observatories", "Shop"], []);
|
2025-04-28 19:03:29 +01:00
|
|
|
// const navOptions = useMemo(() => ["Earthquakes"], []);
|
|
|
|
|
const aboutDropdown = ["Contact Us", "Our Mission", "The Team"];
|
|
|
|
|
// { label: "Our Mission", path: "/our-mission" },
|
|
|
|
|
// { label: "The Team", path: "/the-team" },
|
|
|
|
|
// { label: "Contact Us", path: "/contact-us" }]
|
2025-05-09 10:30:12 +01:00
|
|
|
const router = useRouter();
|
2025-04-28 19:03:29 +01:00
|
|
|
|
|
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
const currencies = useStoreState((state) => state.currency.currencies);
|
|
|
|
|
const currencyTickers = useStoreState((state) => state.currency.tickers);
|
|
|
|
|
|
2025-04-29 16:52:03 +01:00
|
|
|
function NavbarButton({ name, href, dropdownItems }: { name: string; href: string; dropdownItems?: string[] }) {
|
|
|
|
|
const isActive = dropdownItems
|
|
|
|
|
? dropdownItems.some((item) => pathname === `/${item.toLowerCase().replace(" ", "-")}`)
|
|
|
|
|
: pathname === href;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button className="flex items-center justify-center px-2 py-4 relative group">
|
|
|
|
|
{dropdownItems ? (
|
|
|
|
|
<span
|
|
|
|
|
className={`px-4 py-1.5 rounded-md transition-colors ${isActive ? "bg-neutral-200" : "group-hover:bg-neutral-200"}`}
|
|
|
|
|
>
|
|
|
|
|
{name}
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<Link
|
|
|
|
|
href={href}
|
|
|
|
|
className={`px-4 py-1.5 rounded-md transition-colors ${isActive ? "bg-neutral-200" : "hover:bg-neutral-200"}`}
|
|
|
|
|
>
|
|
|
|
|
{name}
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
{dropdownItems && (
|
|
|
|
|
<div className="absolute hidden group-hover:block top-full left-1/2 -translate-x-1/2 w-40 bg-white border border-neutral-300 rounded-lg overflow-hidden shadow-lg z-40">
|
|
|
|
|
<ul>
|
|
|
|
|
{dropdownItems.map((item) => {
|
|
|
|
|
const itemHref = `/${item.toLowerCase().replace(" ", "-")}`;
|
|
|
|
|
const isDropdownActive = pathname === itemHref;
|
|
|
|
|
return (
|
|
|
|
|
<li key={item}>
|
|
|
|
|
<Link
|
|
|
|
|
href={itemHref}
|
|
|
|
|
className={`block px-4 py-2 hover:bg-neutral-100 ${isDropdownActive ? "bg-neutral-100" : ""}`}
|
|
|
|
|
>
|
|
|
|
|
{item}
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-09 10:30:12 +01:00
|
|
|
function ManagementNavbarButton({ name, href, dropdownItems }: { name: string; href: string; dropdownItems?: string[] }) {
|
|
|
|
|
const isActive = dropdownItems
|
|
|
|
|
? dropdownItems.some((item) => pathname === `/${item.toLowerCase().replace(" ", "-")}`)
|
|
|
|
|
: pathname === href;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button className="flex items-center justify-center px-2 py-4 relative group">
|
|
|
|
|
<Link
|
|
|
|
|
href={href}
|
|
|
|
|
className={`px-3 py-1 border-2 rounded-md transition-colors ${
|
|
|
|
|
isActive ? "border-neutral-500" : " hover:border-neutral-500"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{name}
|
|
|
|
|
</Link>
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 19:03:29 +01:00
|
|
|
return (
|
|
|
|
|
<div className="flex sticky top-0 w-full h-14 z-40 font-medium bg-white border border-b-neutral-200">
|
|
|
|
|
<div className="my-1 flex aspect-square ml-3 mr-3">
|
|
|
|
|
<Link href="/" className="rounded-full">
|
|
|
|
|
<Image height={50} width={50} alt="Logo" className="border border-neutral-300 rounded-full" src="/logo.png" />
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
{navOptions.map((name) => (
|
|
|
|
|
<NavbarButton name={name} href={`/${name.toLowerCase()}`} key={name} />
|
|
|
|
|
))}
|
|
|
|
|
<NavbarButton name="About Us" href="/about" dropdownItems={aboutDropdown} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-grow" />
|
|
|
|
|
{pathname.includes("shop") && (
|
|
|
|
|
<button className="flex items-center justify-center mr-3 py-4 relative group">
|
|
|
|
|
<span className={`px-4 py-1.5 rounded-md transition-colors`}>{selectedCurrency}</span>
|
|
|
|
|
|
|
|
|
|
<div className="absolute hidden group-hover:block top-full left-1/2 -translate-x-1/2 w-24 bg-white border border-neutral-300 rounded-lg overflow-hidden shadow-lg z-40">
|
|
|
|
|
<ul>
|
|
|
|
|
{currencies.map((item) => {
|
|
|
|
|
let ticker = currencyTickers[item];
|
|
|
|
|
return (
|
|
|
|
|
<li key={item} onClick={() => setSelectedCurrency(item)}>
|
2025-04-29 16:52:03 +01:00
|
|
|
<div className={`block px-2 py-2 hover:bg-neutral-100 text-md`}>
|
|
|
|
|
{item} ({ticker})
|
|
|
|
|
</div>
|
2025-04-28 19:03:29 +01:00
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2025-05-09 10:30:12 +01:00
|
|
|
{user && (user.role === "SCIENTIST" || user.role === "ADMIN") && (
|
|
|
|
|
<div className="flex h-full mr-5">
|
|
|
|
|
<ManagementNavbarButton name="Warehouse" href="/warehouse"></ManagementNavbarButton>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-05-24 20:09:10 +01:00
|
|
|
{user && (user.role === "SCIENTIST" || user.role === "ADMIN") && (
|
|
|
|
|
<div className="flex h-full mr-5">
|
|
|
|
|
<ManagementNavbarButton name="Scientist Management" href="/management"></ManagementNavbarButton>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-05-12 13:52:47 +01:00
|
|
|
{user && user.role === "ADMIN" && (
|
|
|
|
|
<div className="flex h-full mr-5">
|
|
|
|
|
<ManagementNavbarButton name="Admin" href="/administrator"></ManagementNavbarButton>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-05-09 10:30:12 +01:00
|
|
|
<button className="my-auto mr-4" onClick={() => (user ? router.push("/profile") : setIsModalOpen(true))}>
|
2025-04-28 19:03:29 +01:00
|
|
|
<FaRegUserCircle size={22} />
|
|
|
|
|
</button>
|
|
|
|
|
<AuthModal isOpen={isModalOpen} onClose={() => setIsModalOpen(false)} />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-03-10 13:27:47 +00:00
|
|
|
}
|