plan-item.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import { useContext } from 'use-context-selector'
  7. import { Plan } from '../type'
  8. import { ALL_PLANS, NUM_INFINITE, contactSalesUrl, contractSales, unAvailable } from '../config'
  9. import Toast from '../../base/toast'
  10. import TooltipPlus from '../../base/tooltip-plus'
  11. import { PlanRange } from './select-plan-range'
  12. import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
  13. import { useAppContext } from '@/context/app-context'
  14. import { fetchSubscriptionUrls } from '@/service/billing'
  15. import { LanguagesSupportedUnderscore, getModelRuntimeSupported } from '@/utils/language'
  16. import I18n from '@/context/i18n'
  17. type Props = {
  18. currentPlan: Plan
  19. plan: Plan
  20. planRange: PlanRange
  21. canPay: boolean
  22. }
  23. const KeyValue = ({ label, value, tooltip }: { label: string; value: string | number | JSX.Element; tooltip?: string }) => {
  24. return (
  25. <div className='mt-3.5 leading-[125%] text-[13px] font-medium'>
  26. <div className='flex items-center text-gray-500 space-x-1'>
  27. <div>{label}</div>
  28. {tooltip && (
  29. <TooltipPlus
  30. popupContent={
  31. <div className='w-[200px]'>{tooltip}</div>
  32. }
  33. >
  34. <HelpCircle className='w-3 h-3 text-gray-400' />
  35. </TooltipPlus>
  36. )}
  37. </div>
  38. <div className='mt-0.5 text-gray-900'>{value}</div>
  39. </div>
  40. )
  41. }
  42. const priceClassName = 'leading-[32px] text-[28px] font-bold text-gray-900'
  43. const style = {
  44. [Plan.sandbox]: {
  45. bg: 'bg-[#F2F4F7]',
  46. title: 'text-gray-900',
  47. hoverAndActive: '',
  48. },
  49. [Plan.professional]: {
  50. bg: 'bg-[#E0F2FE]',
  51. title: 'text-[#026AA2]',
  52. hoverAndActive: 'hover:shadow-lg hover:!text-white hover:!bg-[#0086C9] hover:!border-[#026AA2] active:!text-white active:!bg-[#026AA2] active:!border-[#026AA2]',
  53. },
  54. [Plan.team]: {
  55. bg: 'bg-[#E0EAFF]',
  56. title: 'text-[#3538CD]',
  57. hoverAndActive: 'hover:shadow-lg hover:!text-white hover:!bg-[#444CE7] hover:!border-[#3538CD] active:!text-white active:!bg-[#3538CD] active:!border-[#3538CD]',
  58. },
  59. [Plan.enterprise]: {
  60. bg: 'bg-[#FFEED3]',
  61. title: 'text-[#DC6803]',
  62. hoverAndActive: 'hover:shadow-lg hover:!text-white hover:!bg-[#F79009] hover:!border-[#DC6803] active:!text-white active:!bg-[#DC6803] active:!border-[#DC6803]',
  63. },
  64. }
  65. const PlanItem: FC<Props> = ({
  66. plan,
  67. currentPlan,
  68. planRange,
  69. canPay,
  70. }) => {
  71. const { t } = useTranslation()
  72. const { locale } = useContext(I18n)
  73. const language = getModelRuntimeSupported(locale)
  74. const isZh = language === LanguagesSupportedUnderscore[1]
  75. const [loading, setLoading] = React.useState(false)
  76. const i18nPrefix = `billing.plans.${plan}`
  77. const isFreePlan = plan === Plan.sandbox
  78. const isEnterprisePlan = plan === Plan.enterprise
  79. const isMostPopularPlan = plan === Plan.professional
  80. const planInfo = ALL_PLANS[plan]
  81. const isYear = planRange === PlanRange.yearly
  82. const isCurrent = plan === currentPlan
  83. const isPlanDisabled = planInfo.level <= ALL_PLANS[currentPlan].level || (!canPay && plan !== Plan.enterprise)
  84. const { isCurrentWorkspaceManager } = useAppContext()
  85. const messagesRequest = (() => {
  86. const value = planInfo.messageRequest[isZh ? 'zh' : 'en']
  87. if (value === contractSales)
  88. return t('billing.plansCommon.contractSales')
  89. return value
  90. })()
  91. const btnText = (() => {
  92. if (!canPay && plan !== Plan.enterprise)
  93. return t('billing.plansCommon.contractOwner')
  94. if (isCurrent)
  95. return t('billing.plansCommon.currentPlan')
  96. return ({
  97. [Plan.sandbox]: t('billing.plansCommon.startForFree'),
  98. [Plan.professional]: <>{t('billing.plansCommon.getStartedWith')}<span className='capitalize'>&nbsp;{plan}</span></>,
  99. [Plan.team]: <>{t('billing.plansCommon.getStartedWith')}<span className='capitalize'>&nbsp;{plan}</span></>,
  100. [Plan.enterprise]: t('billing.plansCommon.talkToSales'),
  101. })[plan]
  102. })()
  103. const comingSoon = (
  104. <div className='leading-[12px] text-[9px] font-semibold text-[#3538CD] uppercase'>{t('billing.plansCommon.comingSoon')}</div>
  105. )
  106. const supportContent = (() => {
  107. switch (plan) {
  108. case Plan.sandbox:
  109. return (<div className='space-y-3.5'>
  110. <div>{t('billing.plansCommon.supportItems.communityForums')}</div>
  111. <div>{t('billing.plansCommon.supportItems.agentMode')}</div>
  112. <div className='flex items-center space-x-1'>
  113. <div className='flex items-center'>
  114. <div className='mr-0.5'>&nbsp;{t('billing.plansCommon.supportItems.workflow')}</div>
  115. </div>
  116. <div>{comingSoon}</div>
  117. </div>
  118. </div>)
  119. case Plan.professional:
  120. return (
  121. <div>
  122. <div>{t('billing.plansCommon.supportItems.emailSupport')}</div>
  123. <div className='mt-3.5 flex items-center space-x-1'>
  124. <div>+ {t('billing.plansCommon.supportItems.logoChange')}</div>
  125. </div>
  126. <div className='mt-3.5 flex items-center space-x-1'>
  127. <div className='flex items-center'>
  128. +
  129. <div className='mr-0.5'>&nbsp;{t('billing.plansCommon.supportItems.ragAPIRequest')}</div>
  130. <TooltipPlus
  131. popupContent={
  132. <div className='w-[200px]'>{t('billing.plansCommon.ragAPIRequestTooltip')}</div>
  133. }
  134. >
  135. <HelpCircle className='w-3 h-3 text-gray-400' />
  136. </TooltipPlus>
  137. </div>
  138. <div>{comingSoon}</div>
  139. </div>
  140. </div>
  141. )
  142. case Plan.team:
  143. return (
  144. <div>
  145. <div>{t('billing.plansCommon.supportItems.priorityEmail')}</div>
  146. <div className='mt-3.5 flex items-center space-x-1'>
  147. <div>+ {t('billing.plansCommon.supportItems.SSOAuthentication')}</div>
  148. <div>{comingSoon}</div>
  149. </div>
  150. </div>
  151. )
  152. case Plan.enterprise:
  153. return (
  154. <div>
  155. <div>{t('billing.plansCommon.supportItems.personalizedSupport')}</div>
  156. <div className='mt-3.5 flex items-center space-x-1'>
  157. <div>+ {t('billing.plansCommon.supportItems.dedicatedAPISupport')}</div>
  158. </div>
  159. <div className='mt-3.5 flex items-center space-x-1'>
  160. <div>+ {t('billing.plansCommon.supportItems.customIntegration')}</div>
  161. </div>
  162. </div>
  163. )
  164. default:
  165. return ''
  166. }
  167. })()
  168. const handleGetPayUrl = async () => {
  169. if (loading)
  170. return
  171. if (isPlanDisabled)
  172. return
  173. if (isFreePlan)
  174. return
  175. if (isEnterprisePlan) {
  176. window.location.href = contactSalesUrl
  177. return
  178. }
  179. // Only workspace manager can buy plan
  180. if (!isCurrentWorkspaceManager) {
  181. Toast.notify({
  182. type: 'error',
  183. message: t('billing.buyPermissionDeniedTip'),
  184. className: 'z-[1001]',
  185. })
  186. return
  187. }
  188. setLoading(true)
  189. try {
  190. const res = await fetchSubscriptionUrls(plan, isYear ? 'year' : 'month')
  191. // Adb Block additional tracking block the gtag, so we need to redirect directly
  192. window.location.href = res.url
  193. }
  194. finally {
  195. setLoading(false)
  196. }
  197. }
  198. return (
  199. <div className={cn(isMostPopularPlan ? 'bg-[#0086C9] p-0.5' : 'pt-7', 'flex flex-col min-w-[290px] w-[290px] rounded-xl')}>
  200. {isMostPopularPlan && (
  201. <div className='flex items-center h-7 justify-center leading-[12px] text-xs font-medium text-[#F5F8FF]'>{t('billing.plansCommon.mostPopular')}</div>
  202. )}
  203. <div className={cn(style[plan].bg, 'grow px-6 py-6 rounded-[10px]')}>
  204. <div className={cn(style[plan].title, 'mb-1 leading-[125%] text-lg font-semibold')}>{t(`${i18nPrefix}.name`)}</div>
  205. <div className={cn(isFreePlan ? 'mb-5 text-[#FB6514]' : 'mb-4 text-gray-500', 'h-8 leading-[125%] text-[13px] font-normal')}>{t(`${i18nPrefix}.description`)}</div>
  206. {/* Price */}
  207. {isFreePlan && (
  208. <div className={priceClassName}>{t('billing.plansCommon.free')}</div>
  209. )}
  210. {isEnterprisePlan && (
  211. <div className={priceClassName}>{t('billing.plansCommon.contactSales')}</div>
  212. )}
  213. {!isFreePlan && !isEnterprisePlan && (
  214. <div className='flex items-end h-9'>
  215. <div className={priceClassName}>${isYear ? planInfo.price * 10 : planInfo.price}</div>
  216. <div className='ml-1'>
  217. {isYear && <div className='leading-[18px] text-xs font-medium text-[#F26725]'>{t('billing.plansCommon.save')}${planInfo.price * 2}</div>}
  218. <div className='leading-[18px] text-[15px] font-normal text-gray-500'>/{t(`billing.plansCommon.${!isYear ? 'month' : 'year'}`)}</div>
  219. </div>
  220. </div>
  221. )}
  222. <div
  223. className={cn(isMostPopularPlan && !isCurrent && '!bg-[#444CE7] !text-white !border !border-[#3538CD] shadow-sm', isPlanDisabled ? 'opacity-30' : `${style[plan].hoverAndActive} cursor-pointer`, 'mt-4 flex h-11 items-center justify-center border-[2px] border-gray-900 rounded-3xl text-sm font-semibold text-gray-900')}
  224. onClick={handleGetPayUrl}
  225. >
  226. {btnText}
  227. </div>
  228. <div className='my-4 h-[1px] bg-black/5'></div>
  229. <div className='leading-[125%] text-[13px] font-normal text-gray-900'>
  230. {t(`${i18nPrefix}.includesTitle`)}
  231. </div>
  232. <KeyValue
  233. label={t('billing.plansCommon.messageRequest.title')}
  234. value={messagesRequest}
  235. tooltip={t('billing.plansCommon.messageRequest.tooltip') as string}
  236. />
  237. <KeyValue
  238. label={t('billing.plansCommon.modelProviders')}
  239. value={planInfo.modelProviders}
  240. />
  241. <KeyValue
  242. label={t('billing.plansCommon.teamMembers')}
  243. value={planInfo.teamMembers === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : planInfo.teamMembers}
  244. />
  245. <KeyValue
  246. label={t('billing.plansCommon.buildApps')}
  247. value={planInfo.buildApps === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : planInfo.buildApps}
  248. />
  249. <KeyValue
  250. label={t('billing.plansCommon.vectorSpace')}
  251. value={planInfo.vectorSpace === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : (planInfo.vectorSpace >= 1000 ? `${planInfo.vectorSpace / 1000}G` : `${planInfo.vectorSpace}MB`)}
  252. tooltip={t('billing.plansCommon.vectorSpaceBillingTooltip') as string}
  253. />
  254. <KeyValue
  255. label={t('billing.plansCommon.documentProcessingPriority')}
  256. value={t(`billing.plansCommon.priority.${planInfo.documentProcessingPriority}`) as string}
  257. />
  258. <KeyValue
  259. label={t('billing.plansCommon.annotatedResponse.title')}
  260. value={planInfo.annotatedResponse === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : `${planInfo.annotatedResponse}`}
  261. tooltip={t('billing.plansCommon.annotatedResponse.tooltip') as string}
  262. />
  263. <KeyValue
  264. label={t('billing.plansCommon.logsHistory')}
  265. value={planInfo.logHistory === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : `${planInfo.logHistory} ${t('billing.plansCommon.days')}`}
  266. />
  267. <KeyValue
  268. label={t('billing.plansCommon.customTools')}
  269. value={planInfo.customTools === NUM_INFINITE ? t('billing.plansCommon.unlimited') as string : (planInfo.customTools === unAvailable ? t('billing.plansCommon.unavailable') as string : `${planInfo.customTools}`)}
  270. />
  271. <KeyValue
  272. label={t('billing.plansCommon.support')}
  273. value={supportContent}
  274. />
  275. </div>
  276. </div>
  277. )
  278. }
  279. export default React.memo(PlanItem)