import { SegmentedControl, Tooltip } from "@mantine/core"; import { IconKeyOff, IconSettings, IconUser } from "@tabler/icons-react"; import { TbDatabase, TbFingerprint, TbHierarchy2, TbMenu2, TbPhoto, TbSelector, TbUser, TbX, } from "react-icons/tb"; import { useAuth, useBkndWindowContext } from "ui/client"; import { useBknd } from "ui/client/bknd"; import { useTheme } from "ui/client/use-theme"; import { Button } from "ui/components/buttons/Button"; import { IconButton } from "ui/components/buttons/IconButton"; import { Logo } from "ui/components/display/Logo"; import { Dropdown, type DropdownItem } from "ui/components/overlay/Dropdown"; import { Link } from "ui/components/wouter/Link"; import { useEvent } from "ui/hooks/use-event"; import { useNavigate } from "ui/lib/routes"; import { useLocation } from "wouter"; import { NavLink } from "./AppShell"; import { autoFormatString } from "core/utils"; import { appShellStore } from "ui/store"; export function HeaderNavigation() { const [location, navigate] = useLocation(); const items: { label: string; href: string; Icon: any; exact?: boolean; tooltip?: string; disabled?: boolean; }[] = [ /*{ label: "Base", href: "#", exact: true, Icon: TbLayoutDashboard, disabled: true, tooltip: "Coming soon" },*/ { label: "Data", href: "/data", Icon: TbDatabase }, { label: "Auth", href: "/auth", Icon: TbFingerprint }, { label: "Media", href: "/media", Icon: TbPhoto }, { label: "Flows", href: "/flows", Icon: TbHierarchy2 }, ]; const activeItem = items.find((item) => item.exact ? location === item.href : location.startsWith(item.href), ); const handleItemClick = useEvent((item) => { navigate(item.href); }); const renderDropdownItem = (item, { key, onClick }) => (
{item.label}
); return ( <> ); } function SidebarToggler() { const toggle = appShellStore((store) => store.toggleSidebar); const open = appShellStore((store) => store.sidebarOpen); return ; } export function Header({ hasSidebar = true }) { const { app } = useBknd(); const { theme } = useTheme(); const { logo_return_path = "/" } = app.options; return ( ); } function UserMenu() { const { config, options } = useBknd(); const auth = useAuth(); const [navigate] = useNavigate(); const { logout_route } = useBkndWindowContext(); async function handleLogout() { await auth.logout(); // @todo: grab from somewhere constant navigate(logout_route, { reload: true }); } async function handleLogin() { navigate("/auth/login"); } const items: DropdownItem[] = [ { label: "Settings", onClick: () => navigate("/settings"), icon: IconSettings }, ]; if (config.auth.enabled) { if (!auth.user) { items.push({ label: "Login", onClick: handleLogin, icon: IconUser }); } else { items.push({ label: `Logout ${auth.user.email}`, onClick: handleLogout, icon: IconKeyOff, }); } } if (!options.theme) { items.push(() => ); } return ( <> {auth.user ? ( ) : (