This commit is contained in:
parent
e816303958
commit
abc647dbf2
|
|
@ -37,7 +37,25 @@ export default function SetupPage() {
|
|||
} = useContext(ChatbotUIContext)
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
const pathSegments = pathname.split("/").filter(Boolean)
|
||||
const locales = i18nConfig.locales
|
||||
const defaultLocale = i18nConfig.defaultLocale
|
||||
|
||||
let locale: (typeof locales)[number] = defaultLocale
|
||||
|
||||
const segment = pathSegments[0] as (typeof locales)[number]
|
||||
|
||||
if (locales.includes(segment)) {
|
||||
locale = segment
|
||||
}
|
||||
const homePath = locale === defaultLocale ? "/" : `/${locale}`
|
||||
|
||||
|
||||
|
||||
|
||||
// 提取当前路径中的 locale 部分
|
||||
const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en"
|
||||
|
|
@ -76,7 +94,8 @@ export default function SetupPage() {
|
|||
|
||||
if (!session) {
|
||||
// 强制跳转到带有 locale 的 login 页面
|
||||
return router.push(`/${locale}/login`)
|
||||
return router.push(`${homePath}/login`)
|
||||
// return router.push(`/${locale}/login`)
|
||||
} else {
|
||||
const user = session.user
|
||||
|
||||
|
|
@ -103,7 +122,8 @@ export default function SetupPage() {
|
|||
const homeWorkspaceId = await getHomeWorkspaceByUserId(
|
||||
session.user.id
|
||||
)
|
||||
return router.push(`/${locale}/${homeWorkspaceId}/chat`)
|
||||
return router.push(`${homePath}/${homeWorkspaceId}/chat`)
|
||||
// return router.push(`/${locale}/${homeWorkspaceId}/chat`)
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
@ -124,7 +144,8 @@ export default function SetupPage() {
|
|||
const handleSaveSetupSetting = async () => {
|
||||
const session = (await supabase.auth.getSession()).data.session
|
||||
if (!session) {
|
||||
return router.push(`/${locale}/login`)
|
||||
// return router.push(`/${locale}/login`)
|
||||
return (`${homePath}/login`)
|
||||
}
|
||||
|
||||
const user = session.user
|
||||
|
|
@ -162,7 +183,8 @@ export default function SetupPage() {
|
|||
setSelectedWorkspace(homeWorkspace!)
|
||||
setWorkspaces(workspaces)
|
||||
|
||||
return router.push(`/${locale}/${homeWorkspace?.id}/chat`)
|
||||
return router.push(`${homePath}/${homeWorkspace?.id}/chat`)
|
||||
// return router.push(`/${locale}/${homeWorkspace?.id}/chat`)
|
||||
}
|
||||
|
||||
const renderStep = (stepNum: number) => {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { FC, useContext, useRef, useState } from "react"
|
|||
import { SidebarUpdateItem } from "./sidebar-update-item"
|
||||
|
||||
import { usePathname } from "next/navigation"
|
||||
|
||||
import i18nConfig from "@/i18nConfig"
|
||||
|
||||
interface SidebarItemProps {
|
||||
item: DataItemType
|
||||
|
|
@ -30,10 +30,25 @@ export const SidebarItem: FC<SidebarItemProps> = ({
|
|||
const { selectedWorkspace, setChats, setSelectedAssistant } =
|
||||
useContext(ChatbotUIContext)
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
|
||||
// 提取当前路径中的 locale 部分
|
||||
const locale = pathname.split("/")[1] || "en"
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
const pathSegments = pathname.split("/").filter(Boolean)
|
||||
const locales = i18nConfig.locales
|
||||
const defaultLocale = i18nConfig.defaultLocale
|
||||
|
||||
let locale: (typeof locales)[number] = defaultLocale
|
||||
|
||||
const segment = pathSegments[0] as (typeof locales)[number]
|
||||
|
||||
if (locales.includes(segment)) {
|
||||
locale = segment
|
||||
}
|
||||
const homePath = locale === defaultLocale ? "/" : `/${locale}`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
|
|
@ -68,7 +83,8 @@ export const SidebarItem: FC<SidebarItemProps> = ({
|
|||
setChats(prevState => [createdChat, ...prevState])
|
||||
setSelectedAssistant(assistant)
|
||||
|
||||
return router.push(`/${locale}/${selectedWorkspace.id}/chat/${createdChat.id}`)
|
||||
return router.push(`${homePath}/${selectedWorkspace.id}/chat/${createdChat.id}`)
|
||||
// return router.push(`/${locale}/${selectedWorkspace.id}/chat/${createdChat.id}`)
|
||||
},
|
||||
tools: async (item: any) => {},
|
||||
models: async (item: any) => {}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,35 @@ import { VALID_ENV_KEYS } from "@/types/valid-keys"
|
|||
import { useRouter } from "next/navigation"
|
||||
import { FC, useEffect, useState } from "react"
|
||||
|
||||
import i18nConfig from "@/i18nConfig"
|
||||
|
||||
interface GlobalStateProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export const GlobalState: FC<GlobalStateProps> = ({ children }) => {
|
||||
const router = useRouter()
|
||||
|
||||
|
||||
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
const pathSegments = pathname.split("/").filter(Boolean)
|
||||
const locales = i18nConfig.locales
|
||||
const defaultLocale = i18nConfig.defaultLocale
|
||||
|
||||
let locale: (typeof locales)[number] = defaultLocale
|
||||
|
||||
const segment = pathSegments[0] as (typeof locales)[number]
|
||||
|
||||
if (locales.includes(segment)) {
|
||||
locale = segment
|
||||
}
|
||||
const homePath = locale === defaultLocale ? "/" : `/${locale}`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// PROFILE STORE
|
||||
const [profile, setProfile] = useState<Tables<"profiles"> | null>(null)
|
||||
|
|
@ -166,10 +188,11 @@ export const GlobalState: FC<GlobalStateProps> = ({ children }) => {
|
|||
|
||||
if (!profile.has_onboarded) {
|
||||
// 提取当前路径中的 locale 部分
|
||||
const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en"
|
||||
// const locale = pathname.split("/")[1] || "en" // 获取路径中的 locale 部分,如果没有则默认为 "en"
|
||||
|
||||
// 强制跳转到带有 locale 的 setup 页面
|
||||
return router.push(`/${locale}/setup`)
|
||||
return router.push(`${homePath}/setup`)
|
||||
// return router.push(`/${locale}/setup`)
|
||||
}
|
||||
|
||||
const workspaces = await getWorkspacesByUserId(user.id)
|
||||
|
|
|
|||
|
|
@ -19,14 +19,35 @@ import { Input } from "../ui/input"
|
|||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { usePathname } from "next/navigation"
|
||||
import i18nConfig from "@/i18nConfig"
|
||||
|
||||
interface WorkspaceSwitcherProps {}
|
||||
|
||||
export const WorkspaceSwitcher: FC<WorkspaceSwitcherProps> = ({}) => {
|
||||
|
||||
const { t } = useTranslation()
|
||||
// const pathname = usePathname() // 获取当前路径
|
||||
// const locale = pathname.split("/")[1] || "en"
|
||||
|
||||
|
||||
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
const locale = pathname.split("/")[1] || "en"
|
||||
const pathSegments = pathname.split("/").filter(Boolean)
|
||||
const locales = i18nConfig.locales
|
||||
const defaultLocale = i18nConfig.defaultLocale
|
||||
|
||||
let locale: (typeof locales)[number] = defaultLocale
|
||||
|
||||
const segment = pathSegments[0] as (typeof locales)[number]
|
||||
|
||||
if (locales.includes(segment)) {
|
||||
locale = segment
|
||||
}
|
||||
const homePath = locale === defaultLocale ? "/" : `/${locale}`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
useHotkey(";", () => setOpen(prevState => !prevState))
|
||||
|
|
@ -76,7 +97,8 @@ export const WorkspaceSwitcher: FC<WorkspaceSwitcherProps> = ({}) => {
|
|||
setSelectedWorkspace(createdWorkspace)
|
||||
setOpen(false)
|
||||
|
||||
return router.push(`/${locale}/${createdWorkspace.id}/chat`)
|
||||
return router.push(`${homePath}/${createdWorkspace.id}/chat`)
|
||||
// return router.push(`/${locale}/${createdWorkspace.id}/chat`)
|
||||
}
|
||||
|
||||
const getWorkspaceName = (workspaceId: string) => {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export const DeleteWorkspace: FC<DeleteWorkspaceProps> = ({
|
|||
|
||||
setSelectedWorkspace(defaultWorkspace)
|
||||
|
||||
|
||||
const pathname = usePathname() // 获取当前路径
|
||||
const pathSegments = pathname.split("/").filter(Boolean)
|
||||
const locales = i18nConfig.locales
|
||||
const defaultLocale = i18nConfig.defaultLocale
|
||||
|
|
|
|||
Loading…
Reference in New Issue