mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 22:25:58 +08:00
fix: activation page reload issue after activating (#964)
This commit is contained in:
parent
a38412de7b
commit
916d8be0ae
@ -47,13 +47,14 @@ const ActivateForm = () => {
|
|||||||
const [showSuccess, setShowSuccess] = useState(false)
|
const [showSuccess, setShowSuccess] = useState(false)
|
||||||
const defaultLanguage = useCallback(() => (window.navigator.language.startsWith('zh') ? languageMaps['zh-Hans'] : languageMaps.en) || languageMaps.en, [])
|
const defaultLanguage = useCallback(() => (window.navigator.language.startsWith('zh') ? languageMaps['zh-Hans'] : languageMaps.en) || languageMaps.en, [])
|
||||||
|
|
||||||
const showErrorMessage = (message: string) => {
|
const showErrorMessage = useCallback((message: string) => {
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message,
|
message,
|
||||||
})
|
})
|
||||||
}
|
}, [])
|
||||||
const valid = () => {
|
|
||||||
|
const valid = useCallback(() => {
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
showErrorMessage(t('login.error.nameEmpty'))
|
showErrorMessage(t('login.error.nameEmpty'))
|
||||||
return false
|
return false
|
||||||
@ -66,9 +67,9 @@ const ActivateForm = () => {
|
|||||||
showErrorMessage(t('login.error.passwordInvalid'))
|
showErrorMessage(t('login.error.passwordInvalid'))
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}, [name, password, showErrorMessage, t])
|
||||||
|
|
||||||
const handleActivate = async () => {
|
const handleActivate = useCallback(async () => {
|
||||||
if (!valid())
|
if (!valid())
|
||||||
return
|
return
|
||||||
try {
|
try {
|
||||||
@ -84,13 +85,13 @@ const ActivateForm = () => {
|
|||||||
timezone,
|
timezone,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
setLocaleOnClient(language.startsWith('en') ? 'en' : 'zh-Hans')
|
setLocaleOnClient(language.startsWith('en') ? 'en' : 'zh-Hans', false)
|
||||||
setShowSuccess(true)
|
setShowSuccess(true)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
recheck()
|
recheck()
|
||||||
}
|
}
|
||||||
}
|
}, [email, language, name, password, recheck, setLocaleOnClient, timezone, token, valid, workspaceID])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={
|
<div className={
|
||||||
|
@ -3,15 +3,15 @@ import type { Locale } from '@/i18n'
|
|||||||
|
|
||||||
type II18NContext = {
|
type II18NContext = {
|
||||||
locale: Locale
|
locale: Locale
|
||||||
i18n: Record<string, any>,
|
i18n: Record<string, any>
|
||||||
setLocaleOnClient: (locale: Locale) => void
|
setLocaleOnClient: (locale: Locale, reloadPage?: boolean) => void
|
||||||
// setI8N: (i18n: Record<string, string>) => void,
|
// setI8N: (i18n: Record<string, string>) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
const I18NContext = createContext<II18NContext>({
|
const I18NContext = createContext<II18NContext>({
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
i18n: {},
|
i18n: {},
|
||||||
setLocaleOnClient: (lang: Locale) => { }
|
setLocaleOnClient: (lang: Locale, reloadPage?: boolean) => { },
|
||||||
// setI8N: () => {},
|
// setI8N: () => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -9,8 +9,8 @@ export const getLocaleOnClient = (): Locale => {
|
|||||||
return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale
|
return Cookies.get(LOCALE_COOKIE_NAME) as Locale || i18n.defaultLocale
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setLocaleOnClient = (locale: Locale) => {
|
export const setLocaleOnClient = (locale: Locale, reloadPage = true) => {
|
||||||
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
Cookies.set(LOCALE_COOKIE_NAME, locale)
|
||||||
changeLanguage(locale)
|
changeLanguage(locale)
|
||||||
location.reload()
|
reloadPage && location.reload()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user