import { DropdownMenu } from "@cloudflare/kumo/components/dropdown"; import { ListIcon } from "@phosphor-icons/react"; import { Link, useNavigate } from "@tanstack/react-router"; import { signOut } from "~/fns/auth"; import { resetAnalytics } from "~/lib/analytics"; import { useAction } from "~/hooks/use-action"; import { useEmailUnverified, useSupporter, useUnreadNotifications, useViewer } from "~/hooks/use-viewer"; import { ProBadge } from "~/components/billing/ProBadge"; import { Avatar } from "~/ui/Avatar"; import { Logo } from "~/ui/Logo"; import { buttonClass } from "~/ui/Button"; import { SearchForm } from "~/components/SearchForm"; import { Icon } from "~/ui/Icon"; import { cn } from "~/utils/cn"; const MEMBER_NAV = [{ to: "/explore", label: "Explore" }] as const; const VISITOR_NAV = [ { to: "/features", label: "Features" }, { to: "/pricing", label: "Pricing" }, { to: "/self-host", label: "Self-host" }, { to: "/explore", label: "Explore" }, ] as const; function UserMenu({ name, isAdmin }: { name: string; isAdmin: boolean }) { const navigate = useNavigate(); const supporter = useSupporter(); const logout = useAction(signOut); const items = [ { to: "/$owner", params: { owner: name }, label: "Your profile" }, { to: "/settings", params: {}, label: "Settings" }, { to: "/settings/billing", params: {}, label: "Billing" }, { to: "/settings/tokens", params: {}, label: "Access tokens" }, { to: "/settings/containers", params: {}, label: "Containers" }, { to: "/orgs/new", params: {}, label: "New organization" }, ...(isAdmin ? [{ to: "/admin", params: {}, label: "Site admin" } as const] : []), ]; async function handleSignOut() { await logout.run({}); resetAnalytics(); await navigate({ to: "/" }); } return ( } aria-label="Open user menu" > Signed in as {name} {items.map((item) => ( }> {item.label} {item.label === "Billing" && supporter ? : null} ))} Sign out ); } function NavMenu({ items }: { items: ReadonlyArray<{ to: string; label: string }> }) { return ( } aria-label="Open navigation" > {items.map((item) => ( }> {item.label} ))} ); } export function SiteHeader() { const viewer = useViewer(); const unverified = useEmailUnverified(); const unread = useUnreadNotifications(); const nav = viewer ? MEMBER_NAV : VISITOR_NAV; return (
{nav.length > 1 && (
)}
{viewer ? ( <> {!unverified && ( + New )} Notifications {unread > 0 && ( )} ) : ( <> Sign in Sign up )}
); }