Skip to content

Commit df320e3

Browse files
committed
feat: fixes
1 parent 0ef7ab6 commit df320e3

File tree

12 files changed

+63
-54
lines changed

12 files changed

+63
-54
lines changed

packages/addons/sitemap/admin/components/AdminRoute/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const AdminRoute = () => {
66
return (
77
<Route
88
path="/plugins/webtools/sitemap"
9-
component={App}
9+
element={<App />}
1010
/>
1111
);
1212
};

packages/addons/sitemap/admin/components/NavLink/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66

77
const NavLink = () => {
88
return (
9-
<SubNavLink href="/plugins/webtools/sitemap" active key="test">
9+
<SubNavLink href="/admin/plugins/webtools/sitemap" active key="test">
1010
Sitemap
1111
</SubNavLink>
1212
);

packages/addons/sitemap/admin/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import React from 'react';
12
import { AdminApp } from '@pluginpal/webtools-helper-plugin';
3+
import { Route } from 'react-router-dom';
24
import pluginPkg from '../package.json';
35
import pluginId from './helpers/pluginId';
46
import EditView from './components/EditView';
57
import AdminRoute from './components/AdminRoute';
68
import NavLink from './components/NavLink';
79
import getTranslation from './helpers/getTranslation';
10+
import App from './containers/Main';
811

912
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
1013
const { name } = pluginPkg.strapi;
@@ -32,7 +35,10 @@ export default {
3235

3336
app.getPlugin('webtools').injectComponent('webtoolsRouter', 'route', {
3437
name: 'settings-route',
35-
Component: AdminRoute,
38+
Component: {
39+
path: "/plugins/webtools/sitemap",
40+
element: App,
41+
},
3642
});
3743
},
3844
async registerTrads(app: any) {

packages/core/admin/containers/App/index.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Route, Switch, useHistory } from 'react-router-dom';
2+
import { Routes, Route } from 'react-router-dom';
33

44
import {
55
SubNav,
@@ -18,17 +18,17 @@ import List from '../../screens/List';
1818
import Overview from '../../screens/Overview';
1919

2020
const App = () => {
21-
const history = useHistory();
22-
2321
const getPlugin = useStrapiApp('MyComponent', (state) => state.getPlugin);
2422

2523
const plugin = getPlugin(pluginId);
24+
console.log(plugin);
2625
const sidebarComponents = plugin?.getInjectedComponents('webtoolsSidebar', 'link');
2726
const routerComponents = plugin?.getInjectedComponents('webtoolsRouter', 'route');
2827

29-
if (history.location.pathname === `/plugins/${pluginId}`) {
30-
history.replace(`/plugins/${pluginId}/overview`);
31-
}
28+
29+
// if (history.location.pathname === `/plugins/${pluginId}`) {
30+
// history.replace(`/plugins/${pluginId}/overview`);
31+
// }
3232

3333
return (
3434
<Page.Protect permissions={pluginPermissions['settings.patterns']}>
@@ -38,13 +38,13 @@ const App = () => {
3838
<SubNavHeader value="" label="Webtools" />
3939
<SubNavSections>
4040
<SubNavSection label="Core">
41-
<SubNavLink href="/plugins/webtools/overview" key="test">
41+
<SubNavLink href="/admin/plugins/webtools/overview" key="test">
4242
Overview
4343
</SubNavLink>
44-
<SubNavLink href="/plugins/webtools/urls" key="test">
44+
<SubNavLink href="/admin/plugins/webtools/urls" key="test">
4545
All URLs
4646
</SubNavLink>
47-
<SubNavLink href="/plugins/webtools/patterns" key="test">
47+
<SubNavLink href="/admin/plugins/webtools/patterns" key="test">
4848
Url Patterns
4949
</SubNavLink>
5050
</SubNavSection>
@@ -58,16 +58,27 @@ const App = () => {
5858
</SubNav>
5959
)}
6060
>
61-
<Switch>
62-
<Route path={[`/plugins/${pluginId}/overview`, `/plugins/${pluginId}`]} component={Overview} exact />
63-
<Route path={`/plugins/${pluginId}/urls`} component={List} exact />
61+
<Routes>
62+
<Route path="/overview" element={<Overview />} />
63+
<Route path="/urls" element={<List />} />
6464
<Route
65-
path={`/plugins/${pluginId}/patterns`}
66-
component={Patterns}
65+
path="/patterns"
66+
element={<Patterns />}
6767
/>
68-
{routerComponents.map(({ Component }) => <Component />)}
68+
{routerComponents.map(({ Component }) => {
69+
console.log(Component);
70+
return (
71+
<Route
72+
path={Component.path}
73+
element={<Component.element />}
74+
/>
75+
);
76+
// @ts-ignore
77+
// eslint-disable-next-line react/jsx-pascal-case
78+
return <Component.type />;
79+
})}
6980
{/* <Route path="" component={NotFound} /> */}
70-
</Switch>
81+
</Routes>
7182
</Layouts.Root>
7283
</Page.Protect>
7384
);

packages/core/admin/screens/List/components/TableRow/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { useNotification, getFetchClient } from '@strapi/strapi/admin';
1111
import { useIntl } from 'react-intl';
1212
import { Trash, ExternalLink, Pencil } from '@strapi/icons';
13-
import { useHistory } from 'react-router-dom';
13+
import { useNavigate } from 'react-router-dom';
1414
import DeleteConfirmModal from '../DeleteConfirmModal';
1515
import { Config } from '../../../../../server/admin-api/config';
1616

@@ -35,12 +35,12 @@ const TableRow: FC<Props> = ({
3535
const { get } = getFetchClient();
3636
const { formatMessage } = useIntl();
3737
const [openDeleteModal, setOpenDeleteModal] = useState(false);
38-
const { push } = useHistory();
38+
const navigate = useNavigate();
3939

4040
const handleClick = (path: string) => {
4141
get<{ link: string }>(`/webtools/url-alias/editLink?path=${path}`)
4242
.then((res) => {
43-
push(res.data.link);
43+
navigate(res.data.link);
4444
})
4545
.catch(() => { });
4646
};

packages/core/admin/screens/List/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from 'react';
22
import { useIntl } from 'react-intl';
3-
import { useHistory } from 'react-router-dom';
43

54
import { Button } from '@strapi/design-system';
65

@@ -35,7 +34,6 @@ const List = () => {
3534
const [openModal, setOpenModal] = useState<boolean>(false);
3635
const { post } = getFetchClient();
3736

38-
const history = useHistory();
3937
const { formatMessage } = useIntl();
4038
const { get } = getFetchClient();
4139
const [contentTypes, setContentTypes] = useState<EnabledContentTypes>([]);
@@ -49,18 +47,18 @@ const List = () => {
4947
.catch(() => {
5048
toggleNotification({ type: 'warning', message: formatMessage({ id: 'notification.error' }) });
5149
});
52-
}, [get, toggleNotification]);
50+
}, []);
5351

5452
useEffect(() => {
55-
get<any>(`/webtools/url-alias/findMany${history.location.search}`)
53+
get<any>(`/webtools/url-alias/findMany${window.location.search}`)
5654
.then((res) => {
5755
setPaths(res.data.results);
5856
setPagination(res.data.pagination);
5957
})
6058
.catch(() => {
6159
toggleNotification({ type: 'warning', message: formatMessage({ id: 'notification.error' }) });
6260
});
63-
}, [history.location.search, queryCount, toggleNotification]);
61+
}, [window.location.search, queryCount, toggleNotification]);
6462

6563
useEffect(() => {
6664
get<Config>('/webtools/info/config')

packages/core/admin/screens/Patterns/CreatePage/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
FormikProps,
77
FormikErrors,
88
} from 'formik';
9-
import { useHistory } from 'react-router-dom';
9+
import { useNavigate } from 'react-router-dom';
1010

1111
import {
1212
Box,
@@ -32,7 +32,7 @@ import LanguageCheckboxes from '../../../components/LanguageCheckboxes';
3232
import HiddenLocalizedField from '../../../components/HiddenLocalizedField';
3333

3434
const CreatePatternPage = () => {
35-
const { push } = useHistory();
35+
const navigate = useNavigate();
3636
const { toggleNotification } = useNotification();
3737
const [loading, setLoading] = useState(false);
3838
const [contentTypes, setContentTypes] = useState<EnabledContentTypes>([]);
@@ -62,7 +62,7 @@ const CreatePatternPage = () => {
6262
data: values,
6363
});
6464

65-
push(`/plugins/${pluginId}/patterns`);
65+
navigate(`/plugins/${pluginId}/patterns`);
6666
toggleNotification({
6767
type: 'success',
6868
message: formatMessage({ id: 'webtools.settings.success.create' }),

packages/core/admin/screens/Patterns/EditPage/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState } from 'react';
22
import { useIntl } from 'react-intl';
33
import { Formik, Form, FormikProps } from 'formik';
4-
import { useRouteMatch, useHistory } from 'react-router-dom';
4+
import { useParams, useNavigate } from 'react-router-dom';
55
import {
66
Box,
77
Link,
@@ -26,18 +26,15 @@ import HiddenLocalizedField from '../../../components/HiddenLocalizedField';
2626
import LanguageCheckboxes from '../../../components/LanguageCheckboxes';
2727

2828
const EditPatternPage = () => {
29-
const { push } = useHistory();
29+
const navigate = useNavigate();
30+
const { id } = useParams<{ id: string }>();
3031
const { toggleNotification } = useNotification();
3132
const [loading, setLoading] = useState(false);
3233
const [patternEntity, setPatternEntity] = useState<null | PatternEntity>(null);
3334
const [contentTypes, setContentTypes] = useState<EnabledContentTypes>([]);
3435
const { formatMessage } = useIntl();
3536
const { get, put, post } = getFetchClient();
3637

37-
const {
38-
params: { id },
39-
} = useRouteMatch<{ id: string }>(`/plugins/${pluginId}/patterns/:id`)!;
40-
4138
useEffect(() => {
4239
setLoading(true);
4340
get<EnabledContentTypes>('/webtools/info/getContentTypes')
@@ -75,7 +72,7 @@ const EditPatternPage = () => {
7572
data: values,
7673
});
7774

78-
push(`/plugins/${pluginId}/patterns`);
75+
navigate(`/plugins/${pluginId}/patterns`);
7976
toggleNotification({
8077
type: 'success',
8178
message: formatMessage({ id: 'webtools.settings.success.edit' }),

packages/core/admin/screens/Patterns/ListPage/components/TableBody/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import { Pencil, Trash } from '@strapi/icons';
66
import { getFetchClient, useNotification } from '@strapi/strapi/admin';
77
import { useIntl } from 'react-intl';
8-
import { useHistory } from 'react-router-dom';
8+
import { useNavigate } from 'react-router-dom';
99

1010
import pluginId from '../../../../../helpers/pluginId';
1111
import { PatternEntity } from '../../../../../types/url-patterns';
@@ -17,7 +17,7 @@ interface Props {
1717
const TableBody: React.FC<Props> = ({ patterns }) => {
1818
const [statePatterns, setStatePatterns] = useState(patterns);
1919
const { formatMessage } = useIntl();
20-
const { push } = useHistory();
20+
const navigate = useNavigate();
2121
const { toggleNotification } = useNotification();
2222
const { get } = getFetchClient();
2323

@@ -34,7 +34,7 @@ const TableBody: React.FC<Props> = ({ patterns }) => {
3434
};
3535

3636
const handleClickEdit = (id: number) => {
37-
push(`/plugins/${pluginId}/patterns/${id}`);
37+
navigate(`/plugins/${pluginId}/patterns/${id}`);
3838
};
3939

4040
return (

packages/core/admin/screens/Patterns/ListPage/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState } from 'react';
22
import { useIntl } from 'react-intl';
3-
import { useHistory } from 'react-router-dom';
3+
import { useNavigate } from 'react-router-dom';
44
import {
55
Loader,
66
Button,
@@ -19,7 +19,7 @@ const ListPatternPage = () => {
1919
const [patterns, setPatterns] = useState<PatternEntity[]>([]);
2020
const [loading, setLoading] = useState(false);
2121
const { formatMessage } = useIntl();
22-
const { push } = useHistory();
22+
const navigate = useNavigate();
2323
const { get } = getFetchClient();
2424

2525
useEffect(() => {
@@ -54,7 +54,7 @@ const ListPatternPage = () => {
5454
title={formatMessage({ id: 'webtools.settings.page.patterns.title', defaultMessage: 'Patterns' })}
5555
subtitle={formatMessage({ id: 'webtools.settings.page.patterns.description', defaultMessage: 'A list of all the known URL alias patterns.' })}
5656
primaryAction={(
57-
<Button onClick={() => push(`/plugins/${pluginId}/patterns/new`)} startIcon={<Plus />} size="L">
57+
<Button onClick={() => navigate(`/plugins/${pluginId}/patterns/new`)} startIcon={<Plus />} size="L">
5858
{formatMessage({
5959
id: 'webtools.settings.button.add_pattern',
6060
defaultMessage: 'Add new pattern',

0 commit comments

Comments
 (0)