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