Pārlūkot izejas kodu

fix: remove and create app not reload plan (#2220)

tags/0.5.2
Joel pirms 1 gada
vecāks
revīzija
d4262ecceb
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 3
- 0
web/app/(commonLayout)/apps/AppCard.tsx Parādīt failu

import CustomPopover from '@/app/components/base/popover' import CustomPopover from '@/app/components/base/popover'
import Divider from '@/app/components/base/divider' import Divider from '@/app/components/base/divider'
import { asyncRunSafe } from '@/utils' import { asyncRunSafe } from '@/utils'
import { useProviderContext } from '@/context/provider-context'


export type AppCardProps = { export type AppCardProps = {
app: App app: App
const { t } = useTranslation() const { t } = useTranslation()
const { notify } = useContext(ToastContext) const { notify } = useContext(ToastContext)
const { isCurrentWorkspaceManager } = useAppContext() const { isCurrentWorkspaceManager } = useAppContext()
const { onPlanInfoChanged } = useProviderContext()
const { push } = useRouter() const { push } = useRouter()


const mutateApps = useContextSelector( const mutateApps = useContextSelector(
if (onRefresh) if (onRefresh)
onRefresh() onRefresh()
mutateApps() mutateApps()
onPlanInfoChanged()
} }
catch (e: any) { catch (e: any) {
notify({ notify({

+ 9
- 1
web/app/(commonLayout)/apps/NewAppCard.tsx Parādīt failu

import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import style from '../list.module.css' import style from '../list.module.css'
import NewAppDialog from './NewAppDialog' import NewAppDialog from './NewAppDialog'
import { useProviderContext } from '@/context/provider-context'


export type CreateAppCardProps = { export type CreateAppCardProps = {
onSuccess?: () => void onSuccess?: () => void


const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => { const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => {
const { t } = useTranslation() const { t } = useTranslation()
const { onPlanInfoChanged } = useProviderContext()

const [showNewAppDialog, setShowNewAppDialog] = useState(false) const [showNewAppDialog, setShowNewAppDialog] = useState(false)
return ( return (
<a ref={ref} className={classNames(style.listItem, style.newItemCard)} onClick={() => setShowNewAppDialog(true)}> <a ref={ref} className={classNames(style.listItem, style.newItemCard)} onClick={() => setShowNewAppDialog(true)}>
</div> </div>
</div> </div>
{/* <div className='text-xs text-gray-500'>{t('app.createFromConfigFile')}</div> */} {/* <div className='text-xs text-gray-500'>{t('app.createFromConfigFile')}</div> */}
<NewAppDialog show={showNewAppDialog} onSuccess={onSuccess} onClose={() => setShowNewAppDialog(false)} />
<NewAppDialog show={showNewAppDialog} onSuccess={
() => {
onPlanInfoChanged()
if (onSuccess)
onSuccess()
}} onClose={() => setShowNewAppDialog(false)} />
</a> </a>
) )
}) })

+ 39
- 36
web/context/provider-context.tsx Parādīt failu

} }
isFetchedPlan: boolean isFetchedPlan: boolean
enableBilling: boolean enableBilling: boolean
onPlanInfoChanged: () => void
enableReplaceWebAppLogo: boolean enableReplaceWebAppLogo: boolean
}>({ }>({
modelProviders: [],
textGenerationModelList: [],
agentThoughtModelList: [],
supportRetrievalMethods: [],
hasSettedApiKey: true,
plan: {
type: Plan.sandbox,
usage: {
vectorSpace: 32,
buildApps: 12,
teamMembers: 1,
annotatedResponse: 1,
},
total: {
vectorSpace: 200,
buildApps: 50,
teamMembers: 1,
annotatedResponse: 10,
},
},
isFetchedPlan: false,
enableBilling: false,
enableReplaceWebAppLogo: false,
})
modelProviders: [],
textGenerationModelList: [],
agentThoughtModelList: [],
supportRetrievalMethods: [],
hasSettedApiKey: true,
plan: {
type: Plan.sandbox,
usage: {
vectorSpace: 32,
buildApps: 12,
teamMembers: 1,
annotatedResponse: 1,
},
total: {
vectorSpace: 200,
buildApps: 50,
teamMembers: 1,
annotatedResponse: 10,
},
},
isFetchedPlan: false,
enableBilling: false,
onPlanInfoChanged: () => { },
enableReplaceWebAppLogo: false,
})


export const useProviderContext = () => useContext(ProviderContext) export const useProviderContext = () => useContext(ProviderContext)


const [isFetchedPlan, setIsFetchedPlan] = useState(false) const [isFetchedPlan, setIsFetchedPlan] = useState(false)
const [enableBilling, setEnableBilling] = useState(true) const [enableBilling, setEnableBilling] = useState(true)
const [enableReplaceWebAppLogo, setEnableReplaceWebAppLogo] = useState(false) const [enableReplaceWebAppLogo, setEnableReplaceWebAppLogo] = useState(false)

const handleOperateUtm = () => { const handleOperateUtm = () => {
let utm let utm
try { try {
if (utm.utm_source || utm.utm_medium || utm.utm_campaign || utm.utm_content || utm.utm_term) if (utm.utm_source || utm.utm_medium || utm.utm_campaign || utm.utm_content || utm.utm_term)
operationUtm({ url: '/operation/utm', body: utm }) operationUtm({ url: '/operation/utm', body: utm })
} }
const fetchPlan = async () => {
const data = await fetchCurrentPlanInfo()
const enabled = data.billing.enabled
setEnableBilling(enabled)
setEnableReplaceWebAppLogo(data.can_replace_logo)
if (enabled) {
setPlan(parseCurrentPlan(data))
handleOperateUtm()
setIsFetchedPlan(true)
}
}
useEffect(() => { useEffect(() => {
(async () => {
const data = await fetchCurrentPlanInfo()
const enabled = data.billing.enabled
setEnableBilling(enabled)
setEnableReplaceWebAppLogo(data.can_replace_logo)
if (enabled) {
setPlan(parseCurrentPlan(data))
handleOperateUtm()
setIsFetchedPlan(true)
}
})()
fetchPlan()
}, []) }, [])


return ( return (
plan, plan,
isFetchedPlan, isFetchedPlan,
enableBilling, enableBilling,
onPlanInfoChanged: fetchPlan,
enableReplaceWebAppLogo, enableReplaceWebAppLogo,
}}> }}>
{children} {children}

Notiek ielāde…
Atcelt
Saglabāt