index.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. className='inline-flex'
  59. options={[
  60. {
  61. value: 'cloud',
  62. text: <div className={
  63. classNames('inline-flex items-center system-md-semibold-uppercase text-text-secondary',
  64. currentPlan === 'cloud' && 'text-text-accent-light-mode-only')} >
  65. <RiCloudFill className='size-4 mr-2' />{t('billing.plansCommon.cloud')}</div>,
  66. },
  67. {
  68. value: 'self',
  69. text: <div className={
  70. classNames('inline-flex items-center system-md-semibold-uppercase text-text-secondary',
  71. currentPlan === 'self' && 'text-text-accent-light-mode-only')}>
  72. <RiTerminalBoxFill className='size-4 mr-2' />{t('billing.plansCommon.self')}</div>,
  73. }]}
  74. onChange={v => setCurrentPlan(v)} />
  75. {currentPlan === 'cloud' && <SelectPlanRange
  76. value={planRange}
  77. onChange={setPlanRange}
  78. />}
  79. </div>
  80. <div className='pt-3 pb-8'>
  81. <div className='flex justify-center flex-nowrap gap-x-4'>
  82. {currentPlan === 'cloud' && <>
  83. <PlanItem
  84. currentPlan={plan.type}
  85. plan={Plan.sandbox}
  86. planRange={planRange}
  87. canPay={canPay}
  88. />
  89. <PlanItem
  90. currentPlan={plan.type}
  91. plan={Plan.professional}
  92. planRange={planRange}
  93. canPay={canPay}
  94. />
  95. <PlanItem
  96. currentPlan={plan.type}
  97. plan={Plan.team}
  98. planRange={planRange}
  99. canPay={canPay}
  100. />
  101. </>}
  102. {currentPlan === 'self' && <>
  103. <SelfHostedPlanItem
  104. plan={SelfHostedPlan.community}
  105. planRange={planRange}
  106. canPay={canPay}
  107. />
  108. <SelfHostedPlanItem
  109. plan={SelfHostedPlan.premium}
  110. planRange={planRange}
  111. canPay={canPay}
  112. />
  113. <SelfHostedPlanItem
  114. plan={SelfHostedPlan.enterprise}
  115. planRange={planRange}
  116. canPay={canPay}
  117. />
  118. </>}
  119. </div>
  120. </div>
  121. </div>
  122. <div className='py-4 flex items-center justify-center'>
  123. <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'>
  124. <Link href='https://dify.ai/pricing#plans-and-features' className='system-sm-medium'>{t('billing.plansCommon.comparePlanAndFeatures')}</Link>
  125. <RiArrowRightUpLine className='size-4' />
  126. </div>
  127. </div>
  128. </GridMask>
  129. </div >
  130. </div >,
  131. document.body,
  132. )
  133. }
  134. export default React.memo(Pricing)