index.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <PremiumBadge className='select-none' color='blue' allowHover={allowHover} onClick={onClick}>
  21. <SparklesSoft className='flex items-center py-[1px] pl-[3px] w-3.5 h-3.5 text-components-premium-badge-indigo-text-stop-0' />
  22. <div className='system-xs-medium'>
  23. <span className='p-1'>
  24. {t('billing.upgradeBtn.encourageShort')}
  25. </span>
  26. </div>
  27. </PremiumBadge>
  28. }
  29. if (plan === Plan.sandbox) {
  30. return <PremiumBadge className='select-none' size={size} color='gray' allowHover={allowHover} onClick={onClick}>
  31. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  32. <span className='p-1'>
  33. {plan}
  34. </span>
  35. </div>
  36. </PremiumBadge>
  37. }
  38. if (plan === Plan.professional) {
  39. return <PremiumBadge className='select-none' size={size} color='blue' allowHover={allowHover} onClick={onClick}>
  40. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  41. <span className='p-1'>
  42. pro
  43. </span>
  44. </div>
  45. </PremiumBadge>
  46. }
  47. if (plan === Plan.team) {
  48. return <PremiumBadge className='select-none' size={size} color='indigo' allowHover={allowHover} onClick={onClick}>
  49. <div className={classNames(size === 's' ? 'system-2xs-medium-uppercase' : 'system-xs-medium-uppercase')}>
  50. <span className='p-1'>
  51. {plan}
  52. </span>
  53. </div>
  54. </PremiumBadge>
  55. }
  56. return null
  57. }
  58. export default PlanBadge