index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use client'
  2. import { useCallback, useEffect } from 'react'
  3. import Link from 'next/link'
  4. import { useBoolean } from 'ahooks'
  5. import { useSelectedLayoutSegment } from 'next/navigation'
  6. import { Bars3Icon } from '@heroicons/react/20/solid'
  7. import HeaderBillingBtn from '../billing/header-billing-btn'
  8. import AccountDropdown from './account-dropdown'
  9. import AppNav from './app-nav'
  10. import DatasetNav from './dataset-nav'
  11. import EnvNav from './env-nav'
  12. import ExploreNav from './explore-nav'
  13. import ToolsNav from './tools-nav'
  14. import GithubStar from './github-star'
  15. import { WorkspaceProvider } from '@/context/workspace-context'
  16. import { useAppContext } from '@/context/app-context'
  17. import LogoSite from '@/app/components/base/logo/logo-site'
  18. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  19. import { useProviderContext } from '@/context/provider-context'
  20. import { useModalContext } from '@/context/modal-context'
  21. const navClassName = `
  22. flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl
  23. font-medium text-sm
  24. cursor-pointer
  25. `
  26. const Header = () => {
  27. const { isCurrentWorkspaceEditor, isCurrentWorkspaceDatasetOperator } = useAppContext()
  28. const selectedSegment = useSelectedLayoutSegment()
  29. const media = useBreakpoints()
  30. const isMobile = media === MediaType.mobile
  31. const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false)
  32. const { enableBilling, plan } = useProviderContext()
  33. const { setShowPricingModal, setShowAccountSettingModal } = useModalContext()
  34. const isFreePlan = plan.type === 'sandbox'
  35. const handlePlanClick = useCallback(() => {
  36. if (isFreePlan)
  37. setShowPricingModal()
  38. else
  39. setShowAccountSettingModal({ payload: 'billing' })
  40. }, [isFreePlan, setShowAccountSettingModal, setShowPricingModal])
  41. useEffect(() => {
  42. hideNavMenu()
  43. // eslint-disable-next-line react-hooks/exhaustive-deps
  44. }, [selectedSegment])
  45. return (
  46. <div className='flex flex-1 items-center justify-between px-4'>
  47. <div className='flex items-center'>
  48. {isMobile && <div
  49. className='flex items-center justify-center h-8 w-8 cursor-pointer'
  50. onClick={toggle}
  51. >
  52. <Bars3Icon className="h-4 w-4 text-gray-500" />
  53. </div>}
  54. {!isMobile && <>
  55. <Link href="/apps" className='flex items-center mr-4'>
  56. <LogoSite className='object-contain' />
  57. </Link>
  58. <GithubStar />
  59. </>}
  60. </div>
  61. {isMobile && (
  62. <div className='flex'>
  63. <Link href="/apps" className='flex items-center mr-4'>
  64. <LogoSite />
  65. </Link>
  66. <GithubStar />
  67. </div>
  68. )}
  69. {!isMobile && (
  70. <div className='flex items-center'>
  71. {!isCurrentWorkspaceDatasetOperator && <ExploreNav className={navClassName} />}
  72. {!isCurrentWorkspaceDatasetOperator && <AppNav />}
  73. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatasetNav />}
  74. {!isCurrentWorkspaceDatasetOperator && <ToolsNav className={navClassName} />}
  75. </div>
  76. )}
  77. <div className='flex items-center flex-shrink-0'>
  78. <EnvNav />
  79. {enableBilling && (
  80. <div className='mr-3 select-none'>
  81. <HeaderBillingBtn onClick={handlePlanClick} />
  82. </div>
  83. )}
  84. <WorkspaceProvider>
  85. <AccountDropdown isMobile={isMobile} />
  86. </WorkspaceProvider>
  87. </div>
  88. {(isMobile && isShowNavMenu) && (
  89. <div className='w-full flex flex-col p-2 gap-y-1'>
  90. {!isCurrentWorkspaceDatasetOperator && <ExploreNav className={navClassName} />}
  91. {!isCurrentWorkspaceDatasetOperator && <AppNav />}
  92. {(isCurrentWorkspaceEditor || isCurrentWorkspaceDatasetOperator) && <DatasetNav />}
  93. {!isCurrentWorkspaceDatasetOperator && <ToolsNav className={navClassName} />}
  94. </div>
  95. )}
  96. </div>
  97. )
  98. }
  99. export default Header