index.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { Plan } from '../type'
  6. import VectorSpaceInfo from '../usage-info/vector-space-info'
  7. import AppsInfo from '../usage-info/apps-info'
  8. import UpgradeBtn from '../upgrade-btn'
  9. import { User01 } from '../../base/icons/src/vender/line/users'
  10. import { MessageFastPlus } from '../../base/icons/src/vender/line/communication'
  11. import { FileUpload } from '../../base/icons/src/vender/line/files'
  12. import cn from '@/utils/classnames'
  13. import { useProviderContext } from '@/context/provider-context'
  14. import UsageInfo from '@/app/components/billing/usage-info'
  15. const typeStyle = {
  16. [Plan.sandbox]: {
  17. textClassNames: 'text-gray-900',
  18. bg: 'linear-gradient(113deg, rgba(255, 255, 255, 0.51) 3.51%, rgba(255, 255, 255, 0.00) 111.71%), #EAECF0',
  19. },
  20. [Plan.professional]: {
  21. textClassNames: 'text-[#026AA2]',
  22. bg: 'linear-gradient(113deg, rgba(255, 255, 255, 0.51) 3.51%, rgba(255, 255, 255, 0.00) 111.71%), #E0F2FE',
  23. },
  24. [Plan.team]: {
  25. textClassNames: 'text-[#3538CD]',
  26. bg: 'linear-gradient(113deg, rgba(255, 255, 255, 0.51) 3.51%, rgba(255, 255, 255, 0.00) 111.71%), #E0EAFF',
  27. },
  28. [Plan.enterprise]: {
  29. textClassNames: 'text-[#DC6803]',
  30. bg: 'linear-gradient(113deg, rgba(255, 255, 255, 0.51) 3.51%, rgba(255, 255, 255, 0.00) 111.71%), #FFEED3',
  31. },
  32. }
  33. type Props = {
  34. loc: string
  35. }
  36. const PlanComp: FC<Props> = ({
  37. loc,
  38. }) => {
  39. const { t } = useTranslation()
  40. const { plan } = useProviderContext()
  41. const {
  42. type,
  43. } = plan
  44. const {
  45. usage,
  46. total,
  47. } = plan
  48. const isInHeader = loc === 'header'
  49. return (
  50. <div
  51. className='rounded-xl border border-white select-none'
  52. style={{
  53. background: typeStyle[type].bg,
  54. boxShadow: '5px 7px 12px 0px rgba(0, 0, 0, 0.06)',
  55. }}
  56. >
  57. <div className='flex justify-between px-6 py-5 items-center'>
  58. <div>
  59. <div
  60. className='leading-[18px] text-xs font-normal opacity-70'
  61. style={{
  62. color: 'rgba(0, 0, 0, 0.64)',
  63. }}
  64. >
  65. {t('billing.currentPlan')}
  66. </div>
  67. <div className={cn(typeStyle[type].textClassNames, 'leading-[125%] text-lg font-semibold uppercase')}>
  68. {t(`billing.plans.${type}.name`)}
  69. </div>
  70. </div>
  71. {(!isInHeader || (isInHeader && type !== Plan.sandbox)) && (
  72. <UpgradeBtn
  73. className='flex-shrink-0'
  74. isPlain={type !== Plan.sandbox}
  75. loc={loc}
  76. />
  77. )}
  78. </div>
  79. {/* Plan detail */}
  80. <div className='rounded-xl bg-white px-6 py-3'>
  81. <UsageInfo
  82. className='py-3'
  83. Icon={User01}
  84. name={t('billing.plansCommon.teamMembers')}
  85. usage={usage.teamMembers}
  86. total={total.teamMembers}
  87. />
  88. <AppsInfo className='py-3' />
  89. <VectorSpaceInfo className='py-3' />
  90. <UsageInfo
  91. className='py-3'
  92. Icon={MessageFastPlus}
  93. name={t('billing.plansCommon.annotationQuota')}
  94. usage={usage.annotatedResponse}
  95. total={total.annotatedResponse}
  96. />
  97. <UsageInfo
  98. className='py-3'
  99. Icon={FileUpload}
  100. name={t('billing.plansCommon.documentsUploadQuota')}
  101. usage={usage.documentsUploadQuota}
  102. total={total.documentsUploadQuota}
  103. />
  104. {isInHeader && type === Plan.sandbox && (
  105. <UpgradeBtn
  106. className='flex-shrink-0 my-3'
  107. isFull
  108. size='lg'
  109. isPlain={type !== Plan.sandbox}
  110. loc={loc}
  111. />
  112. )}
  113. </div>
  114. </div>
  115. )
  116. }
  117. export default React.memo(PlanComp)