plan-item.tsx 12 KB

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