plan-item.tsx 11 KB

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