diff --git a/web/app/components/base/toast/index.tsx b/web/app/components/base/toast/index.tsx index ba7d8af518..3b2004aab3 100644 --- a/web/app/components/base/toast/index.tsx +++ b/web/app/components/base/toast/index.tsx @@ -122,7 +122,8 @@ Toast.notify = ({ duration, className, customComponent, -}: Pick) => { + onClose, +}: Pick) => { const defaultDuring = (type === 'success' || type === 'info') ? 3000 : 6000 if (typeof window === 'object') { const holder = document.createElement('div') @@ -130,12 +131,13 @@ Toast.notify = ({ root.render( {}, + notify: () => { }, close: () => { if (holder) { root.unmount() holder.remove() } + onClose?.() }, }}> @@ -147,6 +149,7 @@ Toast.notify = ({ root.unmount() holder.remove() } + onClose?.() }, duration || defaultDuring) } } diff --git a/web/context/provider-context.tsx b/web/context/provider-context.tsx index 75747ba79c..b24c023661 100644 --- a/web/context/provider-context.tsx +++ b/web/context/provider-context.tsx @@ -3,12 +3,15 @@ import { createContext, useContext, useContextSelector } from 'use-context-selector' import useSWR from 'swr' import { useEffect, useState } from 'react' +import dayjs from 'dayjs' +import { useTranslation } from 'react-i18next' import { fetchModelList, fetchModelProviders, fetchSupportRetrievalMethods, } from '@/service/common' import { + CurrentSystemQuotaTypeEnum, ModelStatusEnum, ModelTypeEnum, } from '@/app/components/header/account-setting/model-provider-page/declarations' @@ -18,6 +21,7 @@ import { Plan, type UsagePlanInfo } from '@/app/components/billing/type' import { fetchCurrentPlanInfo } from '@/service/billing' import { parseCurrentPlan } from '@/app/components/billing/utils' import { defaultPlan } from '@/app/components/billing/config' +import Toast from '@/app/components/base/toast' type ProviderContextState = { modelProviders: ModelProvider[] @@ -110,6 +114,32 @@ export const ProviderContextProvider = ({ fetchPlan() }, []) + const { t } = useTranslation() + useEffect(() => { + if (localStorage.getItem('anthropic_quota_notice') === 'true') + return + + if (dayjs().isAfter(dayjs('2025-03-10'))) + return + + if (providersData?.data && providersData.data.length > 0) { + const anthropic = providersData.data.find(provider => provider.provider === 'anthropic') + if (anthropic && anthropic.system_configuration.current_quota_type === CurrentSystemQuotaTypeEnum.trial) { + const quota = anthropic.system_configuration.quota_configurations.find(item => item.quota_type === anthropic.system_configuration.current_quota_type) + if (quota && quota.is_valid && quota.quota_used < quota.quota_limit) { + Toast.notify({ + type: 'info', + message: t('common.provider.anthropicHosted.trialQuotaTip'), + duration: 6000, + onClose: () => { + localStorage.setItem('anthropic_quota_notice', 'true') + }, + }) + } + } + } + }, [providersData, t]) + return (