Commit 277d21cc authored by JzoNg's avatar JzoNg

fix webapp url

parent 98136096
......@@ -3,7 +3,6 @@ import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useContext } from 'use-context-selector'
import useSWR, { useSWRConfig } from 'swr'
import AppCard from '@/app/components/app/overview/appCard'
import Loading from '@/app/components/base/loading'
import { ToastContext } from '@/app/components/base/toast'
......@@ -18,20 +17,22 @@ import type { UpdateAppSiteCodeResponse } from '@/models/app'
import { asyncRunSafe } from '@/utils'
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
import type { IAppCardProps } from '@/app/components/app/overview/appCard'
import { useStore as useAppStore } from '@/app/components/app/store'
export type ICardViewProps = {
appId: string
}
const CardView: FC<ICardViewProps> = ({ appId }) => {
const detailParams = { url: '/apps', id: appId }
const { data: response } = useSWR(detailParams, fetchAppDetail)
const { mutate } = useSWRConfig()
const { notify } = useContext(ToastContext)
const { t } = useTranslation()
const { notify } = useContext(ToastContext)
const { appDetail, setAppDetail } = useAppStore()
if (!response)
return <Loading />
const updateAppDetail = async () => {
fetchAppDetail({ url: '/apps', id: appId }).then((res) => {
setAppDetail(res)
})
}
const handleCallbackResult = (err: Error | null, message?: string) => {
const type = err ? 'error' : 'success'
......@@ -39,7 +40,7 @@ const CardView: FC<ICardViewProps> = ({ appId }) => {
message ||= (type === 'success' ? 'modifiedSuccessfully' : 'modifiedUnsuccessfully')
if (type === 'success')
mutate(detailParams)
updateAppDetail()
notify({
type,
......@@ -92,10 +93,13 @@ const CardView: FC<ICardViewProps> = ({ appId }) => {
handleCallbackResult(err, err ? 'generatedUnsuccessfully' : 'generatedSuccessfully')
}
if (!appDetail)
return <Loading />
return (
<div className="grid gap-6 grid-cols-1 xl:grid-cols-2 w-full mb-6">
<AppCard
appInfo={response}
appInfo={appDetail}
cardType="webapp"
onChangeStatus={onChangeSiteStatus}
onGenerateCode={onGenerateCode}
......@@ -103,7 +107,7 @@ const CardView: FC<ICardViewProps> = ({ appId }) => {
/>
<AppCard
cardType="api"
appInfo={response}
appInfo={appDetail}
onChangeStatus={onChangeApiStatus}
/>
</div>
......
......@@ -15,7 +15,7 @@ import s from './style.module.css'
import Loading from '@/app/components/base/loading'
import { fetchChatConversations, fetchCompletionConversations } from '@/service/log'
import { APP_PAGE_LIMIT } from '@/config'
import type { App } from '@/types/app'
import type { App, AppMode } from '@/types/app'
export type ILogsProps = {
appDetail: App
}
......@@ -67,6 +67,12 @@ const Logs: FC<ILogsProps> = ({ appDetail }) => {
...omit(queryParams, ['period']),
}
const getWebAppType = (appType: AppMode) => {
if (appType === 'completion' || appType === 'workflow')
return 'completion'
return 'chat'
}
// Get the app type first
const isChatMode = appDetail.mode !== 'completion'
......@@ -96,7 +102,7 @@ const Logs: FC<ILogsProps> = ({ appDetail }) => {
? <Loading type='app' />
: total > 0
? <List logs={isChatMode ? chatConversations : completionConversations} appDetail={appDetail} onRefresh={isChatMode ? mutateChatList : mutateCompletionList} />
: <EmptyElement appUrl={`${appDetail.site.app_base_url}/${appDetail.mode}/${appDetail.site.access_token}`} />
: <EmptyElement appUrl={`${appDetail.site.app_base_url}/${getWebAppType(appDetail.mode)}/${appDetail.site.access_token}`} />
}
{/* Show Pagination only if the total is more than the limit */}
{(total && total > APP_PAGE_LIMIT)
......
......@@ -25,7 +25,6 @@ import CopyFeedback from '@/app/components/base/copy-feedback'
import ShareQRCode from '@/app/components/base/qrcode'
import SecretKeyButton from '@/app/components/develop/secret-key/secret-key-button'
import type { AppDetailResponse } from '@/models/app'
import { AppType } from '@/types/app'
import { useAppContext } from '@/context/app-context'
export type IAppCardProps = {
......@@ -69,7 +68,7 @@ function AppCard({
api: [{ opName: t('appOverview.overview.apiInfo.doc'), opIcon: DocumentTextIcon }],
app: [],
}
if (appInfo.mode === AppType.chat)
if (appInfo.mode !== 'completion' && appInfo.mode !== 'workflow')
operationsMap.webapp.push({ opName: t('appOverview.overview.appInfo.embedded.entry'), opIcon: EmbedIcon })
if (isCurrentWorkspaceManager)
......@@ -84,7 +83,8 @@ function AppCard({
: t('appOverview.overview.apiInfo.title')
const runningStatus = isApp ? appInfo.enable_site : appInfo.enable_api
const { app_base_url, access_token } = appInfo.site ?? {}
const appUrl = `${app_base_url}/${appInfo.mode}/${access_token}`
const appMode = appInfo.mode === ('completion' || appInfo.mode === 'workflow') ? 'completion' : 'chat'
const appUrl = `${app_base_url}/${appMode}/${access_token}`
const apiUrl = appInfo?.api_base_url
let bgColor = 'bg-primary-50 bg-opacity-40'
......
......@@ -17,7 +17,7 @@ Workflow applications offers non-session support and is ideal for translation, a
The Service API uses `API-Key` authentication.
<i>**Strongly recommend storing your API Key on the server-side, not shared or stored on the client-side, to avoid possible API-Key leakage that can lead to serious consequences.**</i>
For all API requests, include your API Key in the `Authorization`HTTP Header, as shown below:
For all API requests, include your API Key in the `Authorization` HTTP Header, as shown below:
<CodeGroup title="Code">
```javascript
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment