'use client' import type { FC } from 'react' import React from 'react' import useSWR, { useSWRConfig } from 'swr' import { createApp, fetchAppDetail, fetchAppList, getAppDailyConversations, getAppDailyEndUsers, updateAppApiStatus, updateAppModelConfig, updateAppRateLimit, updateAppSiteAccessToken, updateAppSiteConfig, updateAppSiteStatus } from '../apps' import Loading from '@/app/components/base/loading' const Service: FC = () => { const { data: appList, error: appListError } = useSWR({ url: '/apps', params: { page: 1 } }, fetchAppList) const { data: firstApp, error: appDetailError } = useSWR({ url: '/apps', id: '1' }, fetchAppDetail) const { data: updateAppSiteStatusRes, error: err1 } = useSWR({ url: '/apps', id: '1', body: { enable_site: false } }, updateAppSiteStatus) const { data: updateAppApiStatusRes, error: err2 } = useSWR({ url: '/apps', id: '1', body: { enable_api: true } }, updateAppApiStatus) const { data: updateAppRateLimitRes, error: err3 } = useSWR({ url: '/apps', id: '1', body: { api_rpm: 10, api_rph: 20 } }, updateAppRateLimit) const { data: updateAppSiteCodeRes, error: err4 } = useSWR({ url: '/apps', id: '1', body: {} }, updateAppSiteAccessToken) const { data: updateAppSiteConfigRes, error: err5 } = useSWR({ url: '/apps', id: '1', body: { title: 'title test', author: 'author test' } }, updateAppSiteConfig) const { data: getAppDailyConversationsRes, error: err6 } = useSWR({ url: '/apps', id: '1', body: { start: '1', end: '2' } }, getAppDailyConversations) const { data: getAppDailyEndUsersRes, error: err7 } = useSWR({ url: '/apps', id: '1', body: { start: '1', end: '2' } }, getAppDailyEndUsers) const { data: updateAppModelConfigRes, error: err8 } = useSWR({ url: '/apps', id: '1', body: { model_id: 'gpt-100' } }, updateAppModelConfig) const { mutate } = useSWRConfig() const handleCreateApp = async () => { await createApp({ name: `new app${Math.round(Math.random() * 100)}`, mode: 'chat', }) // reload app list mutate({ url: '/apps', params: { page: 1 } }) } if (appListError || appDetailError || err1 || err2 || err3 || err4 || err5 || err6 || err7 || err8) return
{JSON.stringify(appListError)}
if (!appList || !firstApp || !updateAppSiteStatusRes || !updateAppApiStatusRes || !updateAppRateLimitRes || !updateAppSiteCodeRes || !updateAppSiteConfigRes || !getAppDailyConversationsRes || !getAppDailyEndUsersRes || !updateAppModelConfigRes) return return (
1.App list
{appList.data.map(item => (
{item.id} {item.name}
))}
2.First app detail
{JSON.stringify(firstApp)}
4.updateAppSiteStatusRes
{JSON.stringify(updateAppSiteStatusRes)}
5.updateAppApiStatusRes
{JSON.stringify(updateAppApiStatusRes)}
6.updateAppRateLimitRes
{JSON.stringify(updateAppRateLimitRes)}
7.updateAppSiteCodeRes
{JSON.stringify(updateAppSiteCodeRes)}
8.updateAppSiteConfigRes
{JSON.stringify(updateAppSiteConfigRes)}
9.getAppDailyConversationsRes
{JSON.stringify(getAppDailyConversationsRes)}
10.getAppDailyEndUsersRes
{JSON.stringify(getAppDailyEndUsersRes)}
11.updateAppModelConfigRes
{JSON.stringify(updateAppModelConfigRes)}
) } export default React.memo(Service)