Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show profile menu if email is not confirmed #934

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions ui/snippets/profileMenu/ProfileMenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box>
<Text
fontSize="sm"
fontWeight={ 500 }
color={ primaryTextColor }
{ ...getDefaultTransitionProps() }
>
Signed in as { name || nickname }
</Text>
<Text
fontSize="sm"
mb={ 1 }
fontWeight={ 500 }
color="gray.500"
{ ...getDefaultTransitionProps() }
>
{ email }
</Text>
{ (data?.name || data?.nickname) && (
<Text
fontSize="sm"
fontWeight={ 500 }
color={ primaryTextColor }
{ ...getDefaultTransitionProps() }
>
Signed in as { data.name || data.nickname }
</Text>
) }
{ data?.email && (
<Text
fontSize="sm"
mb={ 1 }
fontWeight={ 500 }
color="gray.500"
{ ...getDefaultTransitionProps() }
>
{ data.email }
</Text>
) }
<NavLink item={ profileItem } isActive={ undefined } px="0px" isCollapsed={ false }/>
<Box as="nav" mt={ 2 } pt={ 2 } borderTopColor="divider" borderTopWidth="1px" { ...getDefaultTransitionProps() }>
<VStack as="ul" spacing="0" alignItems="flex-start" overflow="hidden">
Expand Down
31 changes: 15 additions & 16 deletions ui/snippets/profileMenu/ProfileMenuDesktop.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ButtonProps> = (() => {
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<ButtonProps> = (() => {
if (hasMenu) {
return {};
}

return {};
return {
as: 'a',
href: loginUrl,
};
})();

return (
Expand All @@ -43,10 +42,10 @@ const ProfileMenuDesktop = () => {
<UserAvatar size={ 50 }/>
</Button>
</PopoverTrigger>
{ data && (
{ hasMenu && (
<PopoverContent w="212px">
<PopoverBody padding="24px 16px 16px 16px">
<ProfileMenuContent { ...data }/>
<ProfileMenuContent data={ data }/>
</PopoverBody>
</PopoverContent>
) }
Expand Down
33 changes: 16 additions & 17 deletions ui/snippets/profileMenu/ProfileMenuMobile.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<ButtonProps> = (() => {
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<ButtonProps> = (() => {
if (hasMenu) {
return {};
}

return {};
return {
as: 'a',
href: loginUrl,
};
})();

return (
<>
<Box padding={ 2 } onClick={ data ? onOpen : undefined }>
<Box padding={ 2 } onClick={ hasMenu ? onOpen : undefined }>
<Button
variant="unstyled"
height="auto"
Expand All @@ -43,7 +42,7 @@ const ProfileMenuMobile = () => {
<UserAvatar size={ 24 }/>
</Button>
</Box>
{ data && (
{ hasMenu && (
<Drawer
isOpen={ isOpen }
placement="right"
Expand All @@ -53,7 +52,7 @@ const ProfileMenuMobile = () => {
<DrawerOverlay/>
<DrawerContent maxWidth="260px">
<DrawerBody p={ 6 }>
<ProfileMenuContent { ...data }/>
<ProfileMenuContent data={ data }/>
</DrawerBody>
</DrawerContent>
</Drawer>
Expand Down