import React from "react"; import { Box, Button, HStack, IconButton, Menu, MenuButton, MenuList, MenuItem, useDisclosure, useToast, } from "@chakra-ui/react"; import { HamburgerIcon } from "@chakra-ui/icons"; import { Link, useLocation } from "react-router-dom"; import { ChevronLeftIcon } from "@chakra-ui/icons"; import Image from "next/image"; import useCurrentUser, { useAuthModeFeatureFlag, useLogout, } from "./components/useCurrentUser"; import HomeLinkIcon from "./images/home-link-icon.png"; import { useAuth0 } from "@auth0/auth0-react"; function GlobalHeader() { return ( ); } function HomeLink(props) { const { pathname } = useLocation(); const isHomePage = pathname === "/"; return ( Dress to Impress ); } function UserNavBarSection() { const { isLoading, isLoggedIn, id, username } = useCurrentUser(); if (isLoading) { return null; } if (isLoggedIn) { return ( {username && ( Hi, {username}! )} {id && ( Lists )} Outfits Modeling ); } else { return ( Modeling ); } } function LoginButton() { const authMode = useAuthModeFeatureFlag(); const { loginWithRedirect } = useAuth0(); const { isOpen, onOpen, onClose } = useDisclosure(); const onClick = () => { if (authMode === "auth0") { loginWithRedirect(); } else if (authMode === "db") { onOpen(); } else { throw new Error(`unexpected auth mode: ${JSON.stringify(authMode)}`); } }; return ( <> Log in {authMode === "db" && ( )} ); } // I don't wanna load all these Chakra components as part of the bundle for // every single page. Split it out! const LoginModal = React.lazy(() => import("./components/LoginModal")); function LogoutButton() { const toast = useToast(); const [logout, { loading, error }] = useLogout(); React.useEffect(() => { if (error != null) { console.error(error); toast({ title: "Oops, there was an error logging you out.", description: "Reload the page and try again? Sorry about that!", status: "warning", duration: null, isClosable: true, }); } }, [error, toast]); return ( logout({ returnTo: window.location.origin })} // NOTE: The `isLoading` prop will only be relevant in the desktop case, // where this renders as a NavButton. In the mobile case, the menu // doesn't have a loading UI, and it closes when you click the // button anyway. Not ideal, but fine for a simple quick action! isLoading={loading} > Log out ); } const NavLinkTypeContext = React.createContext("button"); /** * Renders the given children as a dropdown menu or as a list * of buttons, depending on the screen size. * * It actually renders both, and shows/hides them by media query! */ function NavLinksList({ children }) { return ( <> } /> {children} {children} ); } function NavLinkItem(props) { const navLinkType = React.useContext(NavLinkTypeContext); if (navLinkType === "button") { return ; } else if (navLinkType === "menu") { return ; } else { throw new Error(`unexpected navLinkType: ${JSON.stringify(navLinkType)}`); } } const NavButton = React.forwardRef(({ icon, ...props }, ref) => { const Component = icon ? IconButton : Button; // Opacity is in a separate Box, to avoid overriding the built-in Button // hover/focus states. return ( ); }); export default GlobalHeader;