diff --git a/client/src/app/Header.tsx b/client/src/app/Header.tsx index 5e966a4..2585619 100644 --- a/client/src/app/Header.tsx +++ b/client/src/app/Header.tsx @@ -15,10 +15,12 @@ import { NavbarBrand, NavbarContent, NavbarItem, + NavbarMenu, + NavbarMenuToggle, } from "@nextui-org/react"; import zustand from "@/Zustand"; import { SiteLink } from "./layout"; -import { useEffect } from "react"; +import React, { useEffect } from "react"; export default function Header({ sites }: { sites: SiteLink[] }) { const router = useRouter(); @@ -27,6 +29,33 @@ export default function Header({ sites }: { sites: SiteLink[] }) { const pathname = usePathname(); + const badgeSites: { + content: React.ReactNode; + onPress?: () => void; + color?: "primary" | "secondary" | "success" | "warning" | "danger"; + textValue?: string; + }[] = [ + { + content: ( + <> +

Signed in as

+

{user?.userName}

+ + ), + textValue: `Signed in as ${user?.userName}`, + }, + { + content: "Account", + onPress: () => router.push("/account"), + }, + { + content: Logout, + onPress: logout, + color: "danger", + textValue: "Logout", + }, + ]; + async function logout() { const result = await apiCall("GET", "logout"); @@ -57,13 +86,30 @@ export default function Header({ sites }: { sites: SiteLink[] }) { return (
- router.push("/")}> -

Golunteer

-
- + + + router.push("/")}> +

Golunteer

+
+
{user !== null ? ( <> - + + {sites.map((s) => + // if the site is no admin-site or the user is an admin, render it + !s.admin || user.admin ? ( + + {s.text} + + ) : null, + )} + + + {sites.map((s) => // if the site is no admin-site or the user is an admin, render it !s.admin || user.admin ? ( @@ -91,28 +137,16 @@ export default function Header({ sites }: { sites: SiteLink[] }) { - -

Signed in as

-

{user.userName}

-
- router.push("/account")} - > - Account - - - Log Out - + {badgeSites.map((site, ii) => ( + + {site.content} + + ))}