index.tsx 5.9 KB

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