index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import useSWR, { useSWRConfig } from 'swr'
  5. import { createApp, fetchAppDetail, fetchAppList, getAppDailyConversations, getAppDailyEndUsers, updateAppApiStatus, updateAppModelConfig, updateAppRateLimit, updateAppSiteAccessToken, updateAppSiteConfig, updateAppSiteStatus } from '../apps'
  6. import Loading from '@/app/components/base/loading'
  7. const Service: FC = () => {
  8. const { data: appList, error: appListError } = useSWR({ url: '/apps', params: { page: 1 } }, fetchAppList)
  9. const { data: firstApp, error: appDetailError } = useSWR({ url: '/apps', id: '1' }, fetchAppDetail)
  10. const { data: updateAppSiteStatusRes, error: err1 } = useSWR({ url: '/apps', id: '1', body: { enable_site: false } }, updateAppSiteStatus)
  11. const { data: updateAppApiStatusRes, error: err2 } = useSWR({ url: '/apps', id: '1', body: { enable_api: true } }, updateAppApiStatus)
  12. const { data: updateAppRateLimitRes, error: err3 } = useSWR({ url: '/apps', id: '1', body: { api_rpm: 10, api_rph: 20 } }, updateAppRateLimit)
  13. const { data: updateAppSiteCodeRes, error: err4 } = useSWR({ url: '/apps', id: '1', body: {} }, updateAppSiteAccessToken)
  14. const { data: updateAppSiteConfigRes, error: err5 } = useSWR({ url: '/apps', id: '1', body: { title: 'title test', author: 'author test' } }, updateAppSiteConfig)
  15. const { data: getAppDailyConversationsRes, error: err6 } = useSWR({ url: '/apps', id: '1', body: { start: '1', end: '2' } }, getAppDailyConversations)
  16. const { data: getAppDailyEndUsersRes, error: err7 } = useSWR({ url: '/apps', id: '1', body: { start: '1', end: '2' } }, getAppDailyEndUsers)
  17. const { data: updateAppModelConfigRes, error: err8 } = useSWR({ url: '/apps', id: '1', body: { model_id: 'gpt-100' } }, updateAppModelConfig)
  18. const { mutate } = useSWRConfig()
  19. const handleCreateApp = async () => {
  20. await createApp({
  21. name: `new app${Math.round(Math.random() * 100)}`,
  22. mode: 'chat',
  23. })
  24. // reload app list
  25. mutate({ url: '/apps', params: { page: 1 } })
  26. }
  27. if (appListError || appDetailError || err1 || err2 || err3 || err4 || err5 || err6 || err7 || err8)
  28. return <div>{JSON.stringify(appListError)}</div>
  29. if (!appList || !firstApp || !updateAppSiteStatusRes || !updateAppApiStatusRes || !updateAppRateLimitRes || !updateAppSiteCodeRes || !updateAppSiteConfigRes || !getAppDailyConversationsRes || !getAppDailyEndUsersRes || !updateAppModelConfigRes)
  30. return <Loading />
  31. return (
  32. <div>
  33. <div className='flex flex-col gap-3'>
  34. <div>
  35. <div>1.App list</div>
  36. <div>
  37. {appList.data.map(item => (
  38. <div key={item.id}>{item.id} {item.name}</div>
  39. ))}
  40. </div>
  41. </div>
  42. <div>
  43. <div>2.First app detail</div>
  44. <div>{JSON.stringify(firstApp)}</div>
  45. </div>
  46. <div>
  47. <button onClick={handleCreateApp}>Click me to Create App</button>
  48. </div>
  49. <div>
  50. <div>4.updateAppSiteStatusRes</div>
  51. <div>{JSON.stringify(updateAppSiteStatusRes)}</div>
  52. </div>
  53. <div>
  54. <div>5.updateAppApiStatusRes</div>
  55. <div>{JSON.stringify(updateAppApiStatusRes)}</div>
  56. </div>
  57. <div>
  58. <div>6.updateAppRateLimitRes</div>
  59. <div>{JSON.stringify(updateAppRateLimitRes)}</div>
  60. </div>
  61. <div>
  62. <div>7.updateAppSiteCodeRes</div>
  63. <div>{JSON.stringify(updateAppSiteCodeRes)}</div>
  64. </div>
  65. <div>
  66. <div>8.updateAppSiteConfigRes</div>
  67. <div>{JSON.stringify(updateAppSiteConfigRes)}</div>
  68. </div>
  69. <div>
  70. <div>9.getAppDailyConversationsRes</div>
  71. <div>{JSON.stringify(getAppDailyConversationsRes)}</div>
  72. </div>
  73. <div>
  74. <div>10.getAppDailyEndUsersRes</div>
  75. <div>{JSON.stringify(getAppDailyEndUsersRes)}</div>
  76. </div>
  77. <div>
  78. <div>11.updateAppModelConfigRes</div>
  79. <div>{JSON.stringify(updateAppModelConfigRes)}</div>
  80. </div>
  81. </div>
  82. </div>
  83. )
  84. }
  85. export default React.memo(Service)