index.tsx 2.7 KB

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