From 68cb6390ca1f2e28dca0d7958f1af29a72da0919 Mon Sep 17 00:00:00 2001 From: Damola18 Date: Wed, 15 Jan 2025 14:33:14 +0100 Subject: [PATCH] Refactor SidebarItem to handle external links properly --- src/components/dashboard/sidebar-item.tsx | 79 ++++++++++++++--------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/src/components/dashboard/sidebar-item.tsx b/src/components/dashboard/sidebar-item.tsx index 27790cc9..0daf9963 100644 --- a/src/components/dashboard/sidebar-item.tsx +++ b/src/components/dashboard/sidebar-item.tsx @@ -4,6 +4,7 @@ import { Flex, FlexProps, Icon, LinkBox, Image } from '@chakra-ui/react' import { dataAttr } from '@chakra-ui/utils' import { usePathname } from 'next/navigation' import React from 'react' +import Link from 'next/link' import LinkOverlay from '../elements/LinkElements/LinkOverlay' import { useTranslations } from 'next-intl' @@ -20,41 +21,57 @@ export const SidebarItem = (props: SidebarItemProps) => { const pathname = usePathname() const isActiveRoute = pathname?.endsWith(item.route) + const isExternalLink = item.route.startsWith('http') + + const renderLinkContent = () => ( + + {typeof item.icon === 'string' ? ( + icon + ) : ( + + )} + {t(item.label)} + {isActiveRoute && ( + + )} + + ) return ( - - - {typeof item.icon === 'string' ? ( - icon - ) : ( - - )} - {t(item.label)} - {isActiveRoute && ( - - )} - - + {renderLinkContent()} + + ) : ( + + {renderLinkContent()} + + )} ) }