diff --git a/ui/snippets/profileMenu/ProfileMenuContent.tsx b/ui/snippets/profileMenu/ProfileMenuContent.tsx index b56d3a0676..b254b8bf14 100644 --- a/ui/snippets/profileMenu/ProfileMenuContent.tsx +++ b/ui/snippets/profileMenu/ProfileMenuContent.tsx @@ -8,31 +8,37 @@ import useNavItems from 'lib/hooks/useNavItems'; import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps'; import NavLink from 'ui/snippets/navigation/NavLink'; -type Props = UserInfo; +type Props = { + data?: UserInfo; +}; -const ProfileMenuContent = ({ name, nickname, email }: Props) => { +const ProfileMenuContent = ({ data }: Props) => { const { accountNavItems, profileItem } = useNavItems(); const primaryTextColor = useColorModeValue('blackAlpha.800', 'whiteAlpha.800'); return ( - - Signed in as { name || nickname } - - - { email } - + { (data?.name || data?.nickname) && ( + + Signed in as { data.name || data.nickname } + + ) } + { data?.email && ( + + { data.email } + + ) } diff --git a/ui/snippets/profileMenu/ProfileMenuDesktop.tsx b/ui/snippets/profileMenu/ProfileMenuDesktop.tsx index 395335677e..b3d4724092 100644 --- a/ui/snippets/profileMenu/ProfileMenuDesktop.tsx +++ b/ui/snippets/profileMenu/ProfileMenuDesktop.tsx @@ -1,6 +1,5 @@ import type { ButtonProps } from '@chakra-ui/react'; import { Popover, PopoverContent, PopoverBody, PopoverTrigger, Button } from '@chakra-ui/react'; -import { route } from 'nextjs-routes'; import React from 'react'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; @@ -9,25 +8,25 @@ import UserAvatar from 'ui/shared/UserAvatar'; import ProfileMenuContent from 'ui/snippets/profileMenu/ProfileMenuContent'; const ProfileMenuDesktop = () => { - const { data, error } = useFetchProfileInfo(); + const { data, error, isLoading } = useFetchProfileInfo(); const loginUrl = useLoginUrl(); + const [ hasMenu, setHasMenu ] = React.useState(false); - const buttonProps: Partial = (() => { - if (error?.status === 403) { - return { - as: 'a', - href: route({ pathname: '/auth/profile' }), - }; + React.useEffect(() => { + if (!isLoading) { + setHasMenu(Boolean(data) || error?.status === 403); } + }, [ data, error?.status, isLoading ]); - if (!data) { - return { - as: 'a', - href: loginUrl, - }; + const buttonProps: Partial = (() => { + if (hasMenu) { + return {}; } - return {}; + return { + as: 'a', + href: loginUrl, + }; })(); return ( @@ -43,10 +42,10 @@ const ProfileMenuDesktop = () => { - { data && ( + { hasMenu && ( - + ) } diff --git a/ui/snippets/profileMenu/ProfileMenuMobile.tsx b/ui/snippets/profileMenu/ProfileMenuMobile.tsx index 6cd55c5f2c..15eb3bb3bf 100644 --- a/ui/snippets/profileMenu/ProfileMenuMobile.tsx +++ b/ui/snippets/profileMenu/ProfileMenuMobile.tsx @@ -1,6 +1,5 @@ import { Box, Drawer, DrawerOverlay, DrawerContent, DrawerBody, useDisclosure, Button } from '@chakra-ui/react'; import type { ButtonProps } from '@chakra-ui/react'; -import { route } from 'nextjs-routes'; import React from 'react'; import useFetchProfileInfo from 'lib/hooks/useFetchProfileInfo'; @@ -11,30 +10,30 @@ import ProfileMenuContent from 'ui/snippets/profileMenu/ProfileMenuContent'; const ProfileMenuMobile = () => { const { isOpen, onOpen, onClose } = useDisclosure(); - const { data, error } = useFetchProfileInfo(); + const { data, error, isLoading } = useFetchProfileInfo(); const loginUrl = useLoginUrl(); + const [ hasMenu, setHasMenu ] = React.useState(false); - const buttonProps: Partial = (() => { - if (error?.status === 403) { - return { - as: 'a', - href: route({ pathname: '/auth/profile' }), - }; + React.useEffect(() => { + if (!isLoading) { + setHasMenu(Boolean(data) || error?.status === 403); } + }, [ data, error?.status, isLoading ]); - if (!data) { - return { - as: 'a', - href: loginUrl, - }; + const buttonProps: Partial = (() => { + if (hasMenu) { + return {}; } - return {}; + return { + as: 'a', + href: loginUrl, + }; })(); return ( <> - + - { data && ( + { hasMenu && ( { - +