Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): simplify pricing components (#41416)

yyhf7e71ca9e1de
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index a0c36e9ee71..0b17e1b70df 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -1772,24 +1772,6 @@
"count": 12
}
},
- "web/app/components/billing/pricing/plan-switcher/plan-range-switcher.tsx": {
- "erasable-syntax-only/enums": {
- "count": 1
- },
- "react/only-export-components": {
- "count": 1
- }
- },
- "web/app/components/billing/pricing/plans/self-hosted-plan-item/button.tsx": {
- "eslint-react/static-components": {
- "count": 2
- }
- },
- "web/app/components/billing/pricing/types.ts": {
- "erasable-syntax-only/enums": {
- "count": 1
- }
- },
"web/app/components/datasets/chunk.tsx": {
"jsx-a11y/label-has-associated-control": {
"count": 2
diff --git a/web/__tests__/billing/cloud-plan-payment-flow.test.tsx b/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
index dd5d53ef0e0..7525f331796 100644
--- a/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
+++ b/web/__tests__/billing/cloud-plan-payment-flow.test.tsx
@@ -7,14 +7,14 @@
* Covers plan comparison, downgrade prevention, monthly/yearly pricing,
* and workspace manager permission enforcement.
*/
+import type { GetBillingSubscriptionData } from '@dify/contracts/api/console/billing/types.gen'
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
import { toast, ToastHost } from '@langgenius/dify-ui/toast'
import { cleanup, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import * as React from 'react'
import { ALL_PLANS } from '@/app/components/billing/config'
-import { PlanRange } from '@/app/components/billing/pricing/plan-switcher/plan-range-switcher'
-import CloudPlanItem from '@/app/components/billing/pricing/plans/cloud-plan-item'
+import { CloudPlanItem } from '@/app/components/billing/pricing/plans/cloud-plan-item'
import { createConsoleQueryWrapper } from '@/test/console/query-data'
import { render } from '@/test/console/render'
@@ -70,21 +70,29 @@ const setupConsoleState = (overrides: Record<string, unknown> = {}) => {
type RenderCloudPlanItemOptions = {
currentPlan?: CloudPlan
plan?: CloudPlan
- planRange?: PlanRange
- canPay?: boolean
+ billingInterval?: GetBillingSubscriptionData['query']['interval']
+ canManageBilling?: boolean
+ isEducationDiscountEligible?: boolean
}
const renderCloudPlanItem = ({
currentPlan = 'sandbox',
plan = 'professional',
- planRange = PlanRange.monthly,
- canPay = true,
+ billingInterval = 'month',
+ canManageBilling = true,
+ isEducationDiscountEligible = false,
}: RenderCloudPlanItemOptions = {}) => {
+ setupConsoleState({ isCurrentWorkspaceManager: canManageBilling })
const { wrapper } = createConsoleQueryWrapper()
return render(
<>
<ToastHost timeout={0} />
- <CloudPlanItem currentPlan={currentPlan} plan={plan} planRange={planRange} canPay={canPay} />
+ <CloudPlanItem
+ currentPlan={currentPlan}
+ plan={plan}
+ billingInterval={billingInterval}
+ isEducationDiscountEligible={isEducationDiscountEligible}
+ />
</>,
{ wrapper },
)
@@ -118,13 +126,13 @@ describe('Cloud Plan Payment Flow', () => {
})
it('should show monthly price for paid plans', () => {
- renderCloudPlanItem({ plan: 'professional', planRange: PlanRange.monthly })
+ renderCloudPlanItem({ plan: 'professional', billingInterval: 'month' })
expect(screen.getByText(`$${ALL_PLANS.professional.price}`)).toBeInTheDocument()
})
it('should show yearly discounted price (10 months) and strikethrough original (12 months)', () => {
- renderCloudPlanItem({ plan: 'professional', planRange: PlanRange.yearly })
+ renderCloudPlanItem({ plan: 'professional', billingInterval: 'year' })
const yearlyPrice = ALL_PLANS.professional.price * 10
const originalPrice = ALL_PLANS.professional.price * 12
@@ -217,7 +225,7 @@ describe('Cloud Plan Payment Flow', () => {
renderCloudPlanItem({
currentPlan: 'sandbox',
plan: 'professional',
- planRange: PlanRange.monthly,
+ billingInterval: 'month',
})
const button = getPlanButton('billing.plansCommon.startBuilding')
@@ -235,7 +243,7 @@ describe('Cloud Plan Payment Flow', () => {
renderCloudPlanItem({
currentPlan: 'sandbox',
plan: 'team',
- planRange: PlanRange.yearly,
+ billingInterval: 'year',
})
const button = getPlanButton('billing.plansCommon.getStarted')
@@ -281,7 +289,11 @@ describe('Cloud Plan Payment Flow', () => {
describe('Payment capability', () => {
it('should change plans when payment is allowed', async () => {
const user = userEvent.setup()
- renderCloudPlanItem({ currentPlan: 'sandbox', plan: 'professional', canPay: true })
+ renderCloudPlanItem({
+ currentPlan: 'sandbox',
+ plan: 'professional',
+ canManageBilling: true,
+ })
const button = getPlanButton('billing.plansCommon.startBuilding')
await user.click(button)
@@ -295,7 +307,11 @@ describe('Cloud Plan Payment Flow', () => {
it('should block plan changes when payment is not allowed', async () => {
const user = userEvent.setup()
- renderCloudPlanItem({ currentPlan: 'sandbox', plan: 'professional', canPay: false })
+ renderCloudPlanItem({
+ currentPlan: 'sandbox',
+ plan: 'professional',
+ canManageBilling: false,
+ })
const button = getPlanButton('billing.plansCommon.startBuilding')
await user.click(button)
@@ -311,7 +327,7 @@ describe('Cloud Plan Payment Flow', () => {
renderCloudPlanItem({
currentPlan: 'professional',
plan: 'professional',
- canPay: true,
+ canManageBilling: true,
})
const button = getPlanButton('billing.plansCommon.currentPlan')
@@ -328,7 +344,7 @@ describe('Cloud Plan Payment Flow', () => {
renderCloudPlanItem({
currentPlan: 'professional',
plan: 'professional',
- canPay: false,
+ canManageBilling: false,
})
const button = getPlanButton('billing.plansCommon.currentPlan')
diff --git a/web/__tests__/billing/pricing-modal-flow.test.tsx b/web/__tests__/billing/pricing-modal-flow.test.tsx
index 7bbea49505f..6f32dc9d044 100644
--- a/web/__tests__/billing/pricing-modal-flow.test.tsx
+++ b/web/__tests__/billing/pricing-modal-flow.test.tsx
@@ -2,40 +2,45 @@
* Integration test: Pricing Modal Flow
*
* Tests the full Pricing modal lifecycle:
- * Pricing → PlanSwitcher (category + range toggle) → Plans (cloud / self-hosted)
+ * Pricing → PricingContent (category + billing interval) → cloud / self-hosted plans
* → CloudPlanItem / SelfHostedPlanItem → Footer
*
* Validates cross-component state propagation when the user switches between
* cloud / self-hosted categories and monthly / yearly plan ranges.
*/
+import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
import { cleanup, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import * as React from 'react'
import { ALL_PLANS } from '@/app/components/billing/config'
-import Pricing from '@/app/components/billing/pricing'
-import { createConsoleQueryWrapper } from '@/test/console/query-data'
+import { Pricing } from '@/app/components/billing/pricing'
+import { createConsoleQueryWrapper, seedFeatures } from '@/test/console/query-data'
import { render as renderWithConsoleState } from '@/test/console/render'
// ─── Mock state ──────────────────────────────────────────────────────────────
-let mockProviderCtx: Record<string, unknown> = {}
let mockConsoleState: Record<string, unknown> = {}
let mockEducationStatus = { is_student: false, allow_refresh: false, expire_at: null }
+let mockCurrentPlan: CloudPlan = 'sandbox'
+let mockEducationEnabled = false
const mockGetSubscription = vi.hoisted(() => vi.fn())
const render = (ui: React.ReactElement) => {
- const { wrapper } = createConsoleQueryWrapper({
+ const { queryClient, wrapper } = createConsoleQueryWrapper({
accountProfile: mockConsoleState.userProfile as { email?: string },
accountProfileMeta: { currentVersion: '1.0.0' },
educationStatus: mockEducationStatus,
})
+ seedFeatures(queryClient, {
+ billing: {
+ enabled: true,
+ subscription: { interval: 'month', plan: mockCurrentPlan },
+ },
+ education: { enabled: mockEducationEnabled },
+ })
return renderWithConsoleState(ui, { wrapper })
}
// ─── Context mocks ───────────────────────────────────────────────────────────
-vi.mock('@/context/provider-context', () => ({
- useProviderContext: () => mockProviderCtx,
-}))
-
vi.mock('@/context/workspace-state', async () => {
const { createWorkspaceStateModuleMock } = await import('@/test/console/state-fixture')
return createWorkspaceStateModuleMock(() => mockConsoleState)
@@ -76,61 +81,20 @@ vi.mock('@/next/navigation', () => ({
useSearchParams: () => new URLSearchParams(),
}))
-// ─── External component mocks (lightweight) ─────────────────────────────────
-vi.mock('@/app/components/base/icons/src/public/billing', () => ({
- Azure: () => <span data-testid="icon-azure" />,
- GoogleCloud: () => <span data-testid="icon-gcloud" />,
- AwsMarketplaceLight: () => <span data-testid="icon-aws-light" />,
- AwsMarketplaceDark: () => <span data-testid="icon-aws-dark" />,
-}))
-
-vi.mock('@/hooks/use-theme', () => ({
- default: () => ({ theme: 'light' }),
- useTheme: () => ({ theme: 'light' }),
-}))
-
// Self-hosted List uses t() with returnObjects which returns string in mock;
// mock it to avoid deep i18n dependency (unit tests cover this component)
vi.mock('@/app/components/billing/pricing/plans/self-hosted-plan-item/list', () => ({
- default: ({ plan }: { plan: string }) => (
- <div data-testid={`self-hosted-list-${plan}`}>Features</div>
- ),
+ SelfHostedPlanFeatures: () => null,
}))
// ─── Helpers ─────────────────────────────────────────────────────────────────
-const defaultPlanData = {
- type: 'sandbox',
- usage: {
- buildApps: 1,
- teamMembers: 1,
- documentsUploadQuota: 0,
- vectorSpace: 10,
- annotatedResponse: 1,
- triggerEvents: 0,
- apiRateLimit: 0,
- },
- total: {
- buildApps: 5,
- teamMembers: 1,
- documentsUploadQuota: 50,
- vectorSpace: 50,
- annotatedResponse: 10,
- triggerEvents: 3000,
- apiRateLimit: 5000,
- },
-}
-
const setupContexts = (
- planOverrides: Record<string, unknown> = {},
+ planOverrides: { type?: CloudPlan } = {},
appOverrides: Record<string, unknown> = {},
) => {
mockEducationStatus = { is_student: false, allow_refresh: false, expire_at: null }
- mockProviderCtx = {
- plan: { ...defaultPlanData, ...planOverrides },
- enableBilling: true,
- isFetchedPlan: true,
- enableEducationPlan: false,
- }
+ mockCurrentPlan = planOverrides.type ?? 'sandbox'
+ mockEducationEnabled = false
mockConsoleState = {
isCurrentWorkspaceManager: true,
userProfile: { email: '[email protected]' },
@@ -165,14 +129,17 @@ describe('Pricing Modal Flow', () => {
it('should default to cloud category with three cloud plans', () => {
render(<Pricing onCancel={onCancel} />)
- expect(screen.getByRole('button', { name: 'billing.plansCommon.cloud' })).toHaveAttribute(
- 'aria-pressed',
+ expect(screen.getByRole('tab', { name: 'billing.plansCommon.cloud' })).toHaveAttribute(
+ 'aria-selected',
'true',
)
- expect(screen.getByRole('button', { name: 'billing.plansCommon.self' })).toHaveAttribute(
- 'aria-pressed',
+ expect(screen.getByRole('tab', { name: 'billing.plansCommon.self' })).toHaveAttribute(
+ 'aria-selected',
'false',
)
+ expect(
+ screen.getByRole('tablist', { name: 'billing.plansCommon.title.plans' }),
+ ).toBeInTheDocument()
// Three cloud plans: sandbox, professional, team
expect(screen.getByText(/plans\.sandbox\.name/i)).toBeInTheDocument()
@@ -202,13 +169,12 @@ describe('Pricing Modal Flow', () => {
const user = userEvent.setup()
render(<Pricing onCancel={onCancel} />)
- const selfHostedButton = screen.getByRole('button', {
- name: 'billing.plansCommon.self',
- })
- selfHostedButton.focus()
- await user.keyboard(' ')
+ const cloudTab = screen.getByRole('tab', { name: 'billing.plansCommon.cloud' })
+ const selfHostedTab = screen.getByRole('tab', { name: 'billing.plansCommon.self' })
+ cloudTab.focus()
+ await user.keyboard('{ArrowRight}')
- expect(selfHostedButton).toHaveAttribute('aria-pressed', 'true')
+ expect(selfHostedTab).toHaveAttribute('aria-selected', 'true')
// Self-hosted plans should appear
expect(screen.getByText(/plans\.community\.name/i)).toBeInTheDocument()
@@ -223,7 +189,7 @@ describe('Pricing Modal Flow', () => {
const user = userEvent.setup()
render(<Pricing onCancel={onCancel} />)
- await user.click(screen.getByRole('button', { name: 'billing.plansCommon.self' }))
+ await user.click(screen.getByRole('tab', { name: 'billing.plansCommon.self' }))
// Annual billing toggle should not be visible
expect(screen.queryByText(/plansCommon\.annualBilling/i)).not.toBeInTheDocument()
@@ -233,7 +199,7 @@ describe('Pricing Modal Flow', () => {
const user = userEvent.setup()
render(<Pricing onCancel={onCancel} />)
- await user.click(screen.getByRole('button', { name: 'billing.plansCommon.self' }))
+ await user.click(screen.getByRole('tab', { name: 'billing.plansCommon.self' }))
expect(screen.queryByText('billing.plansCommon.taxTip')).not.toBeInTheDocument()
})
@@ -243,11 +209,11 @@ describe('Pricing Modal Flow', () => {
render(<Pricing onCancel={onCancel} />)
// Switch to self-hosted
- await user.click(screen.getByRole('button', { name: 'billing.plansCommon.self' }))
+ await user.click(screen.getByRole('tab', { name: 'billing.plansCommon.self' }))
expect(screen.queryByText(/plans\.sandbox\.name/i)).not.toBeInTheDocument()
// Switch back to cloud
- await user.click(screen.getByRole('button', { name: 'billing.plansCommon.cloud' }))
+ await user.click(screen.getByRole('tab', { name: 'billing.plansCommon.cloud' }))
expect(screen.getByText(/plans\.sandbox\.name/i)).toBeInTheDocument()
expect(screen.getByText(/plansCommon\.annualBilling/i)).toBeInTheDocument()
})
@@ -297,10 +263,7 @@ describe('Pricing Modal Flow', () => {
it('should default education account managers to yearly checkout', async () => {
setupContexts()
- mockProviderCtx = {
- ...mockProviderCtx,
- enableEducationPlan: true,
- }
+ mockEducationEnabled = true
mockEducationStatus.is_student = true
const user = userEvent.setup()
render(<Pricing onCancel={onCancel} />)
@@ -356,17 +319,6 @@ describe('Pricing Modal Flow', () => {
// ─── 5. Self-Hosted Plan Details ─────────────────────────────────────────
describe('Self-hosted plan details', () => {
- it('should show cloud provider icons only for premium plan', async () => {
- const user = userEvent.setup()
- render(<Pricing onCancel={onCancel} />)
-
- await user.click(screen.getByText(/plansCommon\.self/i))
-
- // Premium plan should show Azure and Google Cloud icons
- expect(screen.getByTestId('icon-azure')).toBeInTheDocument()
- expect(screen.getByTestId('icon-gcloud')).toBeInTheDocument()
- })
-
it('should show "coming soon" text for premium plan cloud providers', async () => {
const user = userEvent.setup()
render(<Pricing onCancel={onCancel} />)
diff --git a/web/__tests__/billing/self-hosted-plan-flow.test.tsx b/web/__tests__/billing/self-hosted-plan-flow.test.tsx
index f76955b4903..4193e1828d0 100644
--- a/web/__tests__/billing/self-hosted-plan-flow.test.tsx
+++ b/web/__tests__/billing/self-hosted-plan-flow.test.tsx
@@ -1,4 +1,4 @@
-import type { SelfHostedPlanOption } from '@/app/components/billing/pricing/plans/self-hosted-plan-item/types'
+import type { SelfHostedPlan } from '@/app/components/billing/config'
/**
* Integration test: Self-Hosted Plan Flow
*
@@ -8,38 +8,16 @@ import type { SelfHostedPlanOption } from '@/app/components/billing/pricing/plan
* Covers community/premium/enterprise plan rendering and external URL navigation.
*/
import { cleanup, screen } from '@testing-library/react'
-import userEvent from '@testing-library/user-event'
import * as React from 'react'
-import {
- contactSalesUrl,
- getStartedWithCommunityUrl,
- getWithPremiumUrl,
-} from '@/app/components/billing/config'
-import SelfHostedPlanItem from '@/app/components/billing/pricing/plans/self-hosted-plan-item'
+import { SELF_HOSTED_PLAN_URLS } from '@/app/components/billing/config'
+import { SelfHostedPlanItem } from '@/app/components/billing/pricing/plans/self-hosted-plan-item'
import { render } from '@/test/console/render'
-const originalLocation = window.location
-let assignedHref = ''
-
-vi.mock('@/hooks/use-theme', () => ({
- default: () => ({ theme: 'light' }),
- useTheme: () => ({ theme: 'light' }),
-}))
-
-vi.mock('@/app/components/base/icons/src/public/billing', () => ({
- Azure: () => <span data-testid="icon-azure" />,
- GoogleCloud: () => <span data-testid="icon-gcloud" />,
- AwsMarketplaceLight: () => <span data-testid="icon-aws-light" />,
- AwsMarketplaceDark: () => <span data-testid="icon-aws-dark" />,
-}))
-
vi.mock('@/app/components/billing/pricing/plans/self-hosted-plan-item/list', () => ({
- default: ({ plan }: { plan: string }) => (
- <div data-testid={`self-hosted-list-${plan}`}>Features</div>
- ),
+ SelfHostedPlanFeatures: () => null,
}))
-const renderSelfHostedPlanItem = (plan: SelfHostedPlanOption) => {
+const renderSelfHostedPlanItem = (plan: SelfHostedPlan) => {
return render(<SelfHostedPlanItem plan={plan} />)
}
@@ -47,28 +25,6 @@ describe('Self-Hosted Plan Flow', () => {
beforeEach(() => {
vi.clearAllMocks()
cleanup()
-
- // Mock window.location with minimal getter/setter (Location props are non-enumerable)
- assignedHref = ''
- Object.defineProperty(window, 'location', {
- configurable: true,
- value: {
- get href() {
- return assignedHref
- },
- set href(value: string) {
- assignedHref = value
- },
- },
- })
- })
-
- afterEach(() => {
- // Restore original location
- Object.defineProperty(window, 'location', {
- configurable: true,
- value: originalLocation,
- })
})
// ─── 1. Plan Rendering ──────────────────────────────────────────────────
@@ -80,21 +36,6 @@ describe('Self-Hosted Plan Flow', () => {
expect(screen.getByText(/plans\.community\.description/i)).toBeInTheDocument()
})
- it('should render premium plan with cloud provider icons', () => {
- renderSelfHostedPlanItem('premium')
-
- expect(screen.getByText(/plans\.premium\.name/i)).toBeInTheDocument()
- expect(screen.getByTestId('icon-azure')).toBeInTheDocument()
- expect(screen.getByTestId('icon-gcloud')).toBeInTheDocument()
- })
-
- it('should render enterprise plan without cloud provider icons', () => {
- renderSelfHostedPlanItem('enterprise')
-
- expect(screen.getByText(/plans\.enterprise\.name/i)).toBeInTheDocument()
- expect(screen.queryByTestId('icon-azure')).not.toBeInTheDocument()
- })
-
it('should not show price tip for community (free) plan', () => {
renderSelfHostedPlanItem('community')
@@ -106,57 +47,18 @@ describe('Self-Hosted Plan Flow', () => {
expect(screen.getByText(/plans\.premium\.priceTip/i)).toBeInTheDocument()
})
-
- it('should render features list for each plan', () => {
- const { unmount: unmount1 } = renderSelfHostedPlanItem('community')
- expect(screen.getByTestId('self-hosted-list-community')).toBeInTheDocument()
- unmount1()
-
- const { unmount: unmount2 } = renderSelfHostedPlanItem('premium')
- expect(screen.getByTestId('self-hosted-list-premium')).toBeInTheDocument()
- unmount2()
-
- renderSelfHostedPlanItem('enterprise')
- expect(screen.getByTestId('self-hosted-list-enterprise')).toBeInTheDocument()
- })
-
- it('should show AWS marketplace icon for premium plan button', () => {
- renderSelfHostedPlanItem('premium')
-
- expect(screen.getByTestId('icon-aws-light')).toBeInTheDocument()
- })
})
// ─── 2. Navigation Flow ─────────────────────────────────────────────────
describe('Navigation flow', () => {
- it('should redirect to GitHub when clicking community plan button', async () => {
- const user = userEvent.setup()
- renderSelfHostedPlanItem('community')
-
- const button = screen.getByRole('button')
- await user.click(button)
-
- expect(assignedHref).toBe(getStartedWithCommunityUrl)
- })
-
- it('should redirect to AWS Marketplace when clicking premium plan button', async () => {
- const user = userEvent.setup()
- renderSelfHostedPlanItem('premium')
-
- const button = screen.getByRole('button')
- await user.click(button)
-
- expect(assignedHref).toBe(getWithPremiumUrl)
- })
-
- it('should redirect to Typeform when clicking enterprise plan button', async () => {
- const user = userEvent.setup()
- renderSelfHostedPlanItem('enterprise')
-
- const button = screen.getByRole('button')
- await user.click(button)
-
- expect(assignedHref).toBe(contactSalesUrl)
+ it.each([
+ ['community', SELF_HOSTED_PLAN_URLS.community],
+ ['premium', SELF_HOSTED_PLAN_URLS.premium],
+ ['enterprise', SELF_HOSTED_PLAN_URLS.enterprise],
+ ] as const)('should expose the %s destination as a native link', (plan, href) => {
+ renderSelfHostedPlanItem(plan)
+
+ expect(screen.getByRole('link')).toHaveAttribute('href', href)
})
})
})
diff --git a/web/app/components/base/icons/src/public/billing/Azure.tsx b/web/app/components/base/icons/src/public/billing/Azure.tsx
deleted file mode 100644
index 1ac6b3a640e..00000000000
--- a/web/app/components/base/icons/src/public/billing/Azure.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-// GENERATE BY script
-// DON NOT EDIT IT MANUALLY
-
-import type { IconData } from '@/app/components/base/icons/IconBase'
-import * as React from 'react'
-import IconBase from '@/app/components/base/icons/IconBase'
-import data from './Azure.json'
-
-const Icon = ({
- ref,
- ...props
-}: React.SVGProps<SVGSVGElement> & {
- ref?: React.RefObject<React.RefObject<HTMLOrSVGElement>>
-}) => <IconBase {...props} ref={ref} data={data as IconData} />
-
-Icon.displayName = 'Azure'
-
-export default Icon
diff --git a/web/app/components/base/icons/src/public/billing/GoogleCloud.tsx b/web/app/components/base/icons/src/public/billing/GoogleCloud.tsx
deleted file mode 100644
index 4fd2fd9bea2..00000000000
--- a/web/app/components/base/icons/src/public/billing/GoogleCloud.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-// GENERATE BY script
-// DON NOT EDIT IT MANUALLY
-
-import type { IconData } from '@/app/components/base/icons/IconBase'
-import * as React from 'react'
-import IconBase from '@/app/components/base/icons/IconBase'
-import data from './GoogleCloud.json'
-
-const Icon = ({
- ref,
- ...props
-}: React.SVGProps<SVGSVGElement> & {
- ref?: React.RefObject<React.RefObject<HTMLOrSVGElement>>
-}) => <IconBase {...props} ref={ref} data={data as IconData} />
-
-Icon.displayName = 'GoogleCloud'
-
-export default Icon
diff --git a/web/app/components/base/icons/src/public/billing/index.ts b/web/app/components/base/icons/src/public/billing/index.ts
deleted file mode 100644
index c80933b0db6..00000000000
--- a/web/app/components/base/icons/src/public/billing/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-export { default as AwsMarketplaceDark } from './AwsMarketplaceDark'
-export { default as AwsMarketplaceLight } from './AwsMarketplaceLight'
-export { default as Azure } from './Azure'
-
-export { default as GoogleCloud } from './GoogleCloud'
diff --git a/web/app/components/billing/config.ts b/web/app/components/billing/config.ts
index 6e6b00b5d09..88a1a60016e 100644
--- a/web/app/components/billing/config.ts
+++ b/web/app/components/billing/config.ts
@@ -5,8 +5,13 @@ const supportModelProviders = 'OpenAI/Anthropic/Llama2/Azure OpenAI/Hugging Face
export const NUM_INFINITE = -1
export const contactSalesUrl = 'https://vikgc6bnu1s.typeform.com/dify-business'
-export const getStartedWithCommunityUrl = 'https://github.com/langgenius/dify'
-export const getWithPremiumUrl = 'https://aws.amazon.com/marketplace/pp/prodview-t22mebxzwjhu6'
+export const SELF_HOSTED_PLAN_URLS = {
+ community: 'https://github.com/langgenius/dify',
+ premium: 'https://aws.amazon.com/marketplace/pp/prodview-t22mebxzwjhu6',
+ enterprise: contactSalesUrl,
+} as const
+
+export type SelfHostedPlan = keyof typeof SELF_HOSTED_PLAN_URLS
export const ALL_PLANS: Record<CloudPlan, PlanInfo> = {
sandbox: {
diff --git a/web/app/components/billing/hooks/use-education-discount.ts b/web/app/components/billing/hooks/use-education-discount.ts
index 217e0a2c282..2fec57d41fd 100644
--- a/web/app/components/billing/hooks/use-education-discount.ts
+++ b/web/app/components/billing/hooks/use-education-discount.ts
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next'
import { isCurrentWorkspaceManagerAtom } from '@/context/workspace-state'
import { consoleClient } from '@/service/client'
-export const useEducationDiscount = () => {
+export function useEducationDiscount() {
const { t } = useTranslation()
const isCurrentWorkspaceManager = useAtomValue(isCurrentWorkspaceManagerAtom)
const [isEducationDiscountLoading, setIsEducationDiscountLoading] = useState(false)
@@ -21,10 +21,10 @@ export const useEducationDiscount = () => {
setIsEducationDiscountLoading(true)
try {
- const res = await consoleClient.billing.subscription.get({
+ const { url } = await consoleClient.billing.subscription.get({
query: { plan: 'professional', interval: 'year' },
})
- window.location.href = res.url
+ window.location.href = url
} finally {
setIsEducationDiscountLoading(false)
}
diff --git a/web/app/components/billing/pricing/__tests__/dialog.spec.tsx b/web/app/components/billing/pricing/__tests__/dialog.spec.tsx
index 784fd362f33..7902c88ba26 100644
--- a/web/app/components/billing/pricing/__tests__/dialog.spec.tsx
+++ b/web/app/components/billing/pricing/__tests__/dialog.spec.tsx
@@ -1,25 +1,15 @@
import type { Mock } from 'vite-plus/test'
-import type { UsagePlanInfo } from '../../type'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { useGetPricingPageLanguage } from '@/context/i18n'
-import { useProviderContext } from '@/context/provider-context'
import { createConsoleQueryWrapper } from '@/test/console/query-data'
import { render } from '@/test/console/render'
-import Pricing from '../index'
+import { Pricing } from '../index'
let mockConsoleState: Record<string, unknown> = {}
-vi.mock('../plan-switcher', () => ({
- default: () => <div>plan-switcher</div>,
-}))
-
-vi.mock('../plans', () => ({
- default: () => <div>plans</div>,
-}))
-
-vi.mock('../footer', () => ({
- default: () => <div>footer</div>,
+vi.mock('../content', () => ({
+ PricingContent: () => <div>pricing-content</div>,
}))
vi.mock('@/context/workspace-state', async () => {
@@ -27,38 +17,16 @@ vi.mock('@/context/workspace-state', async () => {
return createWorkspaceStateModuleMock(() => mockConsoleState)
})
-vi.mock('@/context/provider-context', () => ({
- useProviderContext: vi.fn(),
-}))
-
vi.mock('@/context/i18n', () => ({
useGetPricingPageLanguage: vi.fn(),
}))
-const buildUsage = (): UsagePlanInfo => ({
- buildApps: 0,
- teamMembers: 0,
- annotatedResponse: 0,
- documentsUploadQuota: 0,
- apiRateLimit: 0,
- triggerEvents: 0,
- vectorSpace: 0,
-})
-
describe('Pricing dialog lifecycle', () => {
beforeEach(() => {
vi.clearAllMocks()
mockConsoleState = {
isCurrentWorkspaceManager: true,
}
- ;(useProviderContext as Mock).mockReturnValue({
- enableEducationPlan: false,
- plan: {
- type: 'sandbox',
- usage: buildUsage(),
- total: buildUsage(),
- },
- })
;(useGetPricingPageLanguage as Mock).mockReturnValue('en')
})
diff --git a/web/app/components/billing/pricing/assets/index.tsx b/web/app/components/billing/pricing/assets/index.tsx
deleted file mode 100644
index 0b485eb055f..00000000000
--- a/web/app/components/billing/pricing/assets/index.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-export { default as Cloud } from './cloud'
-export { default as Community } from './community'
-export { default as Enterprise } from './enterprise'
-export { default as EnterpriseNoise } from './enterprise-noise'
-export { default as NoiseBottom } from './noise-bottom'
-export { default as NoiseTop } from './noise-top'
-export { default as Premium } from './premium'
-export { default as PremiumNoise } from './premium-noise'
-export { default as Professional } from './professional'
-export { default as Sandbox } from './sandbox'
-export { default as SelfHosted } from './self-hosted'
-export { default as Team } from './team'
diff --git a/web/app/components/billing/pricing/content.tsx b/web/app/components/billing/pricing/content.tsx
new file mode 100644
index 00000000000..45f93415d0d
--- /dev/null
+++ b/web/app/components/billing/pricing/content.tsx
@@ -0,0 +1,161 @@
+import type { GetBillingSubscriptionData } from '@dify/contracts/api/console/billing/types.gen'
+import { cn } from '@langgenius/dify-ui/cn'
+import { Switch } from '@langgenius/dify-ui/switch'
+import { Tabs, TabsList, TabsPanel, TabsTab } from '@langgenius/dify-ui/tabs'
+import { useQuery } from '@tanstack/react-query'
+import { useAtomValue } from 'jotai'
+import * as React from 'react'
+import { useTranslation } from 'react-i18next'
+import Divider from '@/app/components/base/divider'
+import { isCurrentWorkspaceManagerAtom } from '@/context/workspace-state'
+import { consoleQuery } from '@/service/client'
+import Cloud from './assets/cloud'
+import NoiseBottom from './assets/noise-bottom'
+import NoiseTop from './assets/noise-top'
+import SelfHosted from './assets/self-hosted'
+import { PricingFooter } from './footer'
+import Header from './header'
+import { CloudPlanItem } from './plans/cloud-plan-item'
+import { SelfHostedPlanItem } from './plans/self-hosted-plan-item'
+
+type BillingInterval = GetBillingSubscriptionData['query']['interval']
+
+export function PricingContent({ pricingPageURL }: { pricingPageURL: string }) {
+ const { t } = useTranslation()
+ const { data: features } = useQuery(consoleQuery.features.get.queryOptions())
+ const educationEnabled = features?.education.enabled ?? false
+ const { data: isEducationAccount = false } = useQuery(
+ consoleQuery.account.education.get.queryOptions({
+ enabled: educationEnabled,
+ select: ({ is_student }) => is_student ?? false,
+ }),
+ )
+ const canManageBilling = useAtomValue(isCurrentWorkspaceManagerAtom)
+ const isEducationDiscountEligible = educationEnabled && isEducationAccount
+ const defaultBillingInterval: BillingInterval =
+ canManageBilling && isEducationDiscountEligible ? 'year' : 'month'
+ const [activeCategory, setActiveCategory] = React.useState<'cloud' | 'self-hosted'>('cloud')
+ const [selectedBillingInterval, setSelectedBillingInterval] = React.useState<BillingInterval>()
+ const billingInterval = selectedBillingInterval ?? defaultBillingInterval
+ const isCloud = activeCategory === 'cloud'
+ const currentCloudPlan = features?.billing.subscription.plan ?? 'sandbox'
+
+ return (
+ <Tabs
+ defaultValue="cloud"
+ onValueChange={setActiveCategory}
+ className="relative grid min-h-full grid-rows-[1fr_auto_auto_1fr] overflow-hidden"
+ >
+ <div className="absolute inset-x-0 -top-12 -z-10">
+ <NoiseTop />
+ </div>
+
+ <Header />
+
+ <div className="flex w-full justify-center border-t border-divider-accent px-10">
+ <div className="flex max-w-[1680px] grow items-center justify-between border-x border-divider-accent p-1">
+ <TabsList
+ activateOnFocus
+ aria-label={t(($) => $['plansCommon.title.plans'], { ns: 'billing' })}
+ className="items-center gap-0"
+ >
+ <TabsTab
+ value="cloud"
+ className="appearance-none justify-center gap-x-2 border-b-0 px-5 py-3 outline-hidden data-active:border-transparent"
+ render={(props, { active }) => (
+ <button {...props}>
+ <Cloud isActive={active} />
+ <span
+ className={cn(
+ 'system-xl-semibold text-text-secondary',
+ active && 'text-saas-dify-blue-accessible',
+ )}
+ >
+ {t(($) => $['plansCommon.cloud'], { ns: 'billing' })}
+ </span>
+ </button>
+ )}
+ />
+ <Divider type="vertical" className="mx-2 h-4 bg-divider-accent" />
+ <TabsTab
+ value="self-hosted"
+ className="appearance-none justify-center gap-x-2 border-b-0 px-5 py-3 outline-hidden data-active:border-transparent"
+ render={(props, { active }) => (
+ <button {...props}>
+ <SelfHosted isActive={active} />
+ <span
+ className={cn(
+ 'system-xl-semibold text-text-secondary',
+ active && 'text-saas-dify-blue-accessible',
+ )}
+ >
+ {t(($) => $['plansCommon.self'], { ns: 'billing' })}
+ </span>
+ </button>
+ )}
+ />
+ </TabsList>
+ {isCloud && (
+ <div className="flex items-center justify-end gap-x-3 pr-5">
+ <Switch
+ aria-label={t(($) => $['plansCommon.yearlyBilling'], { ns: 'billing' })}
+ size="lg"
+ checked={billingInterval === 'year'}
+ onCheckedChange={(checked) =>
+ setSelectedBillingInterval(checked ? 'year' : 'month')
+ }
+ />
+ <span className="system-md-regular text-text-tertiary">
+ {t(($) => $['plansCommon.annualBilling'], { ns: 'billing', percent: 17 })}
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
+
+ <div className="flex w-full justify-center border-t border-divider-accent px-10">
+ <TabsPanel
+ value="cloud"
+ className="flex max-w-[1680px] grow border-x border-divider-accent"
+ >
+ <CloudPlanItem
+ currentPlan={currentCloudPlan}
+ plan="sandbox"
+ billingInterval={billingInterval}
+ isEducationDiscountEligible={isEducationDiscountEligible}
+ />
+ <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
+ <CloudPlanItem
+ currentPlan={currentCloudPlan}
+ plan="professional"
+ billingInterval={billingInterval}
+ isEducationDiscountEligible={isEducationDiscountEligible}
+ />
+ <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
+ <CloudPlanItem
+ currentPlan={currentCloudPlan}
+ plan="team"
+ billingInterval={billingInterval}
+ isEducationDiscountEligible={isEducationDiscountEligible}
+ />
+ </TabsPanel>
+ <TabsPanel
+ value="self-hosted"
+ className="flex max-w-[1680px] grow border-x border-divider-accent"
+ >
+ <SelfHostedPlanItem plan="community" />
+ <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
+ <SelfHostedPlanItem plan="premium" />
+ <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
+ <SelfHostedPlanItem plan="enterprise" />
+ </TabsPanel>
+ </div>
+
+ <PricingFooter pricingPageURL={pricingPageURL} category={activeCategory} />
+
+ <div className="absolute inset-x-0 -bottom-12 -z-10">
+ <NoiseBottom />
+ </div>
+ </Tabs>
+ )
+}
diff --git a/web/app/components/billing/pricing/footer.tsx b/web/app/components/billing/pricing/footer.tsx
index bedbd89b664..4d7464724ec 100644
--- a/web/app/components/billing/pricing/footer.tsx
+++ b/web/app/components/billing/pricing/footer.tsx
@@ -1,27 +1,22 @@
-import type { Category } from './types'
-import { cn } from '@langgenius/dify-ui/cn'
-import * as React from 'react'
import { useTranslation } from 'react-i18next'
import Link from '@/next/link'
-import { CategoryEnum } from './types'
-type FooterProps = {
+export function PricingFooter({
+ pricingPageURL,
+ category,
+}: {
pricingPageURL: string
- currentCategory: Category
-}
-
-const Footer = ({ pricingPageURL, currentCategory }: FooterProps) => {
+ category: 'cloud' | 'self-hosted'
+}) {
const { t } = useTranslation()
return (
<div className="flex min-h-16 w-full justify-center border-t border-divider-accent px-10">
<div
- className={cn(
- 'flex max-w-[1680px] grow border-x border-divider-accent p-6',
- currentCategory === CategoryEnum.CLOUD ? 'justify-between' : 'justify-end',
- )}
+ data-category={category}
+ className="flex max-w-[1680px] grow justify-end border-x border-divider-accent p-6 data-[category=cloud]:justify-between"
>
- {currentCategory === CategoryEnum.CLOUD && (
+ {category === 'cloud' && (
<div className="flex flex-col text-text-tertiary">
<span className="system-xs-regular">
{t(($) => $['plansCommon.taxTip'], { ns: 'billing' })}
@@ -43,5 +38,3 @@ const Footer = ({ pricingPageURL, currentCategory }: FooterProps) => {
</div>
)
}
-
-export default React.memo(Footer)
diff --git a/web/app/components/billing/pricing/index.tsx b/web/app/components/billing/pricing/index.tsx
index 450e07e3482..4975bf3c55b 100644
--- a/web/app/components/billing/pricing/index.tsx
+++ b/web/app/components/billing/pricing/index.tsx
@@ -1,6 +1,4 @@
'use client'
-import type { FC } from 'react'
-import type { Category } from './types'
import { Dialog, DialogClose, DialogContent } from '@langgenius/dify-ui/dialog'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import {
@@ -11,44 +9,13 @@ import {
ScrollAreaThumb,
ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
-import { useQuery } from '@tanstack/react-query'
-import { useAtomValue } from 'jotai'
import * as React from 'react'
-import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useGetPricingPageLanguage } from '@/context/i18n'
-import { useProviderContext } from '@/context/provider-context'
-import { isCurrentWorkspaceManagerAtom } from '@/context/workspace-state'
-import { consoleQuery } from '@/service/client'
-import { NoiseBottom, NoiseTop } from './assets'
-import Footer from './footer'
-import Header from './header'
-import PlanSwitcher from './plan-switcher'
-import { PlanRange } from './plan-switcher/plan-range-switcher'
-import Plans from './plans'
-import { CategoryEnum } from './types'
+import { PricingContent } from './content'
-type PricingProps = {
- onCancel: () => void
-}
-
-const Pricing: FC<PricingProps> = ({ onCancel }) => {
+export function Pricing({ onCancel }: { onCancel: () => void }) {
const { t } = useTranslation()
- const { plan, enableEducationPlan } = useProviderContext()
- const { data: isEducationAccount = false } = useQuery(
- consoleQuery.account.education.get.queryOptions({
- enabled: enableEducationPlan,
- select: ({ is_student }) => is_student ?? false,
- }),
- )
- const isCurrentWorkspaceManager = useAtomValue(isCurrentWorkspaceManagerAtom)
- const shouldDefaultToYearly =
- isCurrentWorkspaceManager && enableEducationPlan && isEducationAccount
- const [selectedPlanRange, setSelectedPlanRange] = React.useState<PlanRange>()
- const planRange =
- selectedPlanRange ?? (shouldDefaultToYearly ? PlanRange.yearly : PlanRange.monthly)
- const [currentCategory, setCurrentCategory] = useState<Category>(CategoryEnum.CLOUD)
-
const pricingPageLanguage = useGetPricingPageLanguage()
const pricingPageURL = pricingPageLanguage
? `https://dify.ai/${pricingPageLanguage}/pricing#plans-and-features`
@@ -77,35 +44,14 @@ const Pricing: FC<PricingProps> = ({ onCancel }) => {
<ScrollArea className="h-full w-full overflow-hidden">
<ScrollAreaViewport className="overscroll-contain">
<ScrollAreaContent className="min-h-full min-w-300">
- <div className="relative grid min-h-full grid-rows-[1fr_auto_auto_1fr] overflow-hidden">
- <div className="absolute inset-x-0 -top-12 -z-10">
- <NoiseTop />
- </div>
- <Header />
- <PlanSwitcher
- currentCategory={currentCategory}
- onChangeCategory={setCurrentCategory}
- currentPlanRange={planRange}
- onChangePlanRange={setSelectedPlanRange}
- />
- <Plans
- plan={plan}
- currentPlan={currentCategory}
- planRange={planRange}
- canPay={isCurrentWorkspaceManager}
- />
- <Footer pricingPageURL={pricingPageURL} currentCategory={currentCategory} />
- <div className="absolute inset-x-0 -bottom-12 -z-10">
- <NoiseBottom />
- </div>
- </div>
+ <PricingContent pricingPageURL={pricingPageURL} />
</ScrollAreaContent>
</ScrollAreaViewport>
<ScrollAreaScrollbar>
- <ScrollAreaThumb className="rounded-full" />
+ <ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaScrollbar orientation="horizontal">
- <ScrollAreaThumb className="rounded-full" />
+ <ScrollAreaThumb />
</ScrollAreaScrollbar>
<ScrollAreaCorner className="bg-saas-background" />
</ScrollArea>
@@ -113,4 +59,3 @@ const Pricing: FC<PricingProps> = ({ onCancel }) => {
</Dialog>
)
}
-export default React.memo(Pricing)
diff --git a/web/app/components/billing/pricing/plan-switcher/index.tsx b/web/app/components/billing/pricing/plan-switcher/index.tsx
deleted file mode 100644
index 0e75b4b8ba6..00000000000
--- a/web/app/components/billing/pricing/plan-switcher/index.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import type { FC } from 'react'
-import type { Category } from '../types'
-import type { PlanRange } from './plan-range-switcher'
-import * as React from 'react'
-import { useTranslation } from 'react-i18next'
-import Divider from '@/app/components/base/divider'
-import { Cloud, SelfHosted } from '../assets'
-import PlanRangeSwitcher from './plan-range-switcher'
-import Tab from './tab'
-
-type PlanSwitcherProps = {
- currentCategory: Category
- currentPlanRange: PlanRange
- onChangeCategory: (category: Category) => void
- onChangePlanRange: (value: PlanRange) => void
-}
-
-const PlanSwitcher: FC<PlanSwitcherProps> = ({
- currentCategory,
- currentPlanRange,
- onChangeCategory,
- onChangePlanRange,
-}) => {
- const { t } = useTranslation()
- const isCloud = currentCategory === 'cloud'
-
- const tabs = {
- cloud: {
- value: 'cloud' as Category,
- label: t(($) => $['plansCommon.cloud'], { ns: 'billing' }),
- Icon: Cloud,
- },
- self: {
- value: 'self' as Category,
- label: t(($) => $['plansCommon.self'], { ns: 'billing' }),
- Icon: SelfHosted,
- },
- }
-
- return (
- <div className="flex w-full justify-center border-t border-divider-accent px-10">
- <div className="flex max-w-[1680px] grow items-center justify-between border-x border-divider-accent p-1">
- <div className="flex items-center">
- <Tab<Category>
- {...tabs.cloud}
- isActive={currentCategory === tabs.cloud.value}
- onClick={onChangeCategory}
- />
- <Divider type="vertical" className="mx-2 h-4 bg-divider-accent" />
- <Tab<Category>
- {...tabs.self}
- isActive={currentCategory === tabs.self.value}
- onClick={onChangeCategory}
- />
- </div>
- {isCloud && <PlanRangeSwitcher value={currentPlanRange} onChange={onChangePlanRange} />}
- </div>
- </div>
- )
-}
-
-export default React.memo(PlanSwitcher)
diff --git a/web/app/components/billing/pricing/plan-switcher/plan-range-switcher.tsx b/web/app/components/billing/pricing/plan-switcher/plan-range-switcher.tsx
deleted file mode 100644
index 8a210f17929..00000000000
--- a/web/app/components/billing/pricing/plan-switcher/plan-range-switcher.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-'use client'
-import { Switch } from '@langgenius/dify-ui/switch'
-import * as React from 'react'
-import { useTranslation } from 'react-i18next'
-
-export enum PlanRange {
- monthly = 'monthly',
- yearly = 'yearly',
-}
-
-type PlanRangeSwitcherProps = {
- value: PlanRange
- onChange: (value: PlanRange) => void
-}
-
-function PlanRangeSwitcher({ value, onChange }: PlanRangeSwitcherProps) {
- const { t } = useTranslation()
-
- return (
- <div className="flex items-center justify-end gap-x-3 pr-5">
- <Switch
- aria-label={t(($) => $['plansCommon.yearlyBilling'], { ns: 'billing' })}
- size="lg"
- checked={value === PlanRange.yearly}
- onCheckedChange={(v) => {
- onChange(v ? PlanRange.yearly : PlanRange.monthly)
- }}
- />
- <span className="system-md-regular text-text-tertiary">
- {t(($) => $['plansCommon.annualBilling'], { ns: 'billing', percent: 17 })}
- </span>
- </div>
- )
-}
-export default React.memo(PlanRangeSwitcher)
diff --git a/web/app/components/billing/pricing/plan-switcher/tab.tsx b/web/app/components/billing/pricing/plan-switcher/tab.tsx
deleted file mode 100644
index 318f501482d..00000000000
--- a/web/app/components/billing/pricing/plan-switcher/tab.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import { cn } from '@langgenius/dify-ui/cn'
-import * as React from 'react'
-import { useCallback } from 'react'
-
-type TabProps<T> = {
- Icon: React.ComponentType<{ isActive: boolean }>
- value: T
- label: string
- isActive: boolean
- onClick: (value: T) => void
-}
-
-const Tab = <T,>({ Icon, value, label, isActive, onClick }: TabProps<T>) => {
- const handleClick = useCallback(() => {
- onClick(value)
- }, [onClick, value])
-
- return (
- <button
- type="button"
- aria-pressed={isActive}
- className="flex cursor-pointer appearance-none items-center justify-center gap-x-2 px-5 py-3 outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid"
- onClick={handleClick}
- >
- <Icon isActive={isActive} />
- <span
- className={cn(
- 'system-xl-semibold text-text-secondary',
- isActive && 'text-saas-dify-blue-accessible',
- )}
- >
- {label}
- </span>
- </button>
- )
-}
-
-export default React.memo(Tab) as typeof Tab
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/button.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/button.tsx
deleted file mode 100644
index f1fa81c93ae..00000000000
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/button.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
-import { cn } from '@langgenius/dify-ui/cn'
-import * as React from 'react'
-
-const BUTTON_CLASSNAME = {
- sandbox: {
- btnClassname:
- 'bg-components-button-tertiary-bg hover:bg-components-button-tertiary-bg-hover text-text-primary',
- btnDisabledClassname:
- 'bg-components-button-tertiary-bg-disabled hover:bg-components-button-tertiary-bg-disabled text-text-disabled',
- },
- professional: {
- btnClassname:
- 'bg-saas-dify-blue-static hover:bg-saas-dify-blue-static-hover text-text-primary-on-surface',
- btnDisabledClassname:
- 'bg-components-button-tertiary-bg-disabled hover:bg-components-button-tertiary-bg-disabled text-text-disabled',
- },
- team: {
- btnClassname:
- 'bg-saas-background-inverted hover:bg-saas-background-inverted-hover text-background-default',
- btnDisabledClassname:
- 'bg-components-button-tertiary-bg-disabled hover:bg-components-button-tertiary-bg-disabled text-text-disabled',
- },
-}
-
-type ButtonProps = {
- plan: CloudPlan
- isPlanDisabled: boolean
- btnText: string
- handleGetPayUrl: () => void
- warningText?: string
-}
-
-const Button = ({ plan, isPlanDisabled, btnText, handleGetPayUrl, warningText }: ButtonProps) => {
- return (
- <div className="relative">
- <button
- type="button"
- disabled={isPlanDisabled}
- className={cn(
- 'flex w-full items-center gap-x-2 py-3 pr-4 pl-5 system-xl-semibold',
- BUTTON_CLASSNAME[plan].btnClassname,
- isPlanDisabled && BUTTON_CLASSNAME[plan].btnDisabledClassname,
- isPlanDisabled && 'cursor-not-allowed',
- )}
- onClick={handleGetPayUrl}
- >
- <span className="grow text-start">{btnText}</span>
- {!isPlanDisabled && <span className="i-ri-arrow-right-line size-5 shrink-0" />}
- </button>
- {warningText && (
- <div className="absolute inset-x-0 top-full mt-1.5 text-left system-2xs-medium text-text-tertiary">
- {warningText}
- </div>
- )}
- </div>
- )
-}
-
-export default React.memo(Button)
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
index 684e27dd4db..15800b60505 100644
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
+++ b/web/app/components/billing/pricing/plans/cloud-plan-item/index.tsx
@@ -1,6 +1,6 @@
'use client'
+import type { GetBillingSubscriptionData } from '@dify/contracts/api/console/billing/types.gen'
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
-import type { FC } from 'react'
import { Button } from '@langgenius/dify-ui/button'
import {
Dialog,
@@ -11,19 +11,18 @@ import {
} from '@langgenius/dify-ui/dialog'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { toast } from '@langgenius/dify-ui/toast'
-import { useQuery } from '@tanstack/react-query'
+import { useAtomValue } from 'jotai'
import * as React from 'react'
-import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
-import { useProviderContext } from '@/context/provider-context'
+import { isCurrentWorkspaceManagerAtom } from '@/context/workspace-state'
import { useAsyncWindowOpen } from '@/hooks/use-async-window-open'
-import { consoleClient, consoleQuery } from '@/service/client'
+import { consoleClient } from '@/service/client'
import { ALL_PLANS } from '../../../config'
import { useEducationDiscount } from '../../../hooks/use-education-discount'
-import { Professional, Sandbox, Team } from '../../assets'
-import { PlanRange } from '../../plan-switcher/plan-range-switcher'
-import PlanButton from './button'
-import List from './list'
+import Professional from '../../assets/professional'
+import Sandbox from '../../assets/sandbox'
+import Team from '../../assets/team'
+import { CloudPlanFeatures } from './list'
const ICON_MAP = {
sandbox: <Sandbox />,
@@ -34,68 +33,70 @@ const ICON_MAP = {
type CloudPlanItemProps = {
currentPlan: CloudPlan
plan: CloudPlan
- planRange: PlanRange
- canPay: boolean
+ billingInterval: GetBillingSubscriptionData['query']['interval']
+ isEducationDiscountEligible: boolean
}
-const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, canPay }) => {
+export function CloudPlanItem({
+ plan,
+ currentPlan,
+ billingInterval,
+ isEducationDiscountEligible,
+}: CloudPlanItemProps) {
const { t } = useTranslation()
- const [loading, setLoading] = React.useState(false)
+ const canManageBilling = useAtomValue(isCurrentWorkspaceManagerAtom)
+ const [isPlanActionPending, setIsPlanActionPending] = React.useState(false)
+ const isYearly = billingInterval === 'year'
const i18nPrefix = `plans.${plan}` as const
const isFreePlan = plan === 'sandbox'
const isMostPopularPlan = plan === 'professional'
const planInfo = ALL_PLANS[plan]
- const isYear = planRange === PlanRange.yearly
const isCurrent = plan === currentPlan
const isCurrentPaidPlan = isCurrent && !isFreePlan
const isPlanDisabled = isCurrentPaidPlan ? false : planInfo.level <= ALL_PLANS[currentPlan].level
- const { enableEducationPlan } = useProviderContext()
- const { data: isEducationAccount = false } = useQuery(
- consoleQuery.account.education.get.queryOptions({
- enabled: enableEducationPlan,
- select: ({ is_student }) => is_student ?? false,
- }),
- )
- const isEducationDiscountMode = enableEducationPlan && isEducationAccount
- const isEducationDiscountSupportedPlan = plan === 'professional' && isYear
+ const isEducationDiscountSupportedPlan = plan === 'professional' && isYearly
const educationDiscountWarningText =
- canPay && isEducationDiscountMode && !isFreePlan && !isEducationDiscountSupportedPlan
+ canManageBilling &&
+ isEducationDiscountEligible &&
+ !isFreePlan &&
+ !isEducationDiscountSupportedPlan
? t(($) => $.planNotSupportEducationDiscount, { ns: 'education' })
: undefined
const openAsyncWindow = useAsyncWindowOpen()
const { handleEducationDiscount, isEducationDiscountLoading } = useEducationDiscount()
const [showEducationPricingConfirm, setShowEducationPricingConfirm] = React.useState(false)
- const btnText = useMemo(() => {
- if (canPay && isEducationDiscountMode && isEducationDiscountSupportedPlan && !isCurrent)
- return t(($) => $.useEducationDiscount, { ns: 'education' })
-
- if (isCurrent) return t(($) => $['plansCommon.currentPlan'], { ns: 'billing' })
+ const buttonLabel =
+ canManageBilling &&
+ isEducationDiscountEligible &&
+ isEducationDiscountSupportedPlan &&
+ !isCurrent
+ ? t(($) => $.useEducationDiscount, { ns: 'education' })
+ : isCurrent
+ ? t(($) => $['plansCommon.currentPlan'], { ns: 'billing' })
+ : {
+ sandbox: t(($) => $['plansCommon.startForFree'], { ns: 'billing' }),
+ professional: t(($) => $['plansCommon.startBuilding'], { ns: 'billing' }),
+ team: t(($) => $['plansCommon.getStarted'], { ns: 'billing' }),
+ }[plan]
- return {
- sandbox: t(($) => $['plansCommon.startForFree'], { ns: 'billing' }),
- professional: t(($) => $['plansCommon.startBuilding'], { ns: 'billing' }),
- team: t(($) => $['plansCommon.getStarted'], { ns: 'billing' }),
- }[plan]
- }, [canPay, isCurrent, isEducationDiscountMode, isEducationDiscountSupportedPlan, plan, t])
-
- const handlePayCurrentPlan = async () => {
- if (loading || isEducationDiscountLoading) return
+ const runPlanAction = async () => {
+ if (isPlanActionPending || isEducationDiscountLoading) return
if (isPlanDisabled) return
- setLoading(true)
+ setIsPlanActionPending(true)
try {
if (isCurrentPaidPlan) {
- if (!canPay) {
+ if (!canManageBilling) {
toast.error(t(($) => $.buyPermissionDeniedTip, { ns: 'billing' }))
return
}
await openAsyncWindow(
async () => {
- const res = await consoleClient.billing.invoices.get()
- if (res.url) return res.url
+ const { url } = await consoleClient.billing.invoices.get()
+ if (url) return url
throw new Error('Failed to open billing page')
},
{
@@ -109,38 +110,38 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
if (isFreePlan) return
- if (!canPay) {
+ if (!canManageBilling) {
toast.error(t(($) => $.buyPermissionDeniedTip, { ns: 'billing' }))
return
}
- if (isEducationDiscountMode && isEducationDiscountSupportedPlan) {
+ if (isEducationDiscountEligible && isEducationDiscountSupportedPlan) {
await handleEducationDiscount()
return
}
- const res = await consoleClient.billing.subscription.get({
- query: { plan, interval: isYear ? 'year' : 'month' },
+ const { url } = await consoleClient.billing.subscription.get({
+ query: { plan, interval: billingInterval },
})
// Adb Block additional tracking block the gtag, so we need to redirect directly
- window.location.href = res.url
+ window.location.href = url
} finally {
- setLoading(false)
+ setIsPlanActionPending(false)
}
}
- const handleGetPayUrl = async () => {
+ const handlePlanButtonClick = async () => {
if (educationDiscountWarningText && !isPlanDisabled) {
setShowEducationPricingConfirm(true)
return
}
- await handlePayCurrentPlan()
+ await runPlanAction()
}
- const handleSwitchToProfessionalAnnual = async () => {
+ const handleUseEducationDiscount = async () => {
await handleEducationDiscount()
}
- const handleKeepCurrentPlan = async () => {
- await handlePayCurrentPlan()
+ const handleContinueWithoutEducationDiscount = async () => {
+ await runPlanAction()
setShowEducationPricingConfirm(false)
}
return (
@@ -150,9 +151,9 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
{ICON_MAP[plan]}
<div className="flex min-h-26 flex-col gap-y-2">
<div className="flex items-center gap-x-2.5">
- <div className="text-[30px] leading-[1.2] font-medium text-text-primary">
+ <h3 className="text-[30px] leading-[1.2] font-medium text-text-primary">
{t(($) => $[`${i18nPrefix}.name`], { ns: 'billing' })}
- </div>
+ </h3>
{isMostPopularPlan && (
<div className="flex items-center justify-center bg-saas-dify-blue-static px-1.5 py-1">
<span className="system-2xs-semibold-uppercase text-text-primary-on-surface">
@@ -175,30 +176,43 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
)}
{!isFreePlan && (
<>
- {isYear && (
+ {isYearly && (
<span className="title-4xl-semi-bold text-text-quaternary line-through">
${planInfo.price * 12}
</span>
)}
<span className="title-4xl-semi-bold text-text-primary">
- ${isYear ? planInfo.price * 10 : planInfo.price}
+ ${isYearly ? planInfo.price * 10 : planInfo.price}
</span>
<span className="pb-0.5 system-md-regular text-text-tertiary">
{t(($) => $['plansCommon.priceTip'], { ns: 'billing' })}
- {t(($) => $[`plansCommon.${!isYear ? 'month' : 'year'}`], { ns: 'billing' })}
+ {t(($) => $[`plansCommon.${isYearly ? 'year' : 'month'}`], { ns: 'billing' })}
</span>
</>
)}
</div>
- <PlanButton
- plan={plan}
- isPlanDisabled={isPlanDisabled}
- btnText={btnText}
- handleGetPayUrl={handleGetPayUrl}
- warningText={educationDiscountWarningText}
- />
+ <div className="relative">
+ <Button
+ data-plan={plan}
+ variant="tertiary"
+ size={null}
+ disabled={isPlanDisabled}
+ className="h-auto w-full justify-start gap-x-2 rounded-none bg-components-button-tertiary-bg py-3 pr-4 pl-5 system-xl-semibold text-text-primary hover:bg-components-button-tertiary-bg-hover data-disabled:bg-components-button-tertiary-bg-disabled data-disabled:text-text-disabled data-disabled:hover:bg-components-button-tertiary-bg-disabled data-[plan=professional]:bg-saas-dify-blue-static data-[plan=professional]:text-text-primary-on-surface data-[plan=professional]:hover:bg-saas-dify-blue-static-hover data-[plan=team]:bg-saas-background-inverted data-[plan=team]:text-background-default data-[plan=team]:hover:bg-saas-background-inverted-hover"
+ onClick={handlePlanButtonClick}
+ >
+ <span className="grow text-start">{buttonLabel}</span>
+ {!isPlanDisabled && (
+ <span aria-hidden className="i-ri-arrow-right-line size-5 shrink-0" />
+ )}
+ </Button>
+ {educationDiscountWarningText && (
+ <div className="absolute inset-x-0 top-full mt-1.5 text-left system-2xs-medium text-text-tertiary">
+ {educationDiscountWarningText}
+ </div>
+ )}
+ </div>
</div>
- <List plan={plan} />
+ <CloudPlanFeatures plan={plan} />
<Dialog open={showEducationPricingConfirm} onOpenChange={setShowEducationPricingConfirm}>
<DialogContent backdropProps={{ forceRender: true }} className="w-130">
<DialogClose
@@ -223,9 +237,9 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
<div className="mt-10 flex items-start justify-end gap-3">
<Button
size="large"
- onClick={handleKeepCurrentPlan}
- disabled={loading || isEducationDiscountLoading}
- loading={loading}
+ onClick={handleContinueWithoutEducationDiscount}
+ disabled={isEducationDiscountLoading}
+ loading={isPlanActionPending}
className="min-w-38"
>
{t(($) => $['educationPricingConfirm.cancel'], { ns: 'education' })}
@@ -233,8 +247,7 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
<Button
variant="primary"
size="large"
- onClick={handleSwitchToProfessionalAnnual}
- disabled={isEducationDiscountLoading}
+ onClick={handleUseEducationDiscount}
loading={isEducationDiscountLoading}
className="min-w-61"
>
@@ -246,4 +259,3 @@ const CloudPlanItem: FC<CloudPlanItemProps> = ({ plan, currentPlan, planRange, c
</div>
)
}
-export default React.memo(CloudPlanItem)
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/list/index.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/list/index.tsx
index 202c3faf096..45d35bb0a22 100644
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/list/index.tsx
+++ b/web/app/components/billing/pricing/plans/cloud-plan-item/list/index.tsx
@@ -1,22 +1,17 @@
import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
-import * as React from 'react'
import { useTranslation } from 'react-i18next'
import Divider from '@/app/components/base/divider'
import { ALL_PLANS, NUM_INFINITE } from '../../../../config'
-import Item from './item'
+import { CloudPlanFeature } from './item'
-type ListProps = {
- plan: CloudPlan
-}
-
-const List = ({ plan }: ListProps) => {
+export function CloudPlanFeatures({ plan }: { plan: CloudPlan }) {
const { t } = useTranslation()
const isFreePlan = plan === 'sandbox'
const planInfo = ALL_PLANS[plan]
return (
<div className="flex flex-col gap-y-2.5 p-6">
- <Item
+ <CloudPlanFeature
label={
isFreePlan
? t(($) => $['plansCommon.messageRequest.title'], {
@@ -28,43 +23,43 @@ const List = ({ plan }: ListProps) => {
count: planInfo.messageRequest,
})
}
- tooltip={t(($) => $['plansCommon.messageRequest.tooltip'], { ns: 'billing' }) as string}
+ description={t(($) => $['plansCommon.messageRequest.tooltip'], { ns: 'billing' }) as string}
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.teamWorkspace'], {
ns: 'billing',
count: planInfo.teamWorkspace,
})}
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.teamMember'], {
ns: 'billing',
count: planInfo.teamMembers,
})}
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.buildApps'], { ns: 'billing', count: planInfo.buildApps })}
/>
<Divider bgStyle="gradient" />
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.documents'], { ns: 'billing', count: planInfo.documents })}
- tooltip={t(($) => $['plansCommon.documentsTooltip'], { ns: 'billing' }) as string}
+ description={t(($) => $['plansCommon.documentsTooltip'], { ns: 'billing' }) as string}
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.vectorSpace'], {
ns: 'billing',
size: planInfo.vectorSpace,
})}
- tooltip={t(($) => $['plansCommon.vectorSpaceTooltip'], { ns: 'billing' }) as string}
+ description={t(($) => $['plansCommon.vectorSpaceTooltip'], { ns: 'billing' }) as string}
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.documentsRequestQuota'], {
ns: 'billing',
count: planInfo.documentsRequestQuota,
})}
- tooltip={t(($) => $['plansCommon.documentsRequestQuotaTooltip'], { ns: 'billing' })}
+ description={t(($) => $['plansCommon.documentsRequestQuotaTooltip'], { ns: 'billing' })}
/>
- <Item
+ <CloudPlanFeature
label={[
t(($) => $[`plansCommon.priority.${planInfo.documentProcessingPriority}`], {
ns: 'billing',
@@ -73,7 +68,7 @@ const List = ({ plan }: ListProps) => {
].join('')}
/>
<Divider bgStyle="gradient" />
- <Item
+ <CloudPlanFeature
label={
planInfo.triggerEvents === NUM_INFINITE
? t(($) => $['plansCommon.triggerEvents.unlimited'], { ns: 'billing' })
@@ -87,16 +82,16 @@ const List = ({ plan }: ListProps) => {
count: planInfo.triggerEvents,
})
}
- tooltip={t(($) => $['plansCommon.triggerEvents.tooltip'], { ns: 'billing' }) as string}
+ description={t(($) => $['plansCommon.triggerEvents.tooltip'], { ns: 'billing' }) as string}
/>
- <Item
+ <CloudPlanFeature
label={
plan === 'sandbox'
? t(($) => $['plansCommon.startNodes.limited'], { ns: 'billing', count: 2 })
: t(($) => $['plansCommon.startNodes.unlimited'], { ns: 'billing' })
}
/>
- <Item
+ <CloudPlanFeature
label={
plan === 'sandbox'
? t(($) => $['plansCommon.workflowExecution.standard'], { ns: 'billing' })
@@ -104,17 +99,21 @@ const List = ({ plan }: ListProps) => {
? t(($) => $['plansCommon.workflowExecution.faster'], { ns: 'billing' })
: t(($) => $['plansCommon.workflowExecution.priority'], { ns: 'billing' })
}
- tooltip={t(($) => $['plansCommon.workflowExecution.tooltip'], { ns: 'billing' }) as string}
+ description={
+ t(($) => $['plansCommon.workflowExecution.tooltip'], { ns: 'billing' }) as string
+ }
/>
<Divider bgStyle="gradient" />
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.annotatedResponse.title'], {
ns: 'billing',
count: planInfo.annotatedResponse,
})}
- tooltip={t(($) => $['plansCommon.annotatedResponse.tooltip'], { ns: 'billing' }) as string}
+ description={
+ t(($) => $['plansCommon.annotatedResponse.tooltip'], { ns: 'billing' }) as string
+ }
/>
- <Item
+ <CloudPlanFeature
label={t(($) => $['plansCommon.logsHistory'], {
ns: 'billing',
days:
@@ -123,22 +122,20 @@ const List = ({ plan }: ListProps) => {
: `${planInfo.logHistory} ${t(($) => $['plansCommon.days'], { ns: 'billing' })}`,
})}
/>
- <Item
+ <CloudPlanFeature
label={
planInfo.apiRateLimit === NUM_INFINITE
? t(($) => $['plansCommon.unlimitedApiRate'], { ns: 'billing' })
: `${t(($) => $['plansCommon.apiRateLimitUnit'], { ns: 'billing', count: planInfo.apiRateLimit })} ${t(($) => $['plansCommon.apiRateLimit'], { ns: 'billing' })}/${t(($) => $['plansCommon.month'], { ns: 'billing' })}`
}
- tooltip={
+ description={
planInfo.apiRateLimit === NUM_INFINITE
? undefined
: (t(($) => $['plansCommon.apiRateLimitTooltip'], { ns: 'billing' }) as string)
}
/>
<Divider bgStyle="gradient" />
- <Item label={t(($) => $['plansCommon.modelProviders'], { ns: 'billing' })} />
+ <CloudPlanFeature label={t(($) => $['plansCommon.modelProviders'], { ns: 'billing' })} />
</div>
)
}
-
-export default React.memo(List)
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/index.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/index.tsx
index 1789beca6b5..113bc874ce2 100644
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/index.tsx
+++ b/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/index.tsx
@@ -1,18 +1,10 @@
-import * as React from 'react'
-import Tooltip from './tooltip'
+import { PlanFeatureInfotip } from './infotip'
-type ItemProps = {
- label: string
- tooltip?: string
-}
-
-const Item = ({ label, tooltip }: ItemProps) => {
+export function CloudPlanFeature({ label, description }: { label: string; description?: string }) {
return (
<div className="flex items-center">
<span className="grow system-sm-regular text-text-secondary">{label}</span>
- {tooltip && <Tooltip content={tooltip} />}
+ {description && <PlanFeatureInfotip label={label} content={description} />}
</div>
)
}
-
-export default React.memo(Item)
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/infotip.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/infotip.tsx
new file mode 100644
index 00000000000..cc3728413ac
--- /dev/null
+++ b/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/infotip.tsx
@@ -0,0 +1,36 @@
+import { IconButton } from '@langgenius/dify-ui/icon-button'
+import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '@langgenius/dify-ui/popover'
+
+export function PlanFeatureInfotip({ label, content }: { label: string; content: string }) {
+ if (!content) return null
+
+ return (
+ <Popover>
+ <PopoverTrigger
+ openOnHover
+ delay={0}
+ closeDelay={0}
+ render={
+ <IconButton
+ aria-label={content}
+ variant="default"
+ size="xs"
+ className="group relative z-10 size-4.5 rounded-sm border-0 bg-state-base-hover p-0 transition-[border-radius,background-color] duration-500 ease-in-out hover:rounded-none hover:bg-saas-dify-blue-static data-popup-open:rounded-none data-popup-open:bg-saas-dify-blue-static motion-reduce:transition-none"
+ >
+ <span
+ aria-hidden
+ className="i-ri-info-i size-3.5 text-text-tertiary group-hover:text-text-primary-on-surface group-data-popup-open:text-text-primary-on-surface"
+ />
+ </IconButton>
+ }
+ />
+ <PopoverContent
+ placement="top-end"
+ className="w-[260px] rounded-none border-0 bg-saas-dify-blue-static px-5 py-[18px] system-xs-regular text-text-primary-on-surface shadow-none"
+ >
+ <PopoverTitle className="sr-only">{label}</PopoverTitle>
+ {content}
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/tooltip.tsx b/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/tooltip.tsx
deleted file mode 100644
index 3933e531153..00000000000
--- a/web/app/components/billing/pricing/plans/cloud-plan-item/list/item/tooltip.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import { Popover, PopoverContent, PopoverTrigger } from '@langgenius/dify-ui/popover'
-import { RiInfoI } from '@remixicon/react'
-import * as React from 'react'
-
-type TooltipProps = {
- content: string
-}
-
-const Tooltip = ({ content }: TooltipProps) => {
- if (!content) return null
- return (
- <Popover>
- <PopoverTrigger
- openOnHover
- delay={0}
- closeDelay={0}
- aria-label={content}
- className="group relative z-10 flex size-4.5 items-center justify-center rounded-sm border-0 bg-state-base-hover p-0 transition-[border-radius,background-color] duration-500 ease-in-out hover:rounded-none hover:bg-saas-dify-blue-static"
- >
- <RiInfoI className="size-3.5 text-text-tertiary group-hover:text-text-primary-on-surface" />
- </PopoverTrigger>
- <PopoverContent
- placement="top-end"
- className="w-[260px] rounded-none border-0 bg-saas-dify-blue-static px-5 py-[18px] system-xs-regular text-text-primary-on-surface shadow-none"
- >
- {content}
- </PopoverContent>
- </Popover>
- )
-}
-
-export default React.memo(Tooltip)
diff --git a/web/app/components/billing/pricing/plans/index.tsx b/web/app/components/billing/pricing/plans/index.tsx
deleted file mode 100644
index 05729710901..00000000000
--- a/web/app/components/billing/pricing/plans/index.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import type { CloudPlan } from '@dify/contracts/api/console/features/types.gen'
-import type { UsagePlanInfo } from '../../type'
-import type { PlanRange } from '../plan-switcher/plan-range-switcher'
-import Divider from '@/app/components/base/divider'
-import CloudPlanItem from './cloud-plan-item'
-import SelfHostedPlanItem from './self-hosted-plan-item'
-
-type PlansProps = {
- plan: {
- type: CloudPlan
- usage: UsagePlanInfo
- total: UsagePlanInfo
- }
- currentPlan: string
- planRange: PlanRange
- canPay: boolean
-}
-
-const Plans = ({ plan, currentPlan, planRange, canPay }: PlansProps) => {
- const currentPlanType = plan.type
- return (
- <div className="flex w-full justify-center border-t border-divider-accent px-10">
- <div className="flex max-w-[1680px] grow border-x border-divider-accent">
- {currentPlan === 'cloud' && (
- <>
- <CloudPlanItem
- currentPlan={currentPlanType}
- plan="sandbox"
- planRange={planRange}
- canPay={canPay}
- />
- <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
- <CloudPlanItem
- currentPlan={currentPlanType}
- plan="professional"
- planRange={planRange}
- canPay={canPay}
- />
- <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
- <CloudPlanItem
- currentPlan={currentPlanType}
- plan="team"
- planRange={planRange}
- canPay={canPay}
- />
- </>
- )}
- {currentPlan === 'self' && (
- <>
- <SelfHostedPlanItem plan="community" />
- <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
- <SelfHostedPlanItem plan="premium" />
- <Divider type="vertical" className="mx-0 shrink-0 bg-divider-accent" />
- <SelfHostedPlanItem plan="enterprise" />
- </>
- )}
- </div>
- </div>
- )
-}
-
-export default Plans
diff --git a/web/app/components/billing/pricing/plans/self-hosted-plan-item/button.tsx b/web/app/components/billing/pricing/plans/self-hosted-plan-item/button.tsx
deleted file mode 100644
index f3db901fad0..00000000000
--- a/web/app/components/billing/pricing/plans/self-hosted-plan-item/button.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import type { SelfHostedPlanOption } from './types'
-import { cn } from '@langgenius/dify-ui/cn'
-import { RiArrowRightLine } from '@remixicon/react'
-import * as React from 'react'
-import { useMemo } from 'react'
-import { useTranslation } from 'react-i18next'
-import {
- AwsMarketplaceDark,
- AwsMarketplaceLight,
-} from '@/app/components/base/icons/src/public/billing'
-import useTheme from '@/hooks/use-theme'
-import { Theme } from '@/types/app'
-
-const BUTTON_CLASSNAME = {
- community:
- 'text-text-primary bg-components-button-tertiary-bg hover:bg-components-button-tertiary-bg-hover',
- premium:
- 'text-background-default bg-saas-background-inverted hover:bg-saas-background-inverted-hover',
- enterprise:
- 'text-text-primary-on-surface bg-saas-dify-blue-static hover:bg-saas-dify-blue-static-hover',
-}
-
-type ButtonProps = {
- plan: SelfHostedPlanOption
- handleGetPayUrl: () => void
-}
-
-const Button = ({ plan, handleGetPayUrl }: ButtonProps) => {
- const { t } = useTranslation()
- const { theme } = useTheme()
- const i18nPrefix = `plans.${plan}` as const
- const isPremiumPlan = plan === 'premium'
- const AwsMarketplace = useMemo(() => {
- return theme === Theme.light ? AwsMarketplaceLight : AwsMarketplaceDark
- }, [theme])
-
- return (
- <button
- type="button"
- className={cn(
- 'flex items-center gap-x-2 py-3 pr-4 pl-5 system-xl-semibold',
- BUTTON_CLASSNAME[plan],
- isPremiumPlan && 'py-2',
- )}
- onClick={handleGetPayUrl}
- >
- <div className="flex grow items-center gap-x-2">
- <span>{t(($) => $[`${i18nPrefix}.btnText`], { ns: 'billing' })}</span>
- {isPremiumPlan && (
- <span className="pt-1.75 pb-px">
- <AwsMarketplace className="h-6" />
- </span>
- )}
- </div>
- <RiArrowRightLine className="size-5 shrink-0" />
- </button>
- )
-}
-
-export default React.memo(Button)
diff --git a/web/app/components/billing/pricing/plans/self-hosted-plan-item/index.tsx b/web/app/components/billing/pricing/plans/self-hosted-plan-item/index.tsx
index a0c4d1321d1..cadc5f703a2 100644
--- a/web/app/components/billing/pricing/plans/self-hosted-plan-item/index.tsx
+++ b/web/app/components/billing/pricing/plans/self-hosted-plan-item/index.tsx
@@ -1,15 +1,19 @@
'use client'
-import type { FC } from 'react'
-import type { SelfHostedPlanOption } from './types'
+import type { SelfHostedPlan } from '../../../config'
+import { buttonVariants } from '@langgenius/dify-ui/button'
import { cn } from '@langgenius/dify-ui/cn'
-import * as React from 'react'
-import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
-import { Azure, GoogleCloud } from '@/app/components/base/icons/src/public/billing'
-import { contactSalesUrl, getStartedWithCommunityUrl, getWithPremiumUrl } from '../../../config'
-import { Community, Enterprise, EnterpriseNoise, Premium, PremiumNoise } from '../../assets'
-import Button from './button'
-import List from './list'
+import AwsMarketplaceDark from '@/app/components/base/icons/src/public/billing/AwsMarketplaceDark'
+import AwsMarketplaceLight from '@/app/components/base/icons/src/public/billing/AwsMarketplaceLight'
+import useTheme from '@/hooks/use-theme'
+import { Theme } from '@/types/app'
+import { SELF_HOSTED_PLAN_URLS } from '../../../config'
+import Community from '../../assets/community'
+import Enterprise from '../../assets/enterprise'
+import EnterpriseNoise from '../../assets/enterprise-noise'
+import Premium from '../../assets/premium'
+import PremiumNoise from '../../assets/premium-noise'
+import { SelfHostedPlanFeatures } from './list'
const STYLE_MAP = {
community: {
@@ -37,29 +41,12 @@ const STYLE_MAP = {
},
}
-type SelfHostedPlanItemProps = {
- plan: SelfHostedPlanOption
-}
-
-const SelfHostedPlanItem: FC<SelfHostedPlanItemProps> = ({ plan }) => {
+export function SelfHostedPlanItem({ plan }: { plan: SelfHostedPlan }) {
const { t } = useTranslation()
+ const { theme } = useTheme()
const i18nPrefix = `plans.${plan}` as const
const isFreePlan = plan === 'community'
const isPremiumPlan = plan === 'premium'
- const isEnterprisePlan = plan === 'enterprise'
-
- const handleGetPayUrl = useCallback(() => {
- if (isFreePlan) {
- window.location.href = getStartedWithCommunityUrl
- return
- }
- if (isPremiumPlan) {
- window.location.href = getWithPremiumUrl
- return
- }
-
- if (isEnterprisePlan) window.location.href = contactSalesUrl
- }, [isFreePlan, isPremiumPlan, isEnterprisePlan])
return (
<div className="relative flex flex-1 flex-col overflow-hidden">
@@ -70,9 +57,9 @@ const SelfHostedPlanItem: FC<SelfHostedPlanItemProps> = ({ plan }) => {
<div className="flex flex-col gap-y-6 px-1 pt-10">
{STYLE_MAP[plan].icon}
<div className="flex min-h-26 flex-col gap-y-2">
- <div className="text-[30px] leading-[1.2] font-medium text-text-primary">
+ <h3 className="text-[30px] leading-[1.2] font-medium text-text-primary">
{t(($) => $[`${i18nPrefix}.name`], { ns: 'billing' })}
- </div>
+ </h3>
<div className="line-clamp-2 system-md-regular text-text-secondary">
{t(($) => $[`${i18nPrefix}.description`], { ns: 'billing' })}
</div>
@@ -89,17 +76,41 @@ const SelfHostedPlanItem: FC<SelfHostedPlanItemProps> = ({ plan }) => {
</span>
)}
</div>
- <Button plan={plan} handleGetPayUrl={handleGetPayUrl} />
+ <a
+ href={SELF_HOSTED_PLAN_URLS[plan]}
+ data-plan={plan}
+ className={cn(
+ buttonVariants({ variant: 'tertiary', size: null }),
+ 'h-12 w-full justify-start gap-x-2 rounded-none bg-components-button-tertiary-bg py-3 pr-4 pl-5 system-xl-semibold text-text-primary hover:bg-components-button-tertiary-bg-hover data-[plan=enterprise]:bg-saas-dify-blue-static data-[plan=enterprise]:text-text-primary-on-surface data-[plan=enterprise]:hover:bg-saas-dify-blue-static-hover data-[plan=premium]:bg-saas-background-inverted data-[plan=premium]:py-2 data-[plan=premium]:text-background-default data-[plan=premium]:hover:bg-saas-background-inverted-hover',
+ )}
+ >
+ <span className="flex grow items-center gap-x-2">
+ <span>{t(($) => $[`${i18nPrefix}.btnText`], { ns: 'billing' })}</span>
+ {isPremiumPlan && (
+ <span aria-hidden className="pt-1.75 pb-px">
+ {theme === Theme.light ? (
+ <AwsMarketplaceLight className="h-6" />
+ ) : (
+ <AwsMarketplaceDark className="h-6" />
+ )}
+ </span>
+ )}
+ </span>
+ <span aria-hidden className="i-ri-arrow-right-line size-5 shrink-0" />
+ </a>
</div>
- <List plan={plan} />
+ <SelfHostedPlanFeatures plan={plan} />
{isPremiumPlan && (
<div className="flex grow flex-col justify-end gap-y-2 p-6 pt-0">
<div className="flex items-center gap-x-1">
<div className="flex size-8 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border-subtle bg-background-default shadow-xs shadow-shadow-shadow-3">
- <Azure />
+ <span aria-hidden className="i-custom-public-billing-azure h-5 w-[21px]" />
</div>
<div className="flex size-8 items-center justify-center rounded-lg border-[0.5px] border-components-panel-border-subtle bg-background-default shadow-xs shadow-shadow-shadow-3">
- <GoogleCloud />
+ <span
+ aria-hidden
+ className="i-custom-public-billing-google-cloud h-[18px] w-[22px]"
+ />
</div>
</div>
<span className="system-xs-regular text-text-tertiary">
@@ -110,4 +121,3 @@ const SelfHostedPlanItem: FC<SelfHostedPlanItemProps> = ({ plan }) => {
</div>
)
}
-export default React.memo(SelfHostedPlanItem)
diff --git a/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/index.tsx b/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/index.tsx
index 189531ce63c..b6ccaafce39 100644
--- a/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/index.tsx
+++ b/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/index.tsx
@@ -1,13 +1,8 @@
-import type { SelfHostedPlanOption } from '../types'
-import * as React from 'react'
+import type { SelfHostedPlan } from '@/app/components/billing/config'
import { Trans, useTranslation } from 'react-i18next'
-import Item from './item'
+import { SelfHostedPlanFeature } from './item'
-type ListProps = {
- plan: SelfHostedPlanOption
-}
-
-const List = ({ plan }: ListProps) => {
+export function SelfHostedPlanFeatures({ plan }: { plan: SelfHostedPlan }) {
const { t } = useTranslation()
const i18nPrefix = `plans.${plan}` as const
const features = t(($) => $[`${i18nPrefix}.features`], {
@@ -25,10 +20,8 @@ const List = ({ plan }: ListProps) => {
/>
</div>
{features.map((feature) => (
- <Item key={`${plan}-${feature}`} label={feature} />
+ <SelfHostedPlanFeature key={`${plan}-${feature}`} label={feature} />
))}
</div>
)
}
-
-export default React.memo(List)
diff --git a/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/item.tsx b/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/item.tsx
index b360f0b6754..ec39a543ca0 100644
--- a/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/item.tsx
+++ b/web/app/components/billing/pricing/plans/self-hosted-plan-item/list/item.tsx
@@ -1,19 +1,10 @@
-import { RiCheckLine } from '@remixicon/react'
-import * as React from 'react'
-
-type ItemProps = {
- label: string
-}
-
-const Item = ({ label }: ItemProps) => {
+export function SelfHostedPlanFeature({ label }: { label: string }) {
return (
<div className="flex items-center gap-x-1">
<div className="py-px">
- <RiCheckLine className="size-4 shrink-0 text-text-tertiary" />
+ <span aria-hidden className="i-ri-check-line size-4 shrink-0 text-text-tertiary" />
</div>
<span className="grow system-sm-regular text-text-secondary">{label}</span>
</div>
)
}
-
-export default React.memo(Item)
diff --git a/web/app/components/billing/pricing/plans/self-hosted-plan-item/types.ts b/web/app/components/billing/pricing/plans/self-hosted-plan-item/types.ts
deleted file mode 100644
index 55ae69190e6..00000000000
--- a/web/app/components/billing/pricing/plans/self-hosted-plan-item/types.ts
+++ /dev/null
@@ -1 +0,0 @@
-export type SelfHostedPlanOption = 'community' | 'premium' | 'enterprise'
diff --git a/web/app/components/billing/pricing/types.ts b/web/app/components/billing/pricing/types.ts
deleted file mode 100644
index 843d98e6f55..00000000000
--- a/web/app/components/billing/pricing/types.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export enum CategoryEnum {
- CLOUD = 'cloud',
- SELF = 'self',
-}
-
-export type Category = CategoryEnum.CLOUD | CategoryEnum.SELF
diff --git a/web/context/modal-context-provider.tsx b/web/context/modal-context-provider.tsx
index 12fa72940b6..b88b0fed621 100644
--- a/web/context/modal-context-provider.tsx
+++ b/web/context/modal-context-provider.tsx
@@ -31,9 +31,12 @@ const ExternalDataToolModal = dynamic(
ssr: false,
},
)
-const Pricing = dynamic(() => import('@/app/components/billing/pricing'), {
- ssr: false,
-})
+const Pricing = dynamic(
+ () => import('@/app/components/billing/pricing').then((module) => module.Pricing),
+ {
+ ssr: false,
+ },
+)
const AnnotationFullModal = dynamic(
() => import('@/app/components/billing/annotation-full/modal'),
{
diff --git a/web/context/modal-context.test.tsx b/web/context/modal-context.test.tsx
index 596393fc391..3d32d8dea74 100644
--- a/web/context/modal-context.test.tsx
+++ b/web/context/modal-context.test.tsx
@@ -18,7 +18,7 @@ vi.mock('@/next/navigation', () => ({
}))
vi.mock('@/app/components/billing/pricing', () => ({
- default: () => <div>billing.plansCommon.mostPopular</div>,
+ Pricing: () => <div>billing.plansCommon.mostPopular</div>,
}))
vi.mock('@/app/components/plugins/update-plugin', () => ({