You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { createPortal } from 'react-dom'
  5. import { useTranslation } from 'react-i18next'
  6. import { RiArrowRightUpLine, RiCloseLine, RiCloudFill, RiTerminalBoxFill } from '@remixicon/react'
  7. import Link from 'next/link'
  8. import { useKeyPress } from 'ahooks'
  9. import { Plan, SelfHostedPlan } from '../type'
  10. import TabSlider from '../../base/tab-slider'
  11. import SelectPlanRange, { PlanRange } from './select-plan-range'
  12. import PlanItem from './plan-item'
  13. import SelfHostedPlanItem from './self-hosted-plan-item'
  14. import { useProviderContext } from '@/context/provider-context'
  15. import GridMask from '@/app/components/base/grid-mask'
  16. import { useAppContext } from '@/context/app-context'
  17. import classNames from '@/utils/classnames'
  18. import { useGetPricingPageLanguage } from '@/context/i18n'
  19. type Props = {
  20. onCancel: () => void
  21. }
  22. const Pricing: FC<Props> = ({
  23. onCancel,
  24. }) => {
  25. const { t } = useTranslation()
  26. const { plan } = useProviderContext()
  27. const { isCurrentWorkspaceManager } = useAppContext()
  28. const canPay = isCurrentWorkspaceManager
  29. const [planRange, setPlanRange] = React.useState<PlanRange>(PlanRange.monthly)
  30. const [currentPlan, setCurrentPlan] = React.useState<string>('cloud')
  31. useKeyPress(['esc'], onCancel)
  32. const pricingPageLanguage = useGetPricingPageLanguage()
  33. const pricingPageURL = pricingPageLanguage
  34. ? `https://dify.ai/${pricingPageLanguage}/pricing#plans-and-features`
  35. : 'https://dify.ai/pricing#plans-and-features'
  36. return createPortal(
  37. <div
  38. className='fixed inset-0 bottom-0 left-0 right-0 top-0 z-[1000] bg-background-overlay-backdrop p-4 backdrop-blur-[6px]'
  39. onClick={e => e.stopPropagation()}
  40. >
  41. <div className='relative h-full w-full overflow-auto rounded-2xl border border-effects-highlight bg-saas-background'>
  42. <div
  43. className='fixed right-7 top-7 z-[1001] flex h-9 w-9 cursor-pointer items-center justify-center rounded-[10px] bg-components-button-tertiary-bg hover:bg-components-button-tertiary-bg-hover'
  44. onClick={onCancel}
  45. >
  46. <RiCloseLine className='size-5 text-components-button-tertiary-text' />
  47. </div>
  48. <GridMask wrapperClassName='w-full min-h-full' canvasClassName='min-h-full'>
  49. <div className='flex flex-col items-center px-8 pb-7 pt-12'>
  50. <div className='title-5xl-bold mb-2 text-text-primary'>
  51. {t('billing.plansCommon.title')}
  52. </div>
  53. <div className='system-sm-regular text-text-secondary'>
  54. <span>{t('billing.plansCommon.freeTrialTipPrefix')}</span>
  55. <span className='text-gradient font-semibold'>{t('billing.plansCommon.freeTrialTip')}</span>
  56. <span>{t('billing.plansCommon.freeTrialTipSuffix')}</span>
  57. </div>
  58. </div>
  59. <div className='mx-auto w-[1152px]'>
  60. <div className='flex h-[64px] items-center justify-between py-2'>
  61. <TabSlider
  62. value={currentPlan}
  63. className='inline-flex'
  64. options={[
  65. {
  66. value: 'cloud',
  67. text: <div className={
  68. classNames('system-md-semibold-uppercase inline-flex items-center text-text-secondary',
  69. currentPlan === 'cloud' && 'text-text-accent-light-mode-only')} >
  70. <RiCloudFill className='mr-2 size-4' />{t('billing.plansCommon.cloud')}</div>,
  71. },
  72. {
  73. value: 'self',
  74. text: <div className={
  75. classNames('system-md-semibold-uppercase inline-flex items-center text-text-secondary',
  76. currentPlan === 'self' && 'text-text-accent-light-mode-only')}>
  77. <RiTerminalBoxFill className='mr-2 size-4' />{t('billing.plansCommon.self')}</div>,
  78. }]}
  79. onChange={v => setCurrentPlan(v)} />
  80. {currentPlan === 'cloud' && <SelectPlanRange
  81. value={planRange}
  82. onChange={setPlanRange}
  83. />}
  84. </div>
  85. <div className='pb-8 pt-3'>
  86. <div className='flex flex-nowrap justify-center gap-x-4'>
  87. {currentPlan === 'cloud' && <>
  88. <PlanItem
  89. currentPlan={plan.type}
  90. plan={Plan.sandbox}
  91. planRange={planRange}
  92. canPay={canPay}
  93. />
  94. <PlanItem
  95. currentPlan={plan.type}
  96. plan={Plan.professional}
  97. planRange={planRange}
  98. canPay={canPay}
  99. />
  100. <PlanItem
  101. currentPlan={plan.type}
  102. plan={Plan.team}
  103. planRange={planRange}
  104. canPay={canPay}
  105. />
  106. </>}
  107. {currentPlan === 'self' && <>
  108. <SelfHostedPlanItem
  109. plan={SelfHostedPlan.community}
  110. planRange={planRange}
  111. canPay={canPay}
  112. />
  113. <SelfHostedPlanItem
  114. plan={SelfHostedPlan.premium}
  115. planRange={planRange}
  116. canPay={canPay}
  117. />
  118. <SelfHostedPlanItem
  119. plan={SelfHostedPlan.enterprise}
  120. planRange={planRange}
  121. canPay={canPay}
  122. />
  123. </>}
  124. </div>
  125. </div>
  126. </div>
  127. <div className='flex items-center justify-center py-4'>
  128. <div className='flex items-center justify-center gap-x-0.5 rounded-lg px-3 py-2 text-components-button-secondary-accent-text hover:cursor-pointer hover:bg-state-accent-hover'>
  129. <Link href={pricingPageURL} className='system-sm-medium'>{t('billing.plansCommon.comparePlanAndFeatures')}</Link>
  130. <RiArrowRightUpLine className='size-4' />
  131. </div>
  132. </div>
  133. </GridMask>
  134. </div >
  135. </div >,
  136. document.body,
  137. )
  138. }
  139. export default React.memo(Pricing)