index.tsx 2.2 KB

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