index.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { useEffect, useRef, useState } from 'react'
  4. import cn from 'classnames'
  5. import { GoldCoin } from '../../base/icons/src/vender/solid/FinanceAndECommerce'
  6. import { GoldCoin as GoldCoinOutLine } from '../../base/icons/src/vender/line/financeAndECommerce'
  7. import AccountPage from './account-page'
  8. import MembersPage from './members-page'
  9. import IntegrationsPage from './Integrations-page'
  10. import LanguagePage from './language-page'
  11. import PluginPage from './plugin-page'
  12. import ApiBasedExtensionPage from './api-based-extension-page'
  13. import DataSourcePage from './data-source-page'
  14. import ModelProviderPage from './model-provider-page'
  15. import s from './index.module.css'
  16. import BillingPage from '@/app/components/billing/billing-page'
  17. import CustomPage from '@/app/components/custom/custom-page'
  18. import Modal from '@/app/components/base/modal'
  19. import {
  20. Database03,
  21. PuzzlePiece01,
  22. Webhooks,
  23. } from '@/app/components/base/icons/src/vender/line/development'
  24. import { Database03 as Database03Solid, PuzzlePiece01 as PuzzlePiece01Solid } from '@/app/components/base/icons/src/vender/solid/development'
  25. import { User01, Users01 } from '@/app/components/base/icons/src/vender/line/users'
  26. import { User01 as User01Solid, Users01 as Users01Solid } from '@/app/components/base/icons/src/vender/solid/users'
  27. import { Globe01 } from '@/app/components/base/icons/src/vender/line/mapsAndTravel'
  28. import { AtSign, XClose } from '@/app/components/base/icons/src/vender/line/general'
  29. import { CubeOutline } from '@/app/components/base/icons/src/vender/line/shapes'
  30. import { Colors } from '@/app/components/base/icons/src/vender/line/editor'
  31. import { Colors as ColorsSolid } from '@/app/components/base/icons/src/vender/solid/editor'
  32. import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
  33. import { useProviderContext } from '@/context/provider-context'
  34. const iconClassName = `
  35. w-4 h-4 ml-3 mr-2
  36. `
  37. const scrolledClassName = `
  38. border-b shadow-xs bg-white/[.98]
  39. `
  40. type IAccountSettingProps = {
  41. onCancel: () => void
  42. activeTab?: string
  43. }
  44. type GroupItem = {
  45. key: string
  46. name: string
  47. icon: JSX.Element
  48. activeIcon: JSX.Element
  49. }
  50. export default function AccountSetting({
  51. onCancel,
  52. activeTab = 'account',
  53. }: IAccountSettingProps) {
  54. const [activeMenu, setActiveMenu] = useState(activeTab)
  55. const { t } = useTranslation()
  56. const { enableBilling, enableReplaceWebAppLogo } = useProviderContext()
  57. const workplaceGroupItems = (() => {
  58. return [
  59. {
  60. key: 'provider',
  61. name: t('common.settings.provider'),
  62. icon: <CubeOutline className={iconClassName} />,
  63. activeIcon: <CubeOutline className={iconClassName} />,
  64. },
  65. {
  66. key: 'members',
  67. name: t('common.settings.members'),
  68. icon: <Users01 className={iconClassName} />,
  69. activeIcon: <Users01Solid className={iconClassName} />,
  70. },
  71. {
  72. // Use key false to hide this item
  73. key: enableBilling ? 'billing' : false,
  74. name: t('common.settings.billing'),
  75. icon: <GoldCoinOutLine className={iconClassName} />,
  76. activeIcon: <GoldCoin className={iconClassName} />,
  77. },
  78. {
  79. key: 'data-source',
  80. name: t('common.settings.dataSource'),
  81. icon: <Database03 className={iconClassName} />,
  82. activeIcon: <Database03Solid className={iconClassName} />,
  83. },
  84. {
  85. key: 'plugin',
  86. name: t('common.settings.plugin'),
  87. icon: <PuzzlePiece01 className={iconClassName} />,
  88. activeIcon: <PuzzlePiece01Solid className={iconClassName} />,
  89. },
  90. {
  91. key: 'api-based-extension',
  92. name: t('common.settings.apiBasedExtension'),
  93. icon: <Webhooks className={iconClassName} />,
  94. activeIcon: <Webhooks className={iconClassName} />,
  95. },
  96. {
  97. key: (enableReplaceWebAppLogo || enableBilling) ? 'custom' : false,
  98. name: t('custom.custom'),
  99. icon: <Colors className={iconClassName} />,
  100. activeIcon: <ColorsSolid className={iconClassName} />,
  101. },
  102. ].filter(item => !!item.key) as GroupItem[]
  103. })()
  104. const media = useBreakpoints()
  105. const isMobile = media === MediaType.mobile
  106. const menuItems = [
  107. {
  108. key: 'workspace-group',
  109. name: t('common.settings.workplaceGroup'),
  110. items: workplaceGroupItems,
  111. },
  112. {
  113. key: 'account-group',
  114. name: t('common.settings.accountGroup'),
  115. items: [
  116. {
  117. key: 'account',
  118. name: t('common.settings.account'),
  119. icon: <User01 className={iconClassName} />,
  120. activeIcon: <User01Solid className={iconClassName} />,
  121. },
  122. {
  123. key: 'integrations',
  124. name: t('common.settings.integrations'),
  125. icon: <AtSign className={iconClassName} />,
  126. activeIcon: <AtSign className={iconClassName} />,
  127. },
  128. {
  129. key: 'language',
  130. name: t('common.settings.language'),
  131. icon: <Globe01 className={iconClassName} />,
  132. activeIcon: <Globe01 className={iconClassName} />,
  133. },
  134. ],
  135. },
  136. ]
  137. const scrollRef = useRef<HTMLDivElement>(null)
  138. const [scrolled, setScrolled] = useState(false)
  139. const scrollHandle = (e: Event) => {
  140. if ((e.target as HTMLDivElement).scrollTop > 0)
  141. setScrolled(true)
  142. else
  143. setScrolled(false)
  144. }
  145. useEffect(() => {
  146. const targetElement = scrollRef.current
  147. targetElement?.addEventListener('scroll', scrollHandle)
  148. return () => {
  149. targetElement?.removeEventListener('scroll', scrollHandle)
  150. }
  151. }, [])
  152. return (
  153. <Modal
  154. isShow
  155. onClose={() => { }}
  156. className={s.modal}
  157. wrapperClassName='!z-20 pt-[60px]'
  158. >
  159. <div className='flex'>
  160. <div className='w-[44px] sm:w-[200px] px-[1px] py-4 sm:p-4 border border-gray-100 shrink-0 sm:shrink-1 flex flex-col items-center sm:items-start'>
  161. <div className='mb-8 ml-0 sm:ml-2 text-sm sm:text-base font-medium leading-6 text-gray-900'>{t('common.userProfile.settings')}</div>
  162. <div className='w-full'>
  163. {
  164. menuItems.map(menuItem => (
  165. <div key={menuItem.key} className='mb-4'>
  166. <div className='px-2 mb-[6px] text-[10px] sm:text-xs font-medium text-gray-500'>{menuItem.name}</div>
  167. <div>
  168. {
  169. menuItem.items.map(item => (
  170. <div
  171. key={item.key}
  172. className={`
  173. flex items-center h-[37px] mb-[2px] text-sm cursor-pointer rounded-lg
  174. ${activeMenu === item.key ? 'font-semibold text-primary-600 bg-primary-50' : 'font-light text-gray-700'}
  175. `}
  176. title={item.name}
  177. onClick={() => setActiveMenu(item.key)}
  178. >
  179. {activeMenu === item.key ? item.activeIcon : item.icon}
  180. {!isMobile && <div className='truncate'>{item.name}</div>}
  181. </div>
  182. ))
  183. }
  184. </div>
  185. </div>
  186. ))
  187. }
  188. </div>
  189. </div>
  190. <div ref={scrollRef} className='relative w-[824px] h-[720px] pb-4 overflow-y-auto'>
  191. <div className={cn('sticky top-0 px-6 py-4 flex items-center justify-between h-14 mb-4 bg-white text-base font-medium text-gray-900 z-20', scrolled && scrolledClassName)}>
  192. {[...menuItems[0].items, ...menuItems[1].items].find(item => item.key === activeMenu)?.name}
  193. <div className='flex items-center justify-center -mr-4 w-6 h-6 cursor-pointer' onClick={onCancel}>
  194. <XClose className='w-4 h-4 text-gray-500' />
  195. </div>
  196. </div>
  197. <div className='px-4 sm:px-8 pt-2'>
  198. {activeMenu === 'account' && <AccountPage />}
  199. {activeMenu === 'members' && <MembersPage />}
  200. {activeMenu === 'billing' && <BillingPage />}
  201. {activeMenu === 'integrations' && <IntegrationsPage />}
  202. {activeMenu === 'language' && <LanguagePage />}
  203. {activeMenu === 'provider' && <ModelProviderPage />}
  204. {activeMenu === 'data-source' && <DataSourcePage />}
  205. {activeMenu === 'plugin' && <PluginPage />}
  206. {activeMenu === 'api-based-extension' && <ApiBasedExtensionPage /> }
  207. {activeMenu === 'custom' && <CustomPage /> }
  208. </div>
  209. </div>
  210. </div>
  211. </Modal>
  212. )
  213. }