index.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { useTranslation } from 'react-i18next'
  2. import s from './index.module.css'
  3. import cn from 'classnames'
  4. import type { ProviderHosted } from '@/models/common'
  5. interface IOpenaiHostedProviderProps {
  6. provider: ProviderHosted
  7. }
  8. const OpenaiHostedProvider = ({
  9. provider
  10. }: IOpenaiHostedProviderProps) => {
  11. const { t } = useTranslation()
  12. const exhausted = provider.quota_used > provider.quota_limit
  13. return (
  14. <div className={`
  15. border-[0.5px] border-gray-200 rounded-xl
  16. ${exhausted ? 'bg-[#FFFBFA]' : 'bg-gray-50'}
  17. `}>
  18. <div className='pt-4 px-4 pb-3'>
  19. <div className='flex items-center mb-3'>
  20. <div className={s.icon} />
  21. <div className='grow text-sm font-medium text-gray-800'>
  22. {t('common.provider.openaiHosted.openaiHosted')}
  23. </div>
  24. <div className={`
  25. px-2 h-[22px] flex items-center rounded-md border
  26. text-xs font-semibold
  27. ${exhausted ? 'border-[#D92D20] text-[#D92D20]' : 'border-primary-600 text-primary-600'}
  28. `}>
  29. {exhausted ? t('common.provider.openaiHosted.exhausted') : t('common.provider.openaiHosted.onTrial')}
  30. </div>
  31. </div>
  32. <div className='text-[13px] text-gray-500'>{t('common.provider.openaiHosted.desc')}</div>
  33. </div>
  34. <div className='flex items-center h-[42px] px-4 border-t-[0.5px] border-t-[rgba(0, 0, 0, 0.05)]'>
  35. <div className='text-[13px] text-gray-700'>{t('common.provider.openaiHosted.callTimes')}</div>
  36. <div className='relative grow h-2 flex bg-gray-200 rounded-md mx-2 overflow-hidden'>
  37. <div
  38. className={cn(s.bar, exhausted && s['bar-error'], 'absolute top-0 left-0 right-0 bottom-0')}
  39. style={{ width: `${(provider.quota_used / provider.quota_limit * 100).toFixed(2)}%` }}
  40. />
  41. {Array(10).fill(0).map((i, k) => (
  42. <div key={k} className={s['bar-item']} />
  43. ))}
  44. </div>
  45. <div className={`
  46. text-[13px] font-medium ${exhausted ? 'text-[#D92D20]' : 'text-gray-700'}
  47. `}>{provider.quota_used}/{provider.quota_limit}</div>
  48. </div>
  49. {
  50. exhausted && (
  51. <div className='
  52. px-4 py-3 leading-[18px] flex items-center text-[13px] text-gray-700 font-medium
  53. bg-[#FFFAEB] border-t border-t-[rgba(0, 0, 0, 0.05)] rounded-b-xl
  54. '>
  55. {t('common.provider.openaiHosted.usedUp')}
  56. </div>
  57. )
  58. }
  59. </div>
  60. )
  61. }
  62. export default OpenaiHostedProvider