Skip to content

Commit bfd7907

Browse files
authored
[UserMenu, SiteSettings] Fix errors when coming from Project Settings (#3870)
1 parent 91c7f22 commit bfd7907

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/components/AppBar/UserMenu.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import {
3131
shortenName,
3232
tabColor,
3333
} from "components/AppBar/AppBarTypes";
34-
import { clearCurrentProject } from "components/Project/ProjectActions";
35-
import { useAppDispatch } from "rootRedux/hooks";
3634
import { Path } from "types/path";
3735
import { RuntimeConfig } from "types/runtimeConfig";
3836
import { openUserGuide } from "utilities/pathUtilities";
@@ -119,7 +117,6 @@ interface UserMenuListProps {
119117
*/
120118
export function UserMenuList(props: UserMenuListProps): ReactElement {
121119
const combineAppRelease = RuntimeConfig.getInstance().appRelease();
122-
const dispatch = useAppDispatch();
123120
const { t } = useTranslation();
124121
const navigate = useNavigate();
125122

@@ -132,7 +129,6 @@ export function UserMenuList(props: UserMenuListProps): ReactElement {
132129
<MenuItem
133130
id={`${idAffix}-admin`}
134131
onClick={() => {
135-
dispatch(clearCurrentProject());
136132
navigate(Path.SiteSettings);
137133
props.onSelect();
138134
}}

src/components/SiteSettings/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
type ReactElement,
55
type ReactNode,
66
type SyntheticEvent,
7+
useEffect,
78
useState,
89
} from "react";
910
import { useTranslation } from "react-i18next";
1011

12+
import { clearCurrentProject } from "components/Project/ProjectActions";
1113
import Banners from "components/SiteSettings/Banners";
1214
import ProjectManagement from "components/SiteSettings/ProjectManagement";
1315
import UserManagement from "components/SiteSettings/UserManagement";
16+
import { useAppDispatch } from "rootRedux/hooks";
1417

1518
export const enum SiteSettingsTab {
1619
Projects,
@@ -19,10 +22,13 @@ export const enum SiteSettingsTab {
1922
}
2023

2124
export default function SiteSettings(): ReactElement {
25+
const dispatch = useAppDispatch();
2226
const { t } = useTranslation();
2327

2428
const [tab, setTab] = useState(SiteSettingsTab.Projects);
2529

30+
useEffect(() => dispatch(clearCurrentProject()), [dispatch]);
31+
2632
const handleChange = (_e: SyntheticEvent, val: SiteSettingsTab): void =>
2733
setTab(val);
2834

src/components/SiteSettings/tests/index.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ jest.mock("backend", () => ({
1313
getAllUsers: (...args: any[]) => mockGetAllUsers(...args),
1414
getBannerText: (...args: any[]) => mockGetBannerText(...args),
1515
}));
16-
jest.mock("components/Project/ProjectActions", () => ({}));
16+
jest.mock("components/Project/ProjectActions", () => ({
17+
clearCurrentProject: () => jest.fn(),
18+
}));
19+
jest.mock("rootRedux/hooks", () => ({
20+
useAppDispatch: () => jest.fn(),
21+
}));
1722

1823
const setupMocks = (): void => {
1924
mockGetAllProjects.mockResolvedValue([]);

0 commit comments

Comments
 (0)