plan-item.tsx 12 KB

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