plan-item.tsx 12 KB

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