'use client'; import { CloseButton, Popover, PopoverButton, PopoverPanel, Transition } from '@headlessui/react'; import { ArrowRightIcon } from '@heroicons/react/16/solid'; import { Button } from 'components/ui'; import useAuth from 'hooks/use-auth'; import { Menu } from 'lib/shopify/types'; import Link from 'next/link'; import { Fragment } from 'react'; import { useFormState, useFormStatus } from 'react-dom'; import { doLogin, doLogout } from './actions'; import OpenProfile from './open-profile'; type ProfilePopoverProps = { menu: Menu[]; }; function SignInButton({ message }: { message: string | null }) { const { pending } = useFormStatus(); return ( <> {message &&
{message}
} ); } const LogoutButton = () => { const { pending } = useFormStatus(); return ( ); }; const ProfilePopover = ({ menu }: ProfilePopoverProps) => { const [message, action] = useFormState(doLogin, null); const [, logoutAction] = useFormState(doLogout, null); const { isAuthenticated, loading } = useAuth(); return (
My Account {!isAuthenticated && !loading && (
)} {menu.length ? (
    {isAuthenticated && (
  • My Orders
  • )} {menu.map((menuItem) => (
  • {menuItem.title}
  • ))}
) : null} {isAuthenticated && !loading && (
)}
); }; export default ProfilePopover;