index.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { useMemo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import {
  4. DocumentProcessingPriority,
  5. Plan,
  6. } from '../type'
  7. import cn from '@/utils/classnames'
  8. import { useProviderContext } from '@/context/provider-context'
  9. import {
  10. ZapFast,
  11. ZapNarrow,
  12. } from '@/app/components/base/icons/src/vender/solid/general'
  13. import Tooltip from '@/app/components/base/tooltip'
  14. type PriorityLabelProps = {
  15. className?: string
  16. }
  17. const PriorityLabel = ({ className }: PriorityLabelProps) => {
  18. const { t } = useTranslation()
  19. const { plan } = useProviderContext()
  20. const priority = useMemo(() => {
  21. if (plan.type === Plan.sandbox)
  22. return DocumentProcessingPriority.standard
  23. if (plan.type === Plan.professional)
  24. return DocumentProcessingPriority.priority
  25. if (plan.type === Plan.team || plan.type === Plan.enterprise)
  26. return DocumentProcessingPriority.topPriority
  27. }, [plan])
  28. return (
  29. <Tooltip popupContent={
  30. <div>
  31. <div className='mb-1 text-xs font-semibold text-gray-700'>{`${t('billing.plansCommon.documentProcessingPriority')}: ${t(`billing.plansCommon.priority.${priority}`)}`}</div>
  32. {
  33. priority !== DocumentProcessingPriority.topPriority && (
  34. <div className='text-xs text-gray-500'>{t('billing.plansCommon.documentProcessingPriorityTip')}</div>
  35. )
  36. }
  37. </div>
  38. }>
  39. <span className={cn(`
  40. shrink-0 flex items-center ml-1 px-1 h-[18px] rounded-[5px] border border-text-accent-secondary
  41. text-2xs font-medium text-text-accent-secondary
  42. `, className)}>
  43. {
  44. plan.type === Plan.professional && (
  45. <ZapNarrow className='mr-0.5 size-3' />
  46. )
  47. }
  48. {
  49. (plan.type === Plan.team || plan.type === Plan.enterprise) && (
  50. <ZapFast className='mr-0.5 size-3' />
  51. )
  52. }
  53. {t(`billing.plansCommon.priority.${priority}`)}
  54. </span>
  55. </Tooltip>
  56. )
  57. }
  58. export default PriorityLabel