Commit 65c5eec6 authored by Max Alekseenko's avatar Max Alekseenko

disable menu item

parent f292564c
...@@ -28,6 +28,7 @@ export default function useNavItems(): ReturnType { ...@@ -28,6 +28,7 @@ export default function useNavItems(): ReturnType {
balancesQuery: rewardsBalancesQuery, balancesQuery: rewardsBalancesQuery,
dailyRewardQuery, dailyRewardQuery,
apiToken: rewardsApiToken, apiToken: rewardsApiToken,
isInitialized: isRewardsInitialized,
} = useRewardsContext(); } = useRewardsContext();
return React.useMemo(() => { return React.useMemo(() => {
...@@ -273,9 +274,10 @@ export default function useNavItems(): ReturnType { ...@@ -273,9 +274,10 @@ export default function useNavItems(): ReturnType {
config.features.rewards.isEnabled ? { config.features.rewards.isEnabled ? {
text: rewardsBalancesQuery.data?.total ? `${ rewardsBalancesQuery.data?.total } Merits` : 'Merits', text: rewardsBalancesQuery.data?.total ? `${ rewardsBalancesQuery.data?.total } Merits` : 'Merits',
nextRoute: { pathname: '/account/rewards' as const }, nextRoute: { pathname: '/account/rewards' as const },
onClick: rewardsApiToken ? undefined : openRewardsLoginModal, onClick: (isRewardsInitialized && !rewardsApiToken) ? openRewardsLoginModal : undefined,
icon: dailyRewardQuery.data?.available ? 'merits_with_dot' : 'merits', icon: dailyRewardQuery.data?.available ? 'merits_with_dot' : 'merits',
isActive: pathname === '/account/rewards', isActive: pathname === '/account/rewards',
isDisabled: !isRewardsInitialized,
} : null, } : null,
{ {
text: 'Watch list', text: 'Watch list',
...@@ -310,5 +312,5 @@ export default function useNavItems(): ReturnType { ...@@ -310,5 +312,5 @@ export default function useNavItems(): ReturnType {
].filter(Boolean); ].filter(Boolean);
return { mainNavItems, accountNavItems }; return { mainNavItems, accountNavItems };
}, [ pathname, openRewardsLoginModal, rewardsBalancesQuery, dailyRewardQuery, rewardsApiToken ]); }, [ pathname, openRewardsLoginModal, rewardsBalancesQuery, dailyRewardQuery, rewardsApiToken, isRewardsInitialized ]);
} }
...@@ -18,6 +18,7 @@ export type NavItemInternal = NavItemCommon & { ...@@ -18,6 +18,7 @@ export type NavItemInternal = NavItemCommon & {
nextRoute: Route; nextRoute: Route;
isActive?: boolean; isActive?: boolean;
onClick?: () => void; onClick?: () => void;
isDisabled?: boolean;
} }
export type NavItemExternal = { export type NavItemExternal = {
......
...@@ -42,10 +42,11 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState ...@@ -42,10 +42,11 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState
} }
const isHighlighted = checkRouteHighlight(item); const isHighlighted = checkRouteHighlight(item);
const isDisabled = isInternalLink && item.isDisabled;
const content = ( const content = (
<Link <Link
href={ href } href={ isDisabled ? undefined : href }
target={ isInternalLink ? '_self' : '_blank' } target={ isInternalLink ? '_self' : '_blank' }
{ ...styleProps.itemProps } { ...styleProps.itemProps }
w={{ base: '100%', lg: isExpanded ? '100%' : '60px', xl: isCollapsed ? '60px' : '100%' }} w={{ base: '100%', lg: isExpanded ? '100%' : '60px', xl: isCollapsed ? '60px' : '100%' }}
...@@ -58,7 +59,7 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState ...@@ -58,7 +59,7 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState
onClick={ isInternalLink && item.onClick ? item.onClick : onClick } onClick={ isInternalLink && item.onClick ? item.onClick : onClick }
_hover={{ _hover={{
[`& *:not(.${ LIGHTNING_LABEL_CLASS_NAME }, .${ LIGHTNING_LABEL_CLASS_NAME } *)`]: { [`& *:not(.${ LIGHTNING_LABEL_CLASS_NAME }, .${ LIGHTNING_LABEL_CLASS_NAME } *)`]: {
color: 'link_hovered', color: isDisabled ? 'inherit' : 'link_hovered',
}, },
}} }}
> >
...@@ -88,7 +89,7 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState ...@@ -88,7 +89,7 @@ const NavLink = ({ item, isCollapsed, px, className, onClick, disableActiveState
return ( return (
<Box as="li" listStyleType="none" w="100%" className={ className }> <Box as="li" listStyleType="none" w="100%" className={ className }>
{ isInternalLink && !item.onClick ? ( { isInternalLink && !item.onClick && !isDisabled ? (
<NextLink href={ item.nextRoute } passHref legacyBehavior> <NextLink href={ item.nextRoute } passHref legacyBehavior>
{ content } { content }
</NextLink> </NextLink>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment