fix: free quota tip (#831)

This commit is contained in:
zxhlyh
2023-08-14 16:36:04 +08:00
committed by GitHub
parent c5d148bf94
commit 0feb0bf7c0
10 changed files with 79 additions and 51 deletions

View File

@@ -1,14 +1,14 @@
import { useEffect, useState } from 'react'
import { useState } from 'react'
import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { useContext } from 'use-context-selector'
import type { ProviderConfigItem, ProviderWithQuota, TypeWithI18N } from '../declarations'
import type { ProviderConfigItem, TypeWithI18N } from '../declarations'
import { ProviderEnum as ProviderEnumValue } from '../declarations'
import s from './index.module.css'
import I18n from '@/context/i18n'
import Button from '@/app/components/base/button'
import { submitFreeQuota } from '@/service/common'
import { SPARK_FREE_QUOTA_PENDING } from '@/config'
import { LinkExternal01 } from '@/app/components/base/icons/src/vender/line/general'
const TIP_MAP: { [k: string]: TypeWithI18N } = {
[ProviderEnumValue.minimax]: {
@@ -20,34 +20,17 @@ const TIP_MAP: { [k: string]: TypeWithI18N } = {
'zh-Hans': '免费获取 300 万个 token',
},
}
const FREE_QUOTA_TIP = {
'en': 'Your 3 million tokens will be credited in 5 minutes.',
'zh-Hans': '您的 300 万 token 将在 5 分钟内到账。',
}
type FreeQuotaProps = {
modelItem: ProviderConfigItem
onUpdate: () => void
freeProvider?: ProviderWithQuota
}
const FreeQuota: FC<FreeQuotaProps> = ({
modelItem,
onUpdate,
freeProvider,
}) => {
const { locale } = useContext(I18n)
const { t } = useTranslation()
const [loading, setLoading] = useState(false)
const [freeQuotaPending, setFreeQuotaPending] = useState(false)
useEffect(() => {
if (
modelItem.key === ProviderEnumValue.spark
&& localStorage.getItem(SPARK_FREE_QUOTA_PENDING) === '1'
&& freeProvider
&& !freeProvider.is_valid
)
setFreeQuotaPending(true)
}, [freeProvider, modelItem.key])
const handleClick = async () => {
try {
@@ -64,29 +47,21 @@ const FreeQuota: FC<FreeQuotaProps> = ({
}
}
if (freeQuotaPending) {
return (
<div className='flex items-center'>
<div className={`${s.vender} ml-1 mr-2 text-xs font-medium text-transparent`}>{FREE_QUOTA_TIP[locale]}</div>
<Button
className='!px-3 !h-7 !rounded-md !text-xs !font-medium !bg-white !text-gray-700'
onClick={onUpdate}
>
{t('common.operation.reload')}
</Button>
<div className='mx-2 w-[1px] h-4 bg-black/5' />
</div>
)
}
return (
<div className='flex items-center'>
📣
<div className={`${s.vender} ml-1 mr-2 text-xs font-medium text-transparent`}>{TIP_MAP[modelItem.key][locale]}</div>
<div className={`${s.vender} ml-1 text-xs font-medium text-transparent`}>{TIP_MAP[modelItem.key][locale]}</div>
<div className='mx-1 text-xs font-medium text-gray-400'>·</div>
<a
href='https://docs.dify.ai/v/zh-hans/getting-started/faq/llms-use-faq#8.-ru-he-mian-fei-shen-ling-xun-fei-xing-huo-minimax-mo-xing-de-ti-yanedu'
target='_blank'
className='flex items-center text-xs font-medium text-[#155EEF]'>
{t('common.modelProvider.freeQuota.howToEarn')}
<LinkExternal01 className='ml-0.5 w-3 h-3' />
</a>
<Button
type='primary'
className='!px-3 !h-7 !rounded-md !text-xs !font-medium'
className='ml-3 !px-3 !h-7 !rounded-md !text-xs !font-medium'
onClick={handleClick}
disabled={loading}
>

View File

@@ -34,10 +34,9 @@ const Setting: FC<SettingProps> = ({
return (
<div className='flex items-center'>
{
(modelItem.key === ProviderEnum.minimax || modelItem.key === ProviderEnum.spark) && systemFree && !systemFree?.is_valid && !IS_CE_EDITION && (
(modelItem.key === ProviderEnum.minimax || modelItem.key === ProviderEnum.spark) && systemFree && !systemFree?.is_valid && !IS_CE_EDITION && locale === 'zh-Hans' && (
<FreeQuota
modelItem={modelItem}
freeProvider={systemFree}
onUpdate={onUpdate}
/>
)