From 9edfde5759c75a90afe9298bcf58c9ace420ff26 Mon Sep 17 00:00:00 2001 From: haitaoo Date: Fri, 21 Apr 2023 12:36:48 +0800 Subject: [PATCH] fix(user-center): Set the pageTitle for the user center page --- ui/src/pages/UserCenter/Auth/index.tsx | 6 ++++++ ui/src/pages/UserCenter/AuthFailed/index.tsx | 6 ++++++ ui/src/stores/pageTags.ts | 4 +++- ui/src/utils/guard.ts | 5 +++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ui/src/pages/UserCenter/Auth/index.tsx b/ui/src/pages/UserCenter/Auth/index.tsx index 7a43fa09..9387daea 100644 --- a/ui/src/pages/UserCenter/Auth/index.tsx +++ b/ui/src/pages/UserCenter/Auth/index.tsx @@ -1,19 +1,25 @@ import { memo } from 'react'; import { Container, Col } from 'react-bootstrap'; import { useSearchParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; import { userCenterStore } from '@/stores'; import { USER_AGENT_NAMES } from '@/common/constants'; +import { usePageTags } from '@/hooks'; import WeComAuth from './components/WeCom'; const Index = () => { + const { t } = useTranslation('translation'); const [searchParam] = useSearchParams(); const { agent: ucAgent } = userCenterStore(); let agentName = ucAgent?.agent_info.name || ''; if (searchParam.get('agent_name')) { agentName = searchParam.get('agent_name') || ''; } + usePageTags({ + title: t('login', { keyPrefix: 'page_title' }), + }); return ( diff --git a/ui/src/pages/UserCenter/AuthFailed/index.tsx b/ui/src/pages/UserCenter/AuthFailed/index.tsx index 107ebbb3..05c9c78d 100644 --- a/ui/src/pages/UserCenter/AuthFailed/index.tsx +++ b/ui/src/pages/UserCenter/AuthFailed/index.tsx @@ -1,19 +1,25 @@ import { memo } from 'react'; import { Container } from 'react-bootstrap'; import { useSearchParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; import { userCenterStore } from '@/stores'; import { USER_AGENT_NAMES } from '@/common/constants'; +import { usePageTags } from '@/hooks'; import WeCom from './components/WeCom'; const Index = () => { + const { t } = useTranslation('translation'); const [searchParam] = useSearchParams(); const { agent: ucAgent } = userCenterStore(); let agentName = ucAgent?.agent_info.name || ''; if (searchParam.get('agent_name')) { agentName = searchParam.get('agent_name') || ''; } + usePageTags({ + title: t('login', { keyPrefix: 'page_title' }), + }); return ( {USER_AGENT_NAMES.WeCom.toLowerCase() === agentName.toLowerCase() ? ( diff --git a/ui/src/stores/pageTags.ts b/ui/src/stores/pageTags.ts index 6455f937..7b036fa9 100644 --- a/ui/src/stores/pageTags.ts +++ b/ui/src/stores/pageTags.ts @@ -33,7 +33,9 @@ const pageTags = create((set) => ({ o.pageTitle = makePageTitle(params.title, params.subtitle); } o.description = - params.description || siteInfoStore.getState().siteInfo.description; + params.description || + siteInfoStore.getState().siteInfo?.description || + ''; o.keywords = params.keywords || ''; set({ diff --git a/ui/src/utils/guard.ts b/ui/src/utils/guard.ts index e13d7466..7f016f91 100644 --- a/ui/src/utils/guard.ts +++ b/ui/src/utils/guard.ts @@ -9,6 +9,7 @@ import { themeSettingStore, seoSettingStore, loginToContinueStore, + pageTagStore, } from '@/stores'; import { RouteAlias } from '@/router/alias'; import { @@ -373,6 +374,10 @@ export const initAppSettingsStore = async () => { .updateVersion(appSettings.version, appSettings.revision); siteInfoStore.getState().updateUsers(appSettings.site_users); interfaceStore.getState().update(appSettings.interface); + pageTagStore.getState().update({ + title: appSettings.general?.name, + description: appSettings.general?.description, + }); brandingStore.getState().update(appSettings.branding); loginSettingStore.getState().update(appSettings.login); customizeStore.getState().update(appSettings.custom_css_html);