HomeIcon.tsx48 lines · main
| 1 | import { LOCAL_STORAGE_KEYS } from 'common' |
| 2 | import Link from 'next/link' |
| 3 | import { useRouter } from 'next/router' |
| 4 | import { cn } from 'ui' |
| 5 | |
| 6 | import { useOrganizationsQuery } from '@/data/organizations/organizations-query' |
| 7 | import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' |
| 8 | import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage' |
| 9 | import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' |
| 10 | import { IS_PLATFORM } from '@/lib/constants' |
| 11 | import { useTrack } from '@/lib/telemetry/track' |
| 12 | |
| 13 | export const HomeIcon = ({ className }: { className?: string }) => { |
| 14 | const { data: selectedOrganization } = useSelectedOrganizationQuery() |
| 15 | const { data: organizations } = useOrganizationsQuery() |
| 16 | const track = useTrack() |
| 17 | |
| 18 | const largeLogo = useIsFeatureEnabled('branding:large_logo') |
| 19 | |
| 20 | const router = useRouter() |
| 21 | const [lastVisitedOrganization] = useLocalStorageQuery( |
| 22 | LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION, |
| 23 | '' |
| 24 | ) |
| 25 | |
| 26 | const getDefaultOrgRedirect = () => { |
| 27 | if (lastVisitedOrganization) return `/org/${lastVisitedOrganization}` |
| 28 | if (selectedOrganization?.slug) return `/org/${selectedOrganization.slug}` |
| 29 | if (organizations && organizations.length > 0) return `/org/${organizations[0].slug}` |
| 30 | return '/organizations' |
| 31 | } |
| 32 | |
| 33 | const href = IS_PLATFORM ? getDefaultOrgRedirect() : '/project/default' |
| 34 | |
| 35 | return ( |
| 36 | <Link |
| 37 | href={href} |
| 38 | onClick={() => track('header_home_logo_clicked')} |
| 39 | className={cn('items-center justify-center shrink-0 flex', className)} |
| 40 | > |
| 41 | <img |
| 42 | alt="Briven" |
| 43 | src={`${router.basePath}/img/briven-logo.svg`} |
| 44 | className={largeLogo ? 'h-[20px]' : 'h-[18px]'} |
| 45 | /> |
| 46 | </Link> |
| 47 | ) |
| 48 | } |