index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { Fragment, useState } from 'react'
  4. import { useRouter } from 'next/navigation'
  5. import {
  6. RiAccountCircleLine,
  7. RiArrowRightUpLine,
  8. // RiBookOpenLine,
  9. // RiGithubLine,
  10. RiGraduationCapFill,
  11. // RiInformation2Line,
  12. RiLogoutBoxRLine,
  13. // RiMap2Line,
  14. RiSettings3Line,
  15. // RiStarLine,
  16. RiTShirt2Line,
  17. } from '@remixicon/react'
  18. import Link from 'next/link'
  19. import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'
  20. // import Indicator from '../indicator'
  21. import AccountAbout from '../account-about'
  22. // import GithubStar from '../github-star'
  23. // import Support from './support'
  24. import Compliance from './compliance'
  25. import PremiumBadge from '@/app/components/base/premium-badge'
  26. import Avatar from '@/app/components/base/avatar'
  27. import ThemeSwitcher from '@/app/components/base/theme-switcher'
  28. import { logout } from '@/service/common'
  29. import { useAppContext } from '@/context/app-context'
  30. import { useProviderContext } from '@/context/provider-context'
  31. import { useModalContext } from '@/context/modal-context'
  32. import { IS_CLOUD_EDITION } from '@/config'
  33. import cn from '@/utils/classnames'
  34. import { useGlobalPublicStore } from '@/context/global-public-context'
  35. // zlwu12 2025-09-18 注释
  36. // import { useDocLink } from '@/context/i18n'
  37. export default function AppSelector() {
  38. const itemClassName = `
  39. flex items-center w-full h-8 pl-3 pr-2 text-text-secondary system-md-regular
  40. rounded-lg hover:bg-state-base-hover cursor-pointer gap-1
  41. `
  42. const router = useRouter()
  43. const [aboutVisible, setAboutVisible] = useState(false)
  44. const { systemFeatures } = useGlobalPublicStore()
  45. const { t } = useTranslation()
  46. // zlwu12 2025-09-18 注释
  47. // const docLink = useDocLink()
  48. const { userProfile, langGeniusVersionInfo, isCurrentWorkspaceOwner } = useAppContext()
  49. const { isEducationAccount } = useProviderContext()
  50. const { setShowAccountSettingModal } = useModalContext()
  51. const handleLogout = async () => {
  52. await logout({
  53. url: '/logout',
  54. params: {},
  55. })
  56. localStorage.removeItem('setup_status')
  57. localStorage.removeItem('console_token')
  58. localStorage.removeItem('refresh_token')
  59. // To avoid use other account's education notice info
  60. localStorage.removeItem('education-reverify-prev-expire-at')
  61. localStorage.removeItem('education-reverify-has-noticed')
  62. localStorage.removeItem('education-expired-has-noticed')
  63. router.push('/signin')
  64. }
  65. return (
  66. <div className="">
  67. <Menu as="div" className="relative inline-block text-left">
  68. {
  69. ({ open }) => (
  70. <>
  71. <MenuButton className={cn('inline-flex items-center rounded-[20px] p-0.5 hover:bg-background-default-dodge', open && 'bg-background-default-dodge')}>
  72. <Avatar avatar={userProfile.avatar_url} name={userProfile.name} size={36} />
  73. </MenuButton>
  74. <Transition
  75. as={Fragment}
  76. enter="transition ease-out duration-100"
  77. enterFrom="transform opacity-0 scale-95"
  78. enterTo="transform opacity-100 scale-100"
  79. leave="transition ease-in duration-75"
  80. leaveFrom="transform opacity-100 scale-100"
  81. leaveTo="transform opacity-0 scale-95"
  82. >
  83. <MenuItems
  84. className="
  85. absolute right-0 mt-1.5 w-60 max-w-80
  86. origin-top-right divide-y divide-divider-subtle rounded-xl bg-components-panel-bg-blur shadow-lg
  87. backdrop-blur-sm focus:outline-none
  88. "
  89. >
  90. <div className="px-1 py-1">
  91. <MenuItem disabled>
  92. <div className='flex flex-nowrap items-center py-2 pl-3 pr-2'>
  93. <div className='grow'>
  94. <div className='system-md-medium break-all text-text-primary'>
  95. {userProfile.name}
  96. {isEducationAccount && (
  97. <PremiumBadge size='s' color='blue' className='ml-1 !px-2'>
  98. <RiGraduationCapFill className='mr-1 h-3 w-3' />
  99. <span className='system-2xs-medium'>EDU</span>
  100. </PremiumBadge>
  101. )}
  102. </div>
  103. <div className='system-xs-regular break-all text-text-tertiary'>{userProfile.email}</div>
  104. </div>
  105. <Avatar avatar={userProfile.avatar_url} name={userProfile.name} size={36} />
  106. </div>
  107. </MenuItem>
  108. <MenuItem>
  109. <Link
  110. className={cn(itemClassName, 'group',
  111. 'data-[active]:bg-state-base-hover',
  112. )}
  113. href='/account'
  114. target='_self' rel='noopener noreferrer'>
  115. <RiAccountCircleLine className='size-4 shrink-0 text-text-tertiary' />
  116. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.account.account')}</div>
  117. <RiArrowRightUpLine className='size-[14px] shrink-0 text-text-tertiary' />
  118. </Link>
  119. </MenuItem>
  120. <MenuItem>
  121. <div className={cn(itemClassName,
  122. 'data-[active]:bg-state-base-hover',
  123. )} onClick={() => setShowAccountSettingModal({ payload: 'members' })}>
  124. <RiSettings3Line className='size-4 shrink-0 text-text-tertiary' />
  125. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.settings')}</div>
  126. </div>
  127. </MenuItem>
  128. </div>
  129. {!systemFeatures.branding.enabled && <>
  130. <div className='p-1'>
  131. {/* zlwu12 2025-09-18 注释 */}
  132. {/* <MenuItem>
  133. <Link
  134. className={cn(itemClassName, 'group justify-between',
  135. 'data-[active]:bg-state-base-hover',
  136. )}
  137. href={docLink('/introduction')}
  138. target='_blank' rel='noopener noreferrer'>
  139. <RiBookOpenLine className='size-4 shrink-0 text-text-tertiary' />
  140. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.helpCenter')}</div>
  141. <RiArrowRightUpLine className='size-[14px] shrink-0 text-text-tertiary' />
  142. </Link>
  143. </MenuItem>
  144. <Support /> */}
  145. {IS_CLOUD_EDITION && isCurrentWorkspaceOwner && <Compliance />}
  146. </div>
  147. <div className='p-1'>
  148. {/* zlwu12 2025-09-18 注释 */}
  149. {/* <MenuItem>
  150. <Link
  151. className={cn(itemClassName, 'group justify-between',
  152. 'data-[active]:bg-state-base-hover',
  153. )}
  154. href='https://roadmap.dify.ai'
  155. target='_blank' rel='noopener noreferrer'>
  156. <RiMap2Line className='size-4 shrink-0 text-text-tertiary' />
  157. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.roadmap')}</div>
  158. <RiArrowRightUpLine className='size-[14px] shrink-0 text-text-tertiary' />
  159. </Link>
  160. </MenuItem>
  161. <MenuItem>
  162. <Link
  163. className={cn(itemClassName, 'group justify-between',
  164. 'data-[active]:bg-state-base-hover',
  165. )}
  166. href='https://github.com/langgenius/dify'
  167. target='_blank' rel='noopener noreferrer'>
  168. <RiGithubLine className='size-4 shrink-0 text-text-tertiary' />
  169. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.github')}</div>
  170. <div className='flex items-center gap-0.5 rounded-[5px] border border-divider-deep bg-components-badge-bg-dimm px-[5px] py-[3px]'>
  171. <RiStarLine className='size-3 shrink-0 text-text-tertiary' />
  172. <GithubStar className='system-2xs-medium-uppercase text-text-tertiary' />
  173. </div>
  174. </Link>
  175. </MenuItem>
  176. {
  177. document?.body?.getAttribute('data-public-site-about') !== 'hide' && (
  178. <MenuItem>
  179. <div className={cn(itemClassName, 'justify-between',
  180. 'data-[active]:bg-state-base-hover',
  181. )} onClick={() => setAboutVisible(true)}>
  182. <RiInformation2Line className='size-4 shrink-0 text-text-tertiary' />
  183. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.about')}</div>
  184. <div className='flex shrink-0 items-center'>
  185. <div className='system-xs-regular mr-2 text-text-tertiary'>{langGeniusVersionInfo.current_version}</div>
  186. <Indicator color={langGeniusVersionInfo.current_version === langGeniusVersionInfo.latest_version ? 'green' : 'orange'} />
  187. </div>
  188. </div>
  189. </MenuItem>
  190. )
  191. } */}
  192. </div>
  193. </>}
  194. <MenuItem disabled>
  195. <div className='p-1'>
  196. <div className={cn(itemClassName, 'hover:bg-transparent')}>
  197. <RiTShirt2Line className='size-4 shrink-0 text-text-tertiary' />
  198. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.theme.theme')}</div>
  199. <ThemeSwitcher />
  200. </div>
  201. </div>
  202. </MenuItem>
  203. <MenuItem>
  204. <div className='p-1' onClick={() => handleLogout()}>
  205. <div
  206. className={cn(itemClassName, 'group justify-between',
  207. 'data-[active]:bg-state-base-hover',
  208. )}
  209. >
  210. <RiLogoutBoxRLine className='size-4 shrink-0 text-text-tertiary' />
  211. <div className='system-md-regular grow px-1 text-text-secondary'>{t('common.userProfile.logout')}</div>
  212. </div>
  213. </div>
  214. </MenuItem>
  215. </MenuItems>
  216. </Transition>
  217. </>
  218. )
  219. }
  220. </Menu>
  221. {
  222. aboutVisible && <AccountAbout onCancel={() => setAboutVisible(false)} langGeniusVersionInfo={langGeniusVersionInfo} />
  223. }
  224. </div >
  225. )
  226. }