Skip to content

Commit

Permalink
fix: Conditionally set test env header (#3107)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored May 3, 2024
1 parent 53641ac commit f4df65a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions editor.planx.uk/src/components/TestEnvironmentBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import { visuallyHidden } from "@mui/utils";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useState } from "react";
import React from "react";

const TestEnvironmentWarning = styled(Box)(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
Expand All @@ -17,7 +17,10 @@ const TestEnvironmentWarning = styled(Box)(({ theme }) => ({
}));

const TestEnvironmentBanner: React.FC = () => {
const [isTestEnvBannerVisible, hideTestEnvBanner] = useStore(state => [state.isTestEnvBannerVisible, state.hideTestEnvBanner]);
const [isTestEnvBannerVisible, hideTestEnvBanner] = useStore((state) => [
state.isTestEnvBannerVisible,
state.hideTestEnvBanner,
]);

if (!isTestEnvBannerVisible) return null;

Expand All @@ -34,13 +37,15 @@ const TestEnvironmentBanner: React.FC = () => {
<Box display="flex" alignItems="center">
<ReportIcon color="error" />
<Typography variant="body2" ml={1}>
This is a <strong>testing environment</strong> for new features.
Do not use it to make permanent content changes.
This is a <strong>testing environment</strong> for new features. Do
not use it to make permanent content changes.
</Typography>
</Box>
<Button size="small" onClick={hideTestEnvBanner}>
Hide
<Box sx={visuallyHidden} component="span">the test environment banner</Box>
<Box sx={visuallyHidden} component="span">
the test environment banner
</Box>
</Button>
</Container>
</TestEnvironmentWarning>
Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const editorUIStore: StateCreator<
set({ showPreview: !get().showPreview });
},

isTestEnvBannerVisible: true,
isTestEnvBannerVisible: !window.location.href.includes(".uk"),

hideTestEnvBanner: () => set({ isTestEnvBannerVisible: false }),
});
Expand Down

0 comments on commit f4df65a

Please sign in to comment.