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

View File

@ -1,5 +1,6 @@
import React, { createContext, useContext, useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';
import { useSystemSettings } from '../system-settings';
interface DocumentTitleContextProps {
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 = () => {
return useContext(DocumentTitleContext);
};