From bbfe83c86b8c29ee758ba1adea17f5f46e6a68ed Mon Sep 17 00:00:00 2001 From: NFish Date: Thu, 20 Feb 2025 14:31:56 +0800 Subject: [PATCH] Fix/upgrade btn show logic (#14072) --- .../workplace-selector/index.tsx | 10 --- web/app/components/header/index.tsx | 40 ++--------- .../components/header/license-env/index.tsx | 17 +++-- .../components/header/plan-badge/index.tsx | 70 +++++++++++++++++++ 4 files changed, 86 insertions(+), 51 deletions(-) create mode 100644 web/app/components/header/plan-badge/index.tsx diff --git a/web/app/components/header/account-dropdown/workplace-selector/index.tsx b/web/app/components/header/account-dropdown/workplace-selector/index.tsx index f8bde33d51..9649f2c70a 100644 --- a/web/app/components/header/account-dropdown/workplace-selector/index.tsx +++ b/web/app/components/header/account-dropdown/workplace-selector/index.tsx @@ -8,7 +8,6 @@ import { switchWorkspace } from '@/service/common' import { useWorkspacesContext } from '@/context/workspace-context' import { useProviderContext } from '@/context/provider-context' import { ToastContext } from '@/app/components/base/toast' -import PremiumBadge from '@/app/components/base/premium-badge' const WorkplaceSelector = () => { const { t } = useTranslation() @@ -72,15 +71,6 @@ const WorkplaceSelector = () => {
handleSwitchWorkspace(workspace.id)}>
{workspace.name[0].toLocaleUpperCase()}
{workspace.name}
- { - -
- - {plan.type === 'professional' ? 'PRO' : plan.type.toUpperCase()} - -
-
- }
)) } diff --git a/web/app/components/header/index.tsx b/web/app/components/header/index.tsx index d0807ff8ad..0e2df2e917 100644 --- a/web/app/components/header/index.tsx +++ b/web/app/components/header/index.tsx @@ -4,8 +4,6 @@ import Link from 'next/link' import { useBoolean } from 'ahooks' import { useSelectedLayoutSegment } from 'next/navigation' import { Bars3Icon } from '@heroicons/react/20/solid' -import { SparklesSoft } from '@/app/components/base/icons/src/public/common' -import PremiumBadge from '../base/premium-badge' import AccountDropdown from './account-dropdown' import AppNav from './app-nav' import DatasetNav from './dataset-nav' @@ -13,7 +11,6 @@ import EnvNav from './env-nav' import PluginsNav from './plugins-nav' import ExploreNav from './explore-nav' import ToolsNav from './tools-nav' -import LicenseNav from './license-env' import { WorkspaceProvider } from '@/context/workspace-context' import { useAppContext } from '@/context/app-context' import LogoSite from '@/app/components/base/logo/logo-site' @@ -21,7 +18,9 @@ import WorkplaceSelector from '@/app/components/header/account-dropdown/workplac import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import { useProviderContext } from '@/context/provider-context' import { useModalContext } from '@/context/modal-context' -import { useTranslation } from 'react-i18next' +import LicenseNav from './license-env' +import PlanBadge from './plan-badge' +import { Plan } from '../billing/type' const navClassName = ` flex items-center relative mr-0 sm:mr-3 px-3 h-8 rounded-xl @@ -31,15 +30,13 @@ const navClassName = ` const Header = () => { const { isCurrentWorkspaceEditor, isCurrentWorkspaceDatasetOperator } = useAppContext() - const { t } = useTranslation() - const selectedSegment = useSelectedLayoutSegment() const media = useBreakpoints() const isMobile = media === MediaType.mobile const [isShowNavMenu, { toggle, setFalse: hideNavMenu }] = useBoolean(false) const { enableBilling, plan } = useProviderContext() const { setShowPricingModal, setShowAccountSettingModal } = useModalContext() - const isFreePlan = plan.type === 'sandbox' + const isFreePlan = plan.type === Plan.sandbox const handlePlanClick = useCallback(() => { if (isFreePlan) setShowPricingModal() @@ -71,18 +68,7 @@ const Header = () => { - {enableBilling && ( -
- - -
- - {t('billing.upgradeBtn.encourageShort')} - -
-
-
- )} + {enableBilling ? : } } @@ -93,20 +79,7 @@ const Header = () => {
/
- { - enableBilling && ( -
- - -
- - {t('billing.upgradeBtn.encourageShort')} - -
-
-
- ) - } + {enableBilling ? : } )} { @@ -120,7 +93,6 @@ const Header = () => { ) }
-
diff --git a/web/app/components/header/license-env/index.tsx b/web/app/components/header/license-env/index.tsx index 800d86d2b8..ca396db37a 100644 --- a/web/app/components/header/license-env/index.tsx +++ b/web/app/components/header/license-env/index.tsx @@ -5,6 +5,8 @@ import { LicenseStatus } from '@/types/feature' import { useTranslation } from 'react-i18next' import { useContextSelector } from 'use-context-selector' import dayjs from 'dayjs' +import PremiumBadge from '../../base/premium-badge' +import { RiHourglass2Fill } from '@remixicon/react' const LicenseNav = () => { const { t } = useTranslation() @@ -13,15 +15,16 @@ const LicenseNav = () => { if (systemFeatures.license?.status === LicenseStatus.EXPIRING) { const expiredAt = systemFeatures.license?.expired_at const count = dayjs(expiredAt).diff(dayjs(), 'days') - return
- {count <= 1 && {t('common.license.expiring', { count })}} - {count > 1 && {t('common.license.expiring_plural', { count })}} -
+ return + + {count <= 1 && {t('common.license.expiring', { count })}} + {count > 1 && {t('common.license.expiring_plural', { count })}} + } if (systemFeatures.license.status === LicenseStatus.ACTIVE) { - return
- Enterprise -
+ return + Enterprise + } return null } diff --git a/web/app/components/header/plan-badge/index.tsx b/web/app/components/header/plan-badge/index.tsx new file mode 100644 index 0000000000..5068e2da95 --- /dev/null +++ b/web/app/components/header/plan-badge/index.tsx @@ -0,0 +1,70 @@ +import { useProviderContext } from '@/context/provider-context' +import classNames from '@/utils/classnames' +import type { FC } from 'react' +import { useTranslation } from 'react-i18next' +import { SparklesSoft } from '../../base/icons/src/public/common' +import PremiumBadge from '../../base/premium-badge' +import { Plan } from '../../billing/type' + +type PlanBadgeProps = { + plan: Plan + size?: 's' | 'm' + allowHover?: boolean + sandboxAsUpgrade?: boolean + onClick?: () => void +} + +const PlanBadge: FC = ({ plan, allowHover, size = 'm', sandboxAsUpgrade = false, onClick }) => { + const { isFetchedPlan } = useProviderContext() + const { t } = useTranslation() + + if (!isFetchedPlan) return null + if (plan === Plan.sandbox && sandboxAsUpgrade) { + return
+ + +
+ + {t('billing.upgradeBtn.encourageShort')} + +
+
+
+ } + if (plan === Plan.sandbox) { + return
+ +
+ + {plan} + +
+
+
+ } + if (plan === Plan.professional) { + return
+ +
+ + pro + +
+
+
+ } + if (plan === Plan.team) { + return
+ +
+ + {plan} + +
+
+
+ } + return null +} + +export default PlanBadge