'use client' import { useEffect, SyntheticEvent } from 'react' import { useRouter } from 'next/router' import { Menu } from '@headlessui/react' import { Link } from './link' import { UserManager } from '@app/managers' import { LOGGIN_ROUTES } from '@app/configs' import { useMutation } from '@apollo/react-hooks' import { LOGOUT } from '@app/mutations' import { NavItem } from './navigation/nav-item' import { useWasmContext } from '../providers' import { FilterManager } from '@app/managers/filters' import { MenuList } from './menu' type AuthMenuComponentProps = { authenticated?: boolean // user logged in settings?: boolean // display settings icon } const menuItemCss = 'w-full px-4 py-2 md:px-4 h-10 flex text-sm place-items-center place-content-start hover:no-underline hover:opacity-70 dark:bg-black' // auth menu on the right of the ui export function AuthMenu({ authenticated, settings }: AuthMenuComponentProps) { const router = useRouter() const [logoutMutation, { data, client }] = useMutation(LOGOUT) const { feed } = useWasmContext() useEffect(() => { if (data) { ;async () => { try { await client?.clearStore() } catch (e) { console.error(e) } } } }, [data, client]) // simple logout const logout = async (e: SyntheticEvent) => { e?.preventDefault() try { feed?.clear_data() await logoutMutation() UserManager.clearUser() FilterManager.clearFilters() } catch (e) { console.error(e) } await router.push('/') } if ( (!authenticated && LOGGIN_ROUTES.includes(router?.pathname)) || authenticated ) { return (
{router?.pathname !== '/profile' ? ( {() => ( Profile )} ) : null} {router?.pathname !== '/dashboard' ? ( {() => ( Dashboard )} ) : null} {router?.pathname !== '/payments' ? ( {() => ( Payments )} ) : null} {router?.pathname !== '/settings' ? ( {() => ( Settings )} ) : null}
{() => ( )}
) } // when not authed return login or register return ( <> ) }