diff --git a/web/app/components/billing/billing-page/index.tsx b/web/app/components/billing/billing-page/index.tsx index 880800274f..a079bf2cb1 100644 --- a/web/app/components/billing/billing-page/index.tsx +++ b/web/app/components/billing/billing-page/index.tsx @@ -11,23 +11,23 @@ import { useProviderContext } from '@/context/provider-context' const Billing: FC = () => { const { t } = useTranslation() - const { isCurrentWorkspaceManager } = useAppContext() + const { isCurrentWorkspaceOwner } = useAppContext() const [billingUrl, setBillingUrl] = React.useState('') const { enableBilling } = useProviderContext() useEffect(() => { - if (!enableBilling && !isCurrentWorkspaceManager) + if (!enableBilling || !isCurrentWorkspaceOwner) return (async () => { const { url } = await fetchBillingUrl() setBillingUrl(url) })() - }, [isCurrentWorkspaceManager]) + }, [isCurrentWorkspaceOwner]) return (
- {enableBilling && isCurrentWorkspaceManager && billingUrl && ( + {enableBilling && isCurrentWorkspaceOwner && billingUrl && (
diff --git a/web/app/components/billing/pricing/index.tsx b/web/app/components/billing/pricing/index.tsx index fa968650af..de67e52835 100644 --- a/web/app/components/billing/pricing/index.tsx +++ b/web/app/components/billing/pricing/index.tsx @@ -9,6 +9,7 @@ import PlanItem from './plan-item' import { XClose } from '@/app/components/base/icons/src/vender/line/general' import { useProviderContext } from '@/context/provider-context' import GridMask from '@/app/components/base/grid-mask' +import { useAppContext } from '@/context/app-context' type Props = { onCancel: () => void @@ -19,7 +20,8 @@ const Pricing: FC = ({ }) => { const { t } = useTranslation() const { plan } = useProviderContext() - + const { isCurrentWorkspaceOwner } = useAppContext() + const canPay = isCurrentWorkspaceOwner const [planRange, setPlanRange] = React.useState(PlanRange.monthly) return createPortal( @@ -41,21 +43,25 @@ const Pricing: FC = ({ currentPlan={plan.type} plan={Plan.sandbox} planRange={planRange} + canPay={canPay} />
diff --git a/web/app/components/billing/pricing/plan-item.tsx b/web/app/components/billing/pricing/plan-item.tsx index 7dd16f1460..c2222579c4 100644 --- a/web/app/components/billing/pricing/plan-item.tsx +++ b/web/app/components/billing/pricing/plan-item.tsx @@ -16,6 +16,7 @@ type Props = { currentPlan: Plan plan: Plan planRange: PlanRange + canPay: boolean } const KeyValue = ({ label, value, tooltip }: { label: string; value: string | number | JSX.Element; tooltip?: string }) => { @@ -65,6 +66,7 @@ const PlanItem: FC = ({ plan, currentPlan, planRange, + canPay, }) => { const { t } = useTranslation() const [loading, setLoading] = React.useState(false) @@ -75,10 +77,13 @@ const PlanItem: FC = ({ const planInfo = ALL_PLANS[plan] const isYear = planRange === PlanRange.yearly const isCurrent = plan === currentPlan - const isPlanDisabled = planInfo.level <= ALL_PLANS[currentPlan].level + const isPlanDisabled = planInfo.level <= ALL_PLANS[currentPlan].level || (!canPay && plan !== Plan.enterprise) const { isCurrentWorkspaceManager } = useAppContext() const btnText = (() => { + if (!canPay && plan !== Plan.enterprise) + return t('billing.plansCommon.contractOwner') + if (isCurrent) return t('billing.plansCommon.currentPlan') 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 b7ed414e6d..778a815bc9 100644 --- a/web/app/components/header/account-dropdown/workplace-selector/index.tsx +++ b/web/app/components/header/account-dropdown/workplace-selector/index.tsx @@ -31,7 +31,8 @@ const WorkplaceSelector = () => { const handleSwitchWorkspace = async (tenant_id: string) => { try { - if (currentWorkspace?.id === tenant_id) return + if (currentWorkspace?.id === tenant_id) + return await switchWorkspace({ url: '/workspaces/switch', body: { tenant_id } }) notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) location.assign(`${location.origin}`) diff --git a/web/context/app-context.tsx b/web/context/app-context.tsx index b23b0cff1b..3f15bba7ec 100644 --- a/web/context/app-context.tsx +++ b/web/context/app-context.tsx @@ -18,6 +18,7 @@ export type AppContextValue = { mutateUserProfile: VoidFunction currentWorkspace: ICurrentWorkspace isCurrentWorkspaceManager: boolean + isCurrentWorkspaceOwner: boolean mutateCurrentWorkspace: VoidFunction pageContainerRef: React.RefObject langeniusVersionInfo: LangGeniusVersionResponse @@ -83,7 +84,7 @@ export const AppContextProvider: FC = ({ children }) => const [langeniusVersionInfo, setLangeniusVersionInfo] = useState(initialLangeniusVersionInfo) const [currentWorkspace, setCurrentWorkspace] = useState(initialWorkspaceInfo) const isCurrentWorkspaceManager = useMemo(() => ['owner', 'admin'].includes(currentWorkspace.role), [currentWorkspace.role]) - + const isCurrentWorkspaceOwner = useMemo(() => currentWorkspace.role === 'owner', [currentWorkspace.role]) const updateUserProfileAndVersion = useCallback(async () => { if (userProfileResponse && !userProfileResponse.bodyUsed) { const result = await userProfileResponse.json() @@ -118,6 +119,7 @@ export const AppContextProvider: FC = ({ children }) => useSelector, currentWorkspace, isCurrentWorkspaceManager, + isCurrentWorkspaceOwner, mutateCurrentWorkspace, }}>
diff --git a/web/i18n/lang/billing.en.ts b/web/i18n/lang/billing.en.ts index 955b3e45b0..f1a91213bc 100644 --- a/web/i18n/lang/billing.en.ts +++ b/web/i18n/lang/billing.en.ts @@ -20,6 +20,7 @@ const translation = { save: 'Save ', free: 'Free', currentPlan: 'Current Plan', + contractOwner: 'Contact your workspace owner', startForFree: 'Start for free', getStartedWith: 'Get started with ', contactSales: 'Contact Sales', diff --git a/web/i18n/lang/billing.zh.ts b/web/i18n/lang/billing.zh.ts index b668b50472..d6eb8b66fd 100644 --- a/web/i18n/lang/billing.zh.ts +++ b/web/i18n/lang/billing.zh.ts @@ -19,6 +19,7 @@ const translation = { year: '年', save: '节省', currentPlan: '当前计划', + contractOwner: '联系您的工作区所有者', free: '免费', startForFree: '免费开始', getStartedWith: '开始使用',