diff --git a/web/app/(commonLayout)/apps/AppCard.tsx b/web/app/(commonLayout)/apps/AppCard.tsx
index e917e2422a..8764a722b2 100644
--- a/web/app/(commonLayout)/apps/AppCard.tsx
+++ b/web/app/(commonLayout)/apps/AppCard.tsx
@@ -122,14 +122,7 @@ const AppCard = ({ app, onRefresh }: AppCardProps) => {
message: t('app.newApp.appCreated'),
})
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
- if (!isCurrentWorkspaceManager) {
- push(`/app/${newApp.id}/overview`)
- }
- else {
- if (newApp.mode === 'workflow' || newApp.mode === 'advanced-chat')
- push(`/app/${newApp.id}/workflow`)
- push(`/app/${newApp.id}/configuration`)
- }
+ getRedirection(isCurrentWorkspaceManager, newApp, push)
}
catch (e) {
notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
diff --git a/web/app/components/app/create-app-dialog/appForm.tsx b/web/app/components/app/create-app-dialog/appForm.tsx
index 6310b67759..41737110a5 100644
--- a/web/app/components/app/create-app-dialog/appForm.tsx
+++ b/web/app/components/app/create-app-dialog/appForm.tsx
@@ -19,6 +19,7 @@ import { ChatBot, CuteRobot } from '@/app/components/base/icons/src/vender/line/
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
import { Route } from '@/app/components/base/icons/src/vender/line/mapsAndTravel'
import TooltipPlus from '@/app/components/base/tooltip-plus'
+import { getRedirection } from '@/utils/app-redirection'
export type AppFormProps = {
onConfirm: () => void
@@ -32,7 +33,7 @@ const AppForm = ({
onTipChange,
}: AppFormProps) => {
const { t } = useTranslation()
- const router = useRouter()
+ const { push } = useRouter()
const { notify } = useContext(ToastContext)
const mutateApps = useContextSelector(AppsContext, state => state.mutateApps)
@@ -73,21 +74,13 @@ const AppForm = ({
onConfirm()
onHide()
mutateApps()
- if (!isCurrentWorkspaceManager) {
- router.push(`/app/${app.id}/overview`)
- }
- else {
- if (app.mode === 'workflow' || app.mode === 'advanced-chat')
- router.push(`/app/${app.id}/workflow`)
- else
- router.push(`/app/${app.id}/configuration`)
- }
+ getRedirection(isCurrentWorkspaceManager, app, push)
}
catch (e) {
notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
}
isCreatingRef.current = false
- }, [name, notify, t, appMode, emoji.icon, emoji.icon_background, description, onConfirm, onHide, mutateApps, router, isCurrentWorkspaceManager])
+ }, [name, notify, t, appMode, emoji.icon, emoji.icon_background, description, onConfirm, onHide, mutateApps, push, isCurrentWorkspaceManager])
return (
diff --git a/web/app/components/app/create-from-dsl-modal/index.tsx b/web/app/components/app/create-from-dsl-modal/index.tsx
index 344751ef30..51747f3b93 100644
--- a/web/app/components/app/create-from-dsl-modal/index.tsx
+++ b/web/app/components/app/create-from-dsl-modal/index.tsx
@@ -15,6 +15,7 @@ import { useProviderContext } from '@/context/provider-context'
import AppsFull from '@/app/components/billing/apps-full-in-dialog'
import { XClose } from '@/app/components/base/icons/src/vender/line/general'
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
+import { getRedirection } from '@/utils/app-redirection'
type CreateFromDSLModalProps = {
show: boolean
@@ -23,7 +24,7 @@ type CreateFromDSLModalProps = {
}
const CreateFromDSLModal = ({ show, onSuccess, onClose }: CreateFromDSLModalProps) => {
- const router = useRouter()
+ const { push } = useRouter()
const { t } = useTranslation()
const { notify } = useContext(ToastContext)
const [currentFile, setDSLFile] = useState()
@@ -67,14 +68,7 @@ const CreateFromDSLModal = ({ show, onSuccess, onClose }: CreateFromDSLModalProp
onClose()
notify({ type: 'success', message: t('app.newApp.appCreated') })
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
- if (!isCurrentWorkspaceManager) {
- router.push(`/app/${app.id}/overview`)
- }
- else {
- if (app.mode === 'workflow' || app.mode === 'advanced-chat')
- router.push(`/app/${app.id}/workflow`)
- router.push(`/app/${app.id}/configuration`)
- }
+ getRedirection(isCurrentWorkspaceManager, app, push)
}
catch (e) {
notify({ type: 'error', message: t('app.newApp.appCreateFailed') })
diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx
index 77eeca775b..6f2c72483c 100644
--- a/web/app/components/explore/app-list/index.tsx
+++ b/web/app/components/explore/app-list/index.tsx
@@ -20,6 +20,7 @@ import type { CreateAppModalProps } from '@/app/components/explore/create-app-mo
import Loading from '@/app/components/base/loading'
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
import { useAppContext } from '@/context/app-context'
+import { getRedirection } from '@/utils/app-redirection'
type AppsProps = {
pageType?: PageType
@@ -35,7 +36,7 @@ const Apps = ({
}: AppsProps) => {
const { t } = useTranslation()
const { isCurrentWorkspaceManager } = useAppContext()
- const router = useRouter()
+ const { push } = useRouter()
const { hasEditPermission } = useContext(ExploreContext)
const allCategoriesEn = t('explore.apps.allCategories', { lng: 'en' })
@@ -89,14 +90,7 @@ const Apps = ({
message: t('app.newApp.appCreated'),
})
localStorage.setItem(NEED_REFRESH_APP_LIST_KEY, '1')
- if (!isCurrentWorkspaceManager) {
- router.push(`/app/${app.id}/overview`)
- }
- else {
- if (app.mode === 'workflow' || app.mode === 'advanced-chat')
- router.push(`/app/${app.id}/workflow`)
- router.push(`/app/${app.id}/configuration`)
- }
+ getRedirection(isCurrentWorkspaceManager, app, push)
}
catch (e) {
Toast.notify({ type: 'error', message: t('app.newApp.appCreateFailed') })