'use client' import { useTranslation } from 'react-i18next' import { useEffect, useRef, useState } from 'react' import { RiBox3Fill, RiBox3Line, RiCloseLine, RiColorFilterFill, RiColorFilterLine, RiDatabase2Fill, RiDatabase2Line, RiGroup2Fill, RiGroup2Line, RiMoneyDollarCircleFill, RiMoneyDollarCircleLine, RiPuzzle2Fill, RiPuzzle2Line, RiTranslate2, } from '@remixicon/react' import MembersPage from './members-page' import LanguagePage from './language-page' import ApiBasedExtensionPage from './api-based-extension-page' import DataSourcePage from './data-source-page' import ModelProviderPage from './model-provider-page' import s from './index.module.css' import cn from '@/utils/classnames' import BillingPage from '@/app/components/billing/billing-page' import CustomPage from '@/app/components/custom/custom-page' import Modal from '@/app/components/base/modal' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useProviderContext } from '@/context/provider-context' import { useAppContext } from '@/context/app-context' const iconClassName = ` w-4 h-4 ml-3 mr-2 ` const scrolledClassName = ` border-b shadow-xs bg-white/[.98] ` type IAccountSettingProps = { onCancel: () => void activeTab?: string } type GroupItem = { key: string name: string description?: string icon: JSX.Element activeIcon: JSX.Element } export default function AccountSetting({ onCancel, activeTab = 'members', }: IAccountSettingProps) { const [activeMenu, setActiveMenu] = useState(activeTab) const { t } = useTranslation() const { enableBilling, enableReplaceWebAppLogo } = useProviderContext() const { isCurrentWorkspaceDatasetOperator } = useAppContext() const workplaceGroupItems = (() => { if (isCurrentWorkspaceDatasetOperator) return [] return [ { key: 'provider', name: t('common.settings.provider'), icon: , activeIcon: , }, { key: 'members', name: t('common.settings.members'), icon: , activeIcon: , }, { // Use key false to hide this item key: enableBilling ? 'billing' : false, name: t('common.settings.billing'), description: t('billing.plansCommon.receiptInfo'), icon: , activeIcon: , }, { key: 'data-source', name: t('common.settings.dataSource'), icon: , activeIcon: , }, { key: 'api-based-extension', name: t('common.settings.apiBasedExtension'), icon: , activeIcon: , }, { key: (enableReplaceWebAppLogo || enableBilling) ? 'custom' : false, name: t('custom.custom'), icon: , activeIcon: , }, ].filter(item => !!item.key) as GroupItem[] })() const media = useBreakpoints() const isMobile = media === MediaType.mobile const menuItems = [ { key: 'workspace-group', name: t('common.settings.workplaceGroup'), items: workplaceGroupItems, }, { key: 'account-group', name: t('common.settings.accountGroup'), items: [ { key: 'language', name: t('common.settings.language'), icon: , activeIcon: , }, ], }, ] const scrollRef = useRef(null) const [scrolled, setScrolled] = useState(false) useEffect(() => { const targetElement = scrollRef.current const scrollHandle = (e: Event) => { const userScrolled = (e.target as HTMLDivElement).scrollTop > 0 setScrolled(userScrolled) } targetElement?.addEventListener('scroll', scrollHandle) return () => { targetElement?.removeEventListener('scroll', scrollHandle) } }, []) const activeItem = [...menuItems[0].items, ...menuItems[1].items].find(item => item.key === activeMenu) return ( { }} className={s.modal} wrapperClassName='pt-[60px]' > {t('common.userProfile.settings')} { menuItems.map(menuItem => ( {!isCurrentWorkspaceDatasetOperator && ( {menuItem.name} )} { menuItem.items.map(item => ( setActiveMenu(item.key)} > {activeMenu === item.key ? item.activeIcon : item.icon} {!isMobile && {item.name}} )) } )) } {activeItem?.name} { activeItem?.description && ( {activeItem?.description} ) } {activeMenu === 'members' && } {activeMenu === 'billing' && } {activeMenu === 'language' && } {activeMenu === 'provider' && } {activeMenu === 'data-source' && } {activeMenu === 'api-based-extension' && } {activeMenu === 'custom' && } ) }