plan-item.tsx 11 KB

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