-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
/
index.js
68 lines (57 loc) 路 2.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
*
* SettingsPage
*
*/
// NOTE TO PLUGINS DEVELOPERS:
// If you modify this file you also need to update the documentation accordingly
// Here's the file: strapi/docs/3.0.0-beta.x/plugin-development/frontend-settings-api.md
// IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED
import React, { memo, useMemo } from 'react';
import { LoadingIndicatorPage, useStrapiApp } from '@strapi/helper-plugin';
import { Switch, Redirect, Route, useParams } from 'react-router-dom';
import { Layout } from '@strapi/design-system/Layout';
import { useIntl } from 'react-intl';
import { Helmet } from 'react-helmet';
import { useSettingsMenu } from '../../hooks';
import { createRoute, makeUniqueRoutes } from '../../utils';
import ApplicationInfosPage from './pages/ApplicationInfosPage';
import { createSectionsRoutes, routes } from './utils';
import SettingsNav from './components/SettingsNav';
function SettingsPage() {
const { settingId } = useParams();
const { settings } = useStrapiApp();
const { formatMessage } = useIntl();
const { isLoading, menu } = useSettingsMenu();
// Creates the admin routes
const adminRoutes = useMemo(() => {
return makeUniqueRoutes(
routes.map(({ to, Component, exact }) => createRoute(Component, to, exact))
);
}, []);
const pluginsRoutes = createSectionsRoutes(settings);
// Since the useSettingsMenu hook can make API calls in order to check the links permissions
// We need to add a loading state to prevent redirecting the user while permissions are being checked
if (isLoading) {
return <LoadingIndicatorPage />;
}
if (!settingId) {
return <Redirect to="/settings/application-infos" />;
}
const settingTitle = formatMessage({
id: 'global.settings',
defaultMessage: 'Settings',
});
return (
<Layout sideNav={<SettingsNav menu={menu} />}>
<Helmet title={settingTitle} />
<Switch>
<Route path="/settings/application-infos" component={ApplicationInfosPage} exact />
{adminRoutes}
{pluginsRoutes}
</Switch>
</Layout>
);
}
export default memo(SettingsPage);
export { SettingsPage };