fix(client): add RemoteDocumentTitleProvider

This commit is contained in:
chenos 2022-05-24 15:07:48 +08:00
parent 17b6daf41e
commit d1afb15a7a
2 changed files with 13 additions and 3 deletions

View File

@ -13,11 +13,11 @@ import {
CollectionManagerShortcut, CollectionManagerShortcut,
compose, compose,
DesignableSwitch, DesignableSwitch,
DocumentTitleProvider,
FileStorageShortcut, FileStorageShortcut,
i18n, i18n,
MenuItemInitializers, MenuItemInitializers,
PluginManagerProvider, PluginManagerProvider,
RemoteDocumentTitleProvider,
RemoteRouteSwitchProvider, RemoteRouteSwitchProvider,
// RemoteCollectionManagerProvider, // RemoteCollectionManagerProvider,
RouteSchemaComponent, RouteSchemaComponent,
@ -47,7 +47,7 @@ apiClient.axios.interceptors.response.use(
(error) => { (error) => {
const redirectTo = error?.response?.data?.redirectTo; const redirectTo = error?.response?.data?.redirectTo;
if (redirectTo) { if (redirectTo) {
return window.location.href = redirectTo; return (window.location.href = redirectTo);
} }
notification.error({ notification.error({
message: error?.response?.data?.errors?.map?.((error: any) => { message: error?.response?.data?.errors?.map?.((error: any) => {
@ -109,7 +109,7 @@ const providers = [
ACLProvider, ACLProvider,
ChinaRegionProvider, ChinaRegionProvider,
WorkflowRouteProvider, WorkflowRouteProvider,
[DocumentTitleProvider, { addonAfter: 'NocoBase' }], RemoteDocumentTitleProvider,
]; ];
const App = compose(...providers)(() => { const App = compose(...providers)(() => {

View File

@ -1,5 +1,6 @@
import React, { createContext, useContext, useEffect, useState } from 'react'; import React, { createContext, useContext, useEffect, useState } from 'react';
import { Helmet } from 'react-helmet'; import { Helmet } from 'react-helmet';
import { useSystemSettings } from '../system-settings';
interface DocumentTitleContextProps { interface DocumentTitleContextProps {
title?: any; title?: any;
@ -32,6 +33,15 @@ export const DocumentTitleProvider: React.FC<{ addonBefore?: string; addonAfter?
); );
}; };
export const RemoteDocumentTitleProvider: React.FC = (props) => {
const ctx = useSystemSettings();
return (
<DocumentTitleProvider addonAfter={ctx?.data?.data?.title}>
{props.children}
</DocumentTitleProvider>
);
};
export const useDocumentTitle = () => { export const useDocumentTitle = () => {
return useContext(DocumentTitleContext); return useContext(DocumentTitleContext);
}; };