Skip to content

Commit 0feb0bf

Browse files
authored
fix: free quota tip (#831)
1 parent c5d148b commit 0feb0bf

File tree

10 files changed

+79
-51
lines changed

10 files changed

+79
-51
lines changed

web/app/(commonLayout)/apps/Apps.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { useEffect, useRef } from 'react'
44
import useSWRInfinite from 'swr/infinite'
55
import { debounce } from 'lodash-es'
66
import { useTranslation } from 'react-i18next'
7-
import { useSearchParams } from 'next/navigation'
87
import AppCard from './AppCard'
98
import NewAppCard from './NewAppCard'
109
import type { AppListResponse } from '@/models/app'
1110
import { fetchAppList } from '@/service/apps'
1211
import { useSelector } from '@/context/app-context'
13-
import { NEED_REFRESH_APP_LIST_KEY, SPARK_FREE_QUOTA_PENDING } from '@/config'
12+
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
1413

1514
const getKey = (pageIndex: number, previousPageData: AppListResponse) => {
1615
if (!pageIndex || previousPageData.has_more)
@@ -24,21 +23,13 @@ const Apps = () => {
2423
const loadingStateRef = useRef(false)
2524
const pageContainerRef = useSelector(state => state.pageContainerRef)
2625
const anchorRef = useRef<HTMLAnchorElement>(null)
27-
const searchParams = useSearchParams()
2826

2927
useEffect(() => {
3028
document.title = `${t('app.title')} - Dify`
3129
if (localStorage.getItem(NEED_REFRESH_APP_LIST_KEY) === '1') {
3230
localStorage.removeItem(NEED_REFRESH_APP_LIST_KEY)
3331
mutate()
3432
}
35-
if (
36-
localStorage.getItem(SPARK_FREE_QUOTA_PENDING) !== '1'
37-
&& searchParams.get('type') === 'provider_apply_callback'
38-
&& searchParams.get('provider') === 'spark'
39-
&& searchParams.get('result') === 'success'
40-
)
41-
localStorage.setItem(SPARK_FREE_QUOTA_PENDING, '1')
4233
}, [])
4334

4435
useEffect(() => {
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"icon": {
3+
"type": "element",
4+
"isRootNode": true,
5+
"name": "svg",
6+
"attributes": {
7+
"width": "12",
8+
"height": "12",
9+
"viewBox": "0 0 12 12",
10+
"fill": "none",
11+
"xmlns": "http://www.w3.org/2000/svg"
12+
},
13+
"children": [
14+
{
15+
"type": "element",
16+
"name": "g",
17+
"attributes": {
18+
"id": "link-external-01"
19+
},
20+
"children": [
21+
{
22+
"type": "element",
23+
"name": "path",
24+
"attributes": {
25+
"id": "Icon",
26+
"d": "M10.5 4.5L10.5 1.5M10.5 1.5H7.5M10.5 1.5L6.5 5.5M5 2.5H3.9C3.05992 2.5 2.63988 2.5 2.31901 2.66349C2.03677 2.8073 1.8073 3.03677 1.66349 3.31901C1.5 3.63988 1.5 4.05992 1.5 4.9V8.1C1.5 8.94008 1.5 9.36012 1.66349 9.68099C1.8073 9.96323 2.03677 10.1927 2.31901 10.3365C2.63988 10.5 3.05992 10.5 3.9 10.5H7.1C7.94008 10.5 8.36012 10.5 8.68099 10.3365C8.96323 10.1927 9.1927 9.96323 9.33651 9.68099C9.5 9.36012 9.5 8.94008 9.5 8.1V7",
27+
"stroke": "currentColor",
28+
"stroke-linecap": "round",
29+
"stroke-linejoin": "round"
30+
},
31+
"children": []
32+
}
33+
]
34+
}
35+
]
36+
},
37+
"name": "LinkExternal01"
38+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// GENERATE BY script
2+
// DON NOT EDIT IT MANUALLY
3+
4+
import * as React from 'react'
5+
import data from './LinkExternal01.json'
6+
import IconBase from '@/app/components/base/icons/IconBase'
7+
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
8+
9+
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
10+
props,
11+
ref,
12+
) => <IconBase {...props} ref={ref} data={data as IconData} />)
13+
14+
export default Icon

web/app/components/base/icons/src/vender/line/general/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { default as Edit03 } from './Edit03'
55
export { default as Hash02 } from './Hash02'
66
export { default as HelpCircle } from './HelpCircle'
77
export { default as InfoCircle } from './InfoCircle'
8+
export { default as LinkExternal01 } from './LinkExternal01'
89
export { default as LinkExternal02 } from './LinkExternal02'
910
export { default as Loading02 } from './Loading02'
1011
export { default as LogOut01 } from './LogOut01'

web/app/components/header/account-setting/model-page/model-item/FreeQuota.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { useEffect, useState } from 'react'
1+
import { useState } from 'react'
22
import type { FC } from 'react'
33
import { useTranslation } from 'react-i18next'
44
import { useContext } from 'use-context-selector'
5-
import type { ProviderConfigItem, ProviderWithQuota, TypeWithI18N } from '../declarations'
5+
import type { ProviderConfigItem, TypeWithI18N } from '../declarations'
66
import { ProviderEnum as ProviderEnumValue } from '../declarations'
77
import s from './index.module.css'
88
import I18n from '@/context/i18n'
99
import Button from '@/app/components/base/button'
1010
import { submitFreeQuota } from '@/service/common'
11-
import { SPARK_FREE_QUOTA_PENDING } from '@/config'
11+
import { LinkExternal01 } from '@/app/components/base/icons/src/vender/line/general'
1212

1313
const TIP_MAP: { [k: string]: TypeWithI18N } = {
1414
[ProviderEnumValue.minimax]: {
@@ -20,34 +20,17 @@ const TIP_MAP: { [k: string]: TypeWithI18N } = {
2020
'zh-Hans': '免费获取 300 万个 token',
2121
},
2222
}
23-
const FREE_QUOTA_TIP = {
24-
'en': 'Your 3 million tokens will be credited in 5 minutes.',
25-
'zh-Hans': '您的 300 万 token 将在 5 分钟内到账。',
26-
}
2723
type FreeQuotaProps = {
2824
modelItem: ProviderConfigItem
2925
onUpdate: () => void
30-
freeProvider?: ProviderWithQuota
3126
}
3227
const FreeQuota: FC<FreeQuotaProps> = ({
3328
modelItem,
3429
onUpdate,
35-
freeProvider,
3630
}) => {
3731
const { locale } = useContext(I18n)
3832
const { t } = useTranslation()
3933
const [loading, setLoading] = useState(false)
40-
const [freeQuotaPending, setFreeQuotaPending] = useState(false)
41-
42-
useEffect(() => {
43-
if (
44-
modelItem.key === ProviderEnumValue.spark
45-
&& localStorage.getItem(SPARK_FREE_QUOTA_PENDING) === '1'
46-
&& freeProvider
47-
&& !freeProvider.is_valid
48-
)
49-
setFreeQuotaPending(true)
50-
}, [freeProvider, modelItem.key])
5134

5235
const handleClick = async () => {
5336
try {
@@ -64,29 +47,21 @@ const FreeQuota: FC<FreeQuotaProps> = ({
6447
}
6548
}
6649

67-
if (freeQuotaPending) {
68-
return (
69-
<div className='flex items-center'>
70-
71-
<div className={`${s.vender} ml-1 mr-2 text-xs font-medium text-transparent`}>{FREE_QUOTA_TIP[locale]}</div>
72-
<Button
73-
className='!px-3 !h-7 !rounded-md !text-xs !font-medium !bg-white !text-gray-700'
74-
onClick={onUpdate}
75-
>
76-
{t('common.operation.reload')}
77-
</Button>
78-
<div className='mx-2 w-[1px] h-4 bg-black/5' />
79-
</div>
80-
)
81-
}
82-
8350
return (
8451
<div className='flex items-center'>
8552
📣
86-
<div className={`${s.vender} ml-1 mr-2 text-xs font-medium text-transparent`}>{TIP_MAP[modelItem.key][locale]}</div>
53+
<div className={`${s.vender} ml-1 text-xs font-medium text-transparent`}>{TIP_MAP[modelItem.key][locale]}</div>
54+
<div className='mx-1 text-xs font-medium text-gray-400'>·</div>
55+
<a
56+
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'
57+
target='_blank'
58+
className='flex items-center text-xs font-medium text-[#155EEF]'>
59+
{t('common.modelProvider.freeQuota.howToEarn')}
60+
<LinkExternal01 className='ml-0.5 w-3 h-3' />
61+
</a>
8762
<Button
8863
type='primary'
89-
className='!px-3 !h-7 !rounded-md !text-xs !font-medium'
64+
className='ml-3 !px-3 !h-7 !rounded-md !text-xs !font-medium'
9065
onClick={handleClick}
9166
disabled={loading}
9267
>

web/app/components/header/account-setting/model-page/model-item/Setting.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ const Setting: FC<SettingProps> = ({
3434
return (
3535
<div className='flex items-center'>
3636
{
37-
(modelItem.key === ProviderEnum.minimax || modelItem.key === ProviderEnum.spark) && systemFree && !systemFree?.is_valid && !IS_CE_EDITION && (
37+
(modelItem.key === ProviderEnum.minimax || modelItem.key === ProviderEnum.spark) && systemFree && !systemFree?.is_valid && !IS_CE_EDITION && locale === 'zh-Hans' && (
3838
<FreeQuota
3939
modelItem={modelItem}
40-
freeProvider={systemFree}
4140
onUpdate={onUpdate}
4241
/>
4342
)

web/config/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,3 @@ export const VAR_ITEM_TEMPLATE = {
120120
export const appDefaultIconBackground = '#D5F5F6'
121121

122122
export const NEED_REFRESH_APP_LIST_KEY = 'needRefreshAppList'
123-
export const SPARK_FREE_QUOTA_PENDING = 'sparkFreeQuotaPending'

web/i18n/lang/common.en.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ const translation = {
250250
front: 'Your API KEY will be encrypted and stored using',
251251
back: ' technology.',
252252
},
253+
freeQuota: {
254+
howToEarn: 'How to earn',
255+
},
253256
},
254257
dataSource: {
255258
add: 'Add a data source',

web/i18n/lang/common.zh.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ const translation = {
250250
front: '您的密钥将使用',
251251
back: '技术进行加密和存储。',
252252
},
253+
freeQuota: {
254+
howToEarn: '如何获取',
255+
},
253256
},
254257
dataSource: {
255258
add: '添加数据源',

0 commit comments

Comments
 (0)