Skip to content

Commit 675c44e

Browse files
committed
NavBlocker: Block Stop page tab changes
1 parent b9036d9 commit 675c44e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

ui/src/components/forms/common/NavigationBlocker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type BlockerContext = {
7777
readonly requestNavigation: RequestNavigationFn;
7878
};
7979

80-
const navigationBlockerContext = createContext<BlockerContext>({
80+
export const navigationBlockerContext = createContext<BlockerContext>({
8181
registerBlock: () => noop,
8282
requestNavigation: noop,
8383
});

ui/src/components/stop-registry/stops/stop-details/StopDetailsPage.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { FC, useState } from 'react';
1+
import { FC, useContext, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { MdWarning } from 'react-icons/md';
44
import { useGetStopDetails, useRequiredParams } from '../../../../hooks';
55
import { Container, Visible } from '../../../../layoutComponents';
66
import { mapToShortDate } from '../../../../time';
77
import { LoadingWrapper } from '../../../../uiComponents/LoadingWrapper';
8+
import { navigationBlockerContext } from '../../../forms/common/NavigationBlocker';
89
import { BasicDetailsSection } from './basic-details/BasicDetailsSection';
910
import {
1011
DetailTabSelector,
@@ -33,12 +34,17 @@ const testIds = {
3334
};
3435

3536
export const StopDetailsPage: FC = () => {
36-
const { stopDetails, loading, error } = useGetStopDetails();
3737
const { t } = useTranslation();
38-
const [activeDetailTab, selectDetailTab] = useState(
38+
const { label } = useRequiredParams<{ label: string }>();
39+
40+
const [activeDetailTab, setActiveDetailTab] = useState(
3941
DetailTabType.BasicDetailsTab,
4042
);
41-
const { label } = useRequiredParams<{ label: string }>();
43+
const { requestNavigation } = useContext(navigationBlockerContext);
44+
const selectDetailTab = (nextTab: DetailTabType) =>
45+
requestNavigation(() => setActiveDetailTab(nextTab));
46+
47+
const { stopDetails, loading, error } = useGetStopDetails();
4248

4349
return (
4450
<Container testId={testIds.page}>

0 commit comments

Comments
 (0)