index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { useProviderContext } from '@/context/provider-context'
  2. import classNames from '@/utils/classnames'
  3. import type { FC } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { SparklesSoft } from '../../base/icons/src/public/common'
  6. import PremiumBadge from '../../base/premium-badge'
  7. import { Plan } from '../../billing/type'
  8. type PlanBadgeProps = {
  9. plan: Plan
  10. size?: 's' | 'm'
  11. allowHover?: boolean
  12. sandboxAsUpgrade?: boolean
  13. onClick?: () => void
  14. }
  15. const PlanBadge: FC<PlanBadgeProps> = ({ plan, allowHover, size = 'm', sandboxAsUpgrade = false, onClick }) => {
  16. const { isFetchedPlan } = useProviderContext()
  17. const { t } = useTranslation()
  18. if (!isFetchedPlan) return null
  19. if (plan === Plan.sandbox && sandboxAsUpgrade) {
  20. return <div className='select-none'>
  21. <PremiumBadge color='blue' allowHover={allowHover} onClick={onClick}>
  22. <SparklesSoft className='flex items-center py-[1px] pl-[3px] w-3.5 h-3.5 text-components-premium-badge-indigo-text-stop-0' />
  23. <div className='system-xs-medium'>
  24. <span className='p-1'>
  25. {t('billing.upgradeBtn.encourageShort')}
  26. </span>
  27. </div>
  28. </PremiumBadge>
  29. </div>
  30. }
  31. if (plan === Plan.sandbox) {
  32. return <div className='select-none'>
  33. <PremiumBadge size={size} color='gray' allowHover={allowHover} onClick={onClick}>
  34. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  35. <span className='p-1'>
  36. {plan}
  37. </span>
  38. </div>
  39. </PremiumBadge>
  40. </div>
  41. }
  42. if (plan === Plan.professional) {
  43. return <div className='select-none'>
  44. <PremiumBadge size={size} color='blue' allowHover={allowHover} onClick={onClick}>
  45. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  46. <span className='p-1'>
  47. pro
  48. </span>
  49. </div>
  50. </PremiumBadge>
  51. </div>
  52. }
  53. if (plan === Plan.team) {
  54. return <div className='select-none'>
  55. <PremiumBadge size={size} color='indigo' allowHover={allowHover} onClick={onClick}>
  56. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  57. <span className='p-1'>
  58. {plan}
  59. </span>
  60. </div>
  61. </PremiumBadge>
  62. </div>
  63. }
  64. return null
  65. }
  66. export default PlanBadge