index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { useState } from 'react'
  4. import { AtSymbolIcon, CubeTransparentIcon, GlobeAltIcon, UserIcon, UsersIcon, XMarkIcon } from '@heroicons/react/24/outline'
  5. import { GlobeAltIcon as GlobalAltIconSolid, UserIcon as UserIconSolid, UsersIcon as UsersIconSolid } from '@heroicons/react/24/solid'
  6. import cn from 'classnames'
  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 ProviderPage from './provider-page'
  12. import DataSourcePage from './data-source-page'
  13. import s from './index.module.css'
  14. import Modal from '@/app/components/base/modal'
  15. const iconClassName = `
  16. w-4 h-4 ml-3 mr-2
  17. `
  18. type IconProps = {
  19. className?: string
  20. }
  21. const DataSourceIcon = ({ className }: IconProps) => (
  22. <div className={cn(s['data-source-icon'], className)} />
  23. )
  24. const DataSourceSolidIcon = ({ className }: IconProps) => (
  25. <div className={cn(s['data-source-solid-icon'], className)} />
  26. )
  27. type IAccountSettingProps = {
  28. onCancel: () => void
  29. activeTab?: string
  30. }
  31. export default function AccountSetting({
  32. onCancel,
  33. activeTab = 'account',
  34. }: IAccountSettingProps) {
  35. const [activeMenu, setActiveMenu] = useState(activeTab)
  36. const { t } = useTranslation()
  37. const menuItems = [
  38. {
  39. key: 'account-group',
  40. name: t('common.settings.accountGroup'),
  41. items: [
  42. {
  43. key: 'account',
  44. name: t('common.settings.account'),
  45. icon: <UserIcon className={iconClassName} />,
  46. activeIcon: <UserIconSolid className={iconClassName} />,
  47. },
  48. {
  49. key: 'integrations',
  50. name: t('common.settings.integrations'),
  51. icon: <AtSymbolIcon className={iconClassName} />,
  52. activeIcon: <AtSymbolIcon className={iconClassName} />,
  53. },
  54. {
  55. key: 'language',
  56. name: t('common.settings.language'),
  57. icon: <GlobeAltIcon className={iconClassName} />,
  58. activeIcon: <GlobalAltIconSolid className={iconClassName} />,
  59. },
  60. ],
  61. },
  62. {
  63. key: 'workspace-group',
  64. name: t('common.settings.workplaceGroup'),
  65. items: [
  66. {
  67. key: 'members',
  68. name: t('common.settings.members'),
  69. icon: <UsersIcon className={iconClassName} />,
  70. activeIcon: <UsersIconSolid className={iconClassName} />,
  71. },
  72. {
  73. key: 'provider',
  74. name: t('common.settings.provider'),
  75. icon: <CubeTransparentIcon className={iconClassName} />,
  76. activeIcon: <CubeTransparentIcon className={iconClassName} />,
  77. },
  78. {
  79. key: 'data-source',
  80. name: t('common.settings.dataSource'),
  81. icon: <DataSourceIcon className={iconClassName} />,
  82. activeIcon: <DataSourceSolidIcon className={iconClassName} />,
  83. },
  84. ],
  85. },
  86. ]
  87. return (
  88. <Modal
  89. isShow
  90. onClose={() => { }}
  91. className={s.modal}
  92. wrapperClassName='pt-[60px]'
  93. >
  94. <div className='flex'>
  95. <div className='w-[200px] p-4 border border-gray-100'>
  96. <div className='mb-8 ml-2 text-base font-medium leading-6 text-gray-900'>{t('common.userProfile.settings')}</div>
  97. <div>
  98. {
  99. menuItems.map(menuItem => (
  100. <div key={menuItem.key} className='mb-4'>
  101. <div className='px-2 mb-[6px] text-xs font-medium text-gray-500'>{menuItem.name}</div>
  102. <div>
  103. {
  104. menuItem.items.map(item => (
  105. <div
  106. key={item.key}
  107. className={`
  108. flex items-center h-[37px] mb-[2px] text-sm cursor-pointer rounded-lg
  109. ${activeMenu === item.key ? 'font-semibold text-primary-600 bg-primary-50' : 'font-light text-gray-700'}
  110. `}
  111. onClick={() => setActiveMenu(item.key)}
  112. >
  113. {activeMenu === item.key ? item.activeIcon : item.icon}{item.name}
  114. </div>
  115. ))
  116. }
  117. </div>
  118. </div>
  119. ))
  120. }
  121. </div>
  122. </div>
  123. <div className='w-[520px] h-[580px] px-6 py-4 overflow-y-auto'>
  124. <div className='flex items-center justify-between h-6 mb-8 text-base font-medium text-gray-900 '>
  125. {[...menuItems[0].items, ...menuItems[1].items].find(item => item.key === activeMenu)?.name}
  126. <XMarkIcon className='w-4 h-4 cursor-pointer' onClick={onCancel} />
  127. </div>
  128. {
  129. activeMenu === 'account' && <AccountPage />
  130. }
  131. {
  132. activeMenu === 'members' && <MembersPage />
  133. }
  134. {
  135. activeMenu === 'integrations' && <IntegrationsPage />
  136. }
  137. {
  138. activeMenu === 'language' && <LanguagePage />
  139. }
  140. {
  141. activeMenu === 'provider' && <ProviderPage />
  142. }
  143. {
  144. activeMenu === 'data-source' && <DataSourcePage />
  145. }
  146. </div>
  147. </div>
  148. </Modal>
  149. )
  150. }