feat: SaaS price plan frontend (#1683)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
@@ -2,10 +2,16 @@
|
||||
|
||||
import { createContext, useContext } from 'use-context-selector'
|
||||
import useSWR from 'swr'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { fetchDefaultModal, fetchModelList, fetchSupportRetrievalMethods } from '@/service/common'
|
||||
import { ModelFeature, ModelType } from '@/app/components/header/account-setting/model-page/declarations'
|
||||
import type { BackendModel } from '@/app/components/header/account-setting/model-page/declarations'
|
||||
import type { RETRIEVE_METHOD } from '@/types/app'
|
||||
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'
|
||||
|
||||
const ProviderContext = createContext<{
|
||||
textGenerationModelList: BackendModel[]
|
||||
embeddingsModelList: BackendModel[]
|
||||
@@ -23,6 +29,13 @@ const ProviderContext = createContext<{
|
||||
isRerankDefaultModelVaild: boolean
|
||||
mutateRerankDefaultModel: () => void
|
||||
supportRetrievalMethods: RETRIEVE_METHOD[]
|
||||
plan: {
|
||||
type: Plan
|
||||
usage: UsagePlanInfo
|
||||
total: UsagePlanInfo
|
||||
}
|
||||
isFetchedPlan: boolean
|
||||
enableBilling: boolean
|
||||
}>({
|
||||
textGenerationModelList: [],
|
||||
embeddingsModelList: [],
|
||||
@@ -40,6 +53,21 @@ const ProviderContext = createContext<{
|
||||
isRerankDefaultModelVaild: false,
|
||||
mutateRerankDefaultModel: () => {},
|
||||
supportRetrievalMethods: [],
|
||||
plan: {
|
||||
type: Plan.sandbox,
|
||||
usage: {
|
||||
vectorSpace: 32,
|
||||
buildApps: 12,
|
||||
teamMembers: 1,
|
||||
},
|
||||
total: {
|
||||
vectorSpace: 200,
|
||||
buildApps: 50,
|
||||
teamMembers: 1,
|
||||
},
|
||||
},
|
||||
isFetchedPlan: false,
|
||||
enableBilling: false,
|
||||
})
|
||||
|
||||
export const useProviderContext = () => useContext(ProviderContext)
|
||||
@@ -80,6 +108,21 @@ export const ProviderContextProvider = ({
|
||||
mutateRerankModelList()
|
||||
}
|
||||
|
||||
const [plan, setPlan] = useState(defaultPlan)
|
||||
const [isFetchedPlan, setIsFetchedPlan] = useState(false)
|
||||
const [enableBilling, setEnableBilling] = useState(true)
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const data = await fetchCurrentPlanInfo()
|
||||
const enabled = data.enabled
|
||||
setEnableBilling(enabled)
|
||||
if (enabled) {
|
||||
setPlan(parseCurrentPlan(data))
|
||||
setIsFetchedPlan(true)
|
||||
}
|
||||
})()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<ProviderContext.Provider value={{
|
||||
textGenerationModelList: textGenerationModelList || [],
|
||||
@@ -98,6 +141,9 @@ export const ProviderContextProvider = ({
|
||||
isRerankDefaultModelVaild,
|
||||
mutateRerankDefaultModel,
|
||||
supportRetrievalMethods: supportRetrievalMethods?.retrieval_method || [],
|
||||
plan,
|
||||
isFetchedPlan,
|
||||
enableBilling,
|
||||
}}>
|
||||
{children}
|
||||
</ProviderContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user