index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { Fragment, useState } from 'react'
  4. import { useRouter } from 'next/navigation'
  5. import { useContext } from 'use-context-selector'
  6. import classNames from 'classnames'
  7. import Link from 'next/link'
  8. import { Menu, Transition } from '@headlessui/react'
  9. import Indicator from '../indicator'
  10. import AccountAbout from '../account-about'
  11. import WorkplaceSelector from './workplace-selector'
  12. import I18n from '@/context/i18n'
  13. import Avatar from '@/app/components/base/avatar'
  14. import { logout } from '@/service/common'
  15. import { useAppContext } from '@/context/app-context'
  16. import { ArrowUpRight, ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
  17. import { LogOut01 } from '@/app/components/base/icons/src/vender/line/general'
  18. import { useModalContext } from '@/context/modal-context'
  19. import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language'
  20. export type IAppSelecotr = {
  21. isMobile: boolean
  22. }
  23. export default function AppSelector({ isMobile }: IAppSelecotr) {
  24. const itemClassName = `
  25. flex items-center w-full h-9 px-3 text-gray-700 text-[14px]
  26. rounded-lg font-normal hover:bg-gray-50 cursor-pointer
  27. `
  28. const router = useRouter()
  29. const [aboutVisible, setAboutVisible] = useState(false)
  30. const { locale } = useContext(I18n)
  31. const language = getModelRuntimeSupported(locale)
  32. const { t } = useTranslation()
  33. const { userProfile, langeniusVersionInfo } = useAppContext()
  34. const { setShowAccountSettingModal } = useModalContext()
  35. const handleLogout = async () => {
  36. await logout({
  37. url: '/logout',
  38. params: {},
  39. })
  40. router.push('/signin')
  41. }
  42. return (
  43. <div className="">
  44. <Menu as="div" className="relative inline-block text-left">
  45. {
  46. ({ open }) => (
  47. <>
  48. <div>
  49. <Menu.Button
  50. className={`
  51. inline-flex items-center
  52. rounded-[20px] py-1 pr-2.5 pl-1 text-sm
  53. text-gray-700 hover:bg-gray-200
  54. mobile:px-1
  55. ${open && 'bg-gray-200'}
  56. `}
  57. >
  58. <Avatar name={userProfile.name} className='sm:mr-2 mr-0' size={32} />
  59. {!isMobile && <>
  60. {userProfile.name}
  61. <ChevronDown className="w-3 h-3 ml-1 text-gray-700"/>
  62. </>}
  63. </Menu.Button>
  64. </div>
  65. <Transition
  66. as={Fragment}
  67. enter="transition ease-out duration-100"
  68. enterFrom="transform opacity-0 scale-95"
  69. enterTo="transform opacity-100 scale-100"
  70. leave="transition ease-in duration-75"
  71. leaveFrom="transform opacity-100 scale-100"
  72. leaveTo="transform opacity-0 scale-95"
  73. >
  74. <Menu.Items
  75. className="
  76. absolute right-0 mt-1.5 w-60 max-w-80
  77. divide-y divide-gray-100 origin-top-right rounded-lg bg-white
  78. shadow-lg
  79. "
  80. >
  81. <Menu.Item>
  82. <div className='flex flex-nowrap items-center px-4 py-[13px]'>
  83. <Avatar name={userProfile.name} size={36} className='mr-3' />
  84. <div className='grow'>
  85. <div className='leading-5 font-normal text-[14px] text-gray-800 break-all'>{userProfile.name}</div>
  86. <div className='leading-[18px] text-xs font-normal text-gray-500 break-all'>{userProfile.email}</div>
  87. </div>
  88. </div>
  89. </Menu.Item>
  90. <div className='px-1 py-1'>
  91. <div className='mt-2 px-3 text-xs font-medium text-gray-500'>{t('common.userProfile.workspace')}</div>
  92. <WorkplaceSelector />
  93. </div>
  94. <div className="px-1 py-1">
  95. <Menu.Item>
  96. <div className={itemClassName} onClick={() => setShowAccountSettingModal({ payload: 'account' })}>
  97. <div>{t('common.userProfile.settings')}</div>
  98. </div>
  99. </Menu.Item>
  100. <Menu.Item>
  101. <Link
  102. className={classNames(itemClassName, 'group justify-between')}
  103. href='https://feedback.dify.ai/'
  104. target='_blank'>
  105. <div>{t('common.userProfile.roadmapAndFeedback')}</div>
  106. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  107. </Link>
  108. </Menu.Item>
  109. <Menu.Item>
  110. <Link
  111. className={classNames(itemClassName, 'group justify-between')}
  112. href='https://discord.gg/5AEfbxcd9k'
  113. target='_blank'>
  114. <div>{t('common.userProfile.community')}</div>
  115. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  116. </Link>
  117. </Menu.Item>
  118. <Menu.Item>
  119. <Link
  120. className={classNames(itemClassName, 'group justify-between')}
  121. href={
  122. language !== LanguagesSupportedUnderscore[1] ? 'https://docs.dify.ai/' : `https://docs.dify.ai/v/${locale.toLowerCase()}/`
  123. }
  124. target='_blank'>
  125. <div>{t('common.userProfile.helpCenter')}</div>
  126. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  127. </Link>
  128. </Menu.Item>
  129. {
  130. document?.body?.getAttribute('data-public-site-about') !== 'hide' && (
  131. <Menu.Item>
  132. <div className={classNames(itemClassName, 'justify-between')} onClick={() => setAboutVisible(true)}>
  133. <div>{t('common.userProfile.about')}</div>
  134. <div className='flex items-center'>
  135. <div className='mr-2 text-xs font-normal text-gray-500'>{langeniusVersionInfo.current_version}</div>
  136. <Indicator color={langeniusVersionInfo.current_version === langeniusVersionInfo.latest_version ? 'green' : 'orange'} />
  137. </div>
  138. </div>
  139. </Menu.Item>
  140. )
  141. }
  142. </div>
  143. <Menu.Item>
  144. <div className='p-1' onClick={() => handleLogout()}>
  145. <div
  146. className='flex items-center justify-between h-9 px-3 rounded-lg cursor-pointer group hover:bg-gray-50'
  147. >
  148. <div className='font-normal text-[14px] text-gray-700'>{t('common.userProfile.logout')}</div>
  149. <LogOut01 className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  150. </div>
  151. </div>
  152. </Menu.Item>
  153. </Menu.Items>
  154. </Transition>
  155. </>
  156. )
  157. }
  158. </Menu>
  159. {
  160. aboutVisible && <AccountAbout onCancel={() => setAboutVisible(false)} langeniusVersionInfo={langeniusVersionInfo} />
  161. }
  162. </div >
  163. )
  164. }