2023-08-15 13:35:47 +08:00
|
|
|
'use client'
|
2023-12-03 22:10:16 +08:00
|
|
|
import { useEffect, useRef, useState } from 'react'
|
2023-05-15 08:51:32 +08:00
|
|
|
import Link from 'next/link'
|
2023-12-03 22:10:16 +08:00
|
|
|
import { useBoolean, useClickAway } from 'ahooks'
|
2023-11-27 11:47:48 +08:00
|
|
|
import { useSelectedLayoutSegment } from 'next/navigation'
|
|
|
|
import { Bars3Icon } from '@heroicons/react/20/solid'
|
2023-12-03 22:10:16 +08:00
|
|
|
import HeaderBillingBtn from '../billing/header-billing-btn'
|
2023-05-15 08:51:32 +08:00
|
|
|
import AccountDropdown from './account-dropdown'
|
2023-06-27 18:02:01 +08:00
|
|
|
import AppNav from './app-nav'
|
|
|
|
import DatasetNav from './dataset-nav'
|
2023-07-18 16:57:14 +08:00
|
|
|
import EnvNav from './env-nav'
|
|
|
|
import ExploreNav from './explore-nav'
|
2024-01-23 19:31:56 +08:00
|
|
|
import ToolsNav from './tools-nav'
|
2023-07-18 16:57:14 +08:00
|
|
|
import GithubStar from './github-star'
|
2023-05-15 08:51:32 +08:00
|
|
|
import { WorkspaceProvider } from '@/context/workspace-context'
|
2023-08-15 13:35:47 +08:00
|
|
|
import { useAppContext } from '@/context/app-context'
|
2023-10-16 15:26:25 +08:00
|
|
|
import LogoSite from '@/app/components/base/logo/logo-site'
|
2023-12-03 22:10:16 +08:00
|
|
|
import PlanComp from '@/app/components/billing/plan'
|
2023-11-27 11:47:48 +08:00
|
|
|
import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
|
2023-12-03 22:10:16 +08:00
|
|
|
import { useProviderContext } from '@/context/provider-context'
|
2023-05-25 16:59:47 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
const navClassName = `
|
2024-01-04 14:51:26 +08:00
|
|
|
flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl
|
2023-06-27 18:02:01 +08:00
|
|
|
font-medium text-sm
|
2023-05-15 08:51:32 +08:00
|
|
|
cursor-pointer
|
|
|
|
`
|
2023-06-06 10:42:32 +08:00
|
|
|
|
2023-07-18 16:57:14 +08:00
|
|
|
const Header = () => {
|
2023-11-27 11:47:48 +08:00
|
|
|
const { isCurrentWorkspaceManager, langeniusVersionInfo } = useAppContext()
|
2023-12-03 22:10:16 +08:00
|
|
|
const [showUpgradePanel, setShowUpgradePanel] = useState(false)
|
|
|
|
const upgradeBtnRef = useRef<HTMLElement>(null)
|
|
|
|
useClickAway(() => {
|
|
|
|
setShowUpgradePanel(false)
|
|
|
|
}, upgradeBtnRef)
|
|
|
|
|
|
|
|
const selectedSegment = useSelectedLayoutSegment()
|
2023-11-27 11:47:48 +08:00
|
|
|
const media = useBreakpoints()
|
|
|
|
const isMobile = media === MediaType.mobile
|
|
|
|
const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false)
|
2023-12-03 22:10:16 +08:00
|
|
|
const { enableBilling } = useProviderContext()
|
2023-11-27 11:47:48 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
hideNavMenu()
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [selectedSegment])
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
2023-12-03 22:10:16 +08:00
|
|
|
<div className='flex flex-1 items-center justify-between px-4'>
|
|
|
|
<div className='flex items-center'>
|
|
|
|
{isMobile && <div
|
|
|
|
className='flex items-center justify-center h-8 w-8 cursor-pointer'
|
|
|
|
onClick={toggle}
|
|
|
|
>
|
|
|
|
<Bars3Icon className="h-4 w-4 text-gray-500" />
|
|
|
|
</div>}
|
|
|
|
{!isMobile && <>
|
|
|
|
<Link href="/apps" className='flex items-center mr-4'>
|
2024-02-27 19:16:22 +08:00
|
|
|
<LogoSite className='object-contain' />
|
2023-12-03 22:10:16 +08:00
|
|
|
</Link>
|
|
|
|
<GithubStar />
|
|
|
|
</>}
|
|
|
|
</div>
|
|
|
|
{isMobile && (
|
|
|
|
<div className='flex'>
|
|
|
|
<Link href="/apps" className='flex items-center mr-4'>
|
|
|
|
<LogoSite />
|
|
|
|
</Link>
|
|
|
|
<GithubStar />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!isMobile && (
|
2023-11-27 11:47:48 +08:00
|
|
|
<div className='flex items-center'>
|
2023-12-03 22:10:16 +08:00
|
|
|
<ExploreNav className={navClassName} />
|
|
|
|
<AppNav />
|
|
|
|
{isCurrentWorkspaceManager && <DatasetNav />}
|
2024-01-23 19:31:56 +08:00
|
|
|
<ToolsNav className={navClassName} />
|
2023-11-27 11:47:48 +08:00
|
|
|
</div>
|
2023-12-03 22:10:16 +08:00
|
|
|
)}
|
|
|
|
<div className='flex items-center flex-shrink-0'>
|
|
|
|
<EnvNav />
|
|
|
|
{enableBilling && (
|
|
|
|
<div className='mr-3 select-none'>
|
|
|
|
<HeaderBillingBtn onClick={() => setShowUpgradePanel(true)} />
|
|
|
|
{showUpgradePanel && (
|
|
|
|
<div
|
|
|
|
ref={upgradeBtnRef as any}
|
|
|
|
className='fixed z-10 top-12 right-1 w-[360px]'
|
|
|
|
>
|
|
|
|
<PlanComp loc='header' />
|
|
|
|
</div>
|
|
|
|
)}
|
2023-11-27 11:47:48 +08:00
|
|
|
</div>
|
|
|
|
)}
|
2023-12-03 22:10:16 +08:00
|
|
|
<WorkspaceProvider>
|
2024-01-23 19:31:56 +08:00
|
|
|
<AccountDropdown isMobile={isMobile} />
|
2023-12-03 22:10:16 +08:00
|
|
|
</WorkspaceProvider>
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
2023-11-27 11:47:48 +08:00
|
|
|
{(isMobile && isShowNavMenu) && (
|
|
|
|
<div className='w-full flex flex-col p-2 gap-y-1'>
|
|
|
|
<ExploreNav className={navClassName} />
|
|
|
|
<AppNav />
|
|
|
|
{isCurrentWorkspaceManager && <DatasetNav />}
|
2024-01-23 19:31:56 +08:00
|
|
|
<ToolsNav className={navClassName} />
|
2023-11-27 11:47:48 +08:00
|
|
|
</div>
|
|
|
|
)}
|
2023-12-03 22:10:16 +08:00
|
|
|
</div>
|
2023-05-15 08:51:32 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
export default Header
|