index.tsx 7.9 KB

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