index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 { LanguagesSupported } from '@/i18n/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 { t } = useTranslation()
  32. const { userProfile, langeniusVersionInfo } = useAppContext()
  33. const { setShowAccountSettingModal } = useModalContext()
  34. const handleLogout = async () => {
  35. await logout({
  36. url: '/logout',
  37. params: {},
  38. })
  39. router.push('/signin')
  40. }
  41. return (
  42. <div className="">
  43. <Menu as="div" className="relative inline-block text-left">
  44. {
  45. ({ open }) => (
  46. <>
  47. <div>
  48. <Menu.Button
  49. className={`
  50. inline-flex items-center
  51. rounded-[20px] py-1 pr-2.5 pl-1 text-sm
  52. text-gray-700 hover:bg-gray-200
  53. mobile:px-1
  54. ${open && 'bg-gray-200'}
  55. `}
  56. >
  57. <Avatar name={userProfile.name} className='sm:mr-2 mr-0' size={32} />
  58. {!isMobile && <>
  59. {userProfile.name}
  60. <ChevronDown className="w-3 h-3 ml-1 text-gray-700" />
  61. </>}
  62. </Menu.Button>
  63. </div>
  64. <Transition
  65. as={Fragment}
  66. enter="transition ease-out duration-100"
  67. enterFrom="transform opacity-0 scale-95"
  68. enterTo="transform opacity-100 scale-100"
  69. leave="transition ease-in duration-75"
  70. leaveFrom="transform opacity-100 scale-100"
  71. leaveTo="transform opacity-0 scale-95"
  72. >
  73. <Menu.Items
  74. className="
  75. absolute right-0 mt-1.5 w-60 max-w-80
  76. divide-y divide-gray-100 origin-top-right rounded-lg bg-white
  77. shadow-lg
  78. "
  79. >
  80. <Menu.Item>
  81. <div className='flex flex-nowrap items-center px-4 py-[13px]'>
  82. <Avatar name={userProfile.name} size={36} className='mr-3' />
  83. <div className='grow'>
  84. <div className='leading-5 font-normal text-[14px] text-gray-800 break-all'>{userProfile.name}</div>
  85. <div className='leading-[18px] text-xs font-normal text-gray-500 break-all'>{userProfile.email}</div>
  86. </div>
  87. </div>
  88. </Menu.Item>
  89. <div className='px-1 py-1'>
  90. <div className='mt-2 px-3 text-xs font-medium text-gray-500'>{t('common.userProfile.workspace')}</div>
  91. <WorkplaceSelector />
  92. </div>
  93. <div className="px-1 py-1">
  94. <Menu.Item>
  95. <div className={itemClassName} onClick={() => setShowAccountSettingModal({ payload: 'account' })}>
  96. <div>{t('common.userProfile.settings')}</div>
  97. </div>
  98. </Menu.Item>
  99. <Menu.Item>
  100. <Link
  101. className={classNames(itemClassName, 'group justify-between')}
  102. href='https://github.com/langgenius/dify/discussions/categories/feedbacks'
  103. target='_blank' rel='noopener noreferrer'>
  104. <div>{t('common.userProfile.roadmapAndFeedback')}</div>
  105. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  106. </Link>
  107. </Menu.Item>
  108. <Menu.Item>
  109. <Link
  110. className={classNames(itemClassName, 'group justify-between')}
  111. href='https://discord.gg/5AEfbxcd9k'
  112. target='_blank' rel='noopener noreferrer'>
  113. <div>{t('common.userProfile.community')}</div>
  114. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  115. </Link>
  116. </Menu.Item>
  117. <Menu.Item>
  118. <Link
  119. className={classNames(itemClassName, 'group justify-between')}
  120. href={
  121. locale !== LanguagesSupported[1] ? 'https://docs.dify.ai/' : `https://docs.dify.ai/v/${locale.toLowerCase()}/`
  122. }
  123. target='_blank' rel='noopener noreferrer'>
  124. <div>{t('common.userProfile.helpCenter')}</div>
  125. <ArrowUpRight className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  126. </Link>
  127. </Menu.Item>
  128. {
  129. document?.body?.getAttribute('data-public-site-about') !== 'hide' && (
  130. <Menu.Item>
  131. <div className={classNames(itemClassName, 'justify-between')} onClick={() => setAboutVisible(true)}>
  132. <div>{t('common.userProfile.about')}</div>
  133. <div className='flex items-center'>
  134. <div className='mr-2 text-xs font-normal text-gray-500'>{langeniusVersionInfo.current_version}</div>
  135. <Indicator color={langeniusVersionInfo.current_version === langeniusVersionInfo.latest_version ? 'green' : 'orange'} />
  136. </div>
  137. </div>
  138. </Menu.Item>
  139. )
  140. }
  141. </div>
  142. <Menu.Item>
  143. <div className='p-1' onClick={() => handleLogout()}>
  144. <div
  145. className='flex items-center justify-between h-9 px-3 rounded-lg cursor-pointer group hover:bg-gray-50'
  146. >
  147. <div className='font-normal text-[14px] text-gray-700'>{t('common.userProfile.logout')}</div>
  148. <LogOut01 className='hidden w-[14px] h-[14px] text-gray-500 group-hover:flex' />
  149. </div>
  150. </div>
  151. </Menu.Item>
  152. </Menu.Items>
  153. </Transition>
  154. </>
  155. )
  156. }
  157. </Menu>
  158. {
  159. aboutVisible && <AccountAbout onCancel={() => setAboutVisible(false)} langeniusVersionInfo={langeniusVersionInfo} />
  160. }
  161. </div >
  162. )
  163. }