Merge pull request #2260 from bluewave-labs/hotfix/conditional-alert-render
hotfix: conditionally render alert based on settings
This commit is contained in:
3 files changed
+43
-28
No files matched your search
@@ -111,7 +111,7 @@ const Alert = ({ variant, title, body, isToast, hasIcon = true, onClick }) => {
|
|||||||
Alert.propTypes = {
|
Alert.propTypes = {
|
||||||
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
|
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
|
||||||
title: PropTypes.string,
|
title: PropTypes.string,
|
||||||
body: PropTypes.string,
|
body: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
||||||
isToast: PropTypes.bool,
|
isToast: PropTypes.bool,
|
||||||
hasIcon: PropTypes.bool,
|
hasIcon: PropTypes.bool,
|
||||||
onClick: function (props, propName, componentName) {
|
onClick: function (props, propName, componentName) {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import { useSelector } from "react-redux";
|
|||||||
import Alert from "../Alert";
|
import Alert from "../Alert";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import { useFetchSettings } from "../../Hooks/useFetchSettings";
|
||||||
|
import { useState } from "react";
|
||||||
/**
|
/**
|
||||||
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
|
* Fallback component to display a fallback UI with a title, a list of checks, and a navigation button.
|
||||||
*
|
*
|
||||||
@@ -24,32 +25,41 @@ import "./index.css";
|
|||||||
* @returns {JSX.Element} The rendered fallback UI.
|
* @returns {JSX.Element} The rendered fallback UI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Fallback = ({ title, checks, link = "/", isAdmin, vowelStart = false, showPageSpeedWarning = false }) => {
|
const Fallback = ({
|
||||||
|
title,
|
||||||
|
checks,
|
||||||
|
link = "/",
|
||||||
|
isAdmin,
|
||||||
|
vowelStart = false,
|
||||||
|
showPageSpeedWarning = false,
|
||||||
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
const mode = useSelector((state) => state.ui.mode);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [settingsData, setSettingsData] = useState(undefined);
|
||||||
|
|
||||||
|
const [isLoading, error] = useFetchSettings({ setSettingsData });
|
||||||
// Custom warning message with clickable link
|
// Custom warning message with clickable link
|
||||||
const renderWarningMessage = () => {
|
const renderWarningMessage = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{t("pageSpeedWarning")} {" "}
|
{t("pageSpeedWarning")}{" "}
|
||||||
<Link
|
<Link
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
to="/settings"
|
to="/settings"
|
||||||
sx={{
|
sx={{
|
||||||
textDecoration: "underline",
|
textDecoration: "underline",
|
||||||
color: "inherit",
|
color: "inherit",
|
||||||
fontWeight: "inherit",
|
fontWeight: "inherit",
|
||||||
"&:hover": {
|
"&:hover": {
|
||||||
textDecoration: "underline",
|
textDecoration: "underline",
|
||||||
}
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("pageSpeedLearnMoreLink")}
|
{t("pageSpeedLearnMoreLink")}
|
||||||
</Link>
|
</Link>{" "}
|
||||||
{" "}{t("pageSpeedAddApiKey")}
|
{t("pageSpeedAddApiKey")}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -120,7 +130,7 @@ const Fallback = ({ title, checks, link = "/", isAdmin, vowelStart = false, show
|
|||||||
</Button>
|
</Button>
|
||||||
{/* Bulk create of uptime monitors */}
|
{/* Bulk create of uptime monitors */}
|
||||||
{title === "uptime monitor" && (
|
{title === "uptime monitor" && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="accent"
|
color="accent"
|
||||||
sx={{ alignSelf: "center" }}
|
sx={{ alignSelf: "center" }}
|
||||||
@@ -129,27 +139,31 @@ const Fallback = ({ title, checks, link = "/", isAdmin, vowelStart = false, show
|
|||||||
{t("bulkImport.fallbackPage")}
|
{t("bulkImport.fallbackPage")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Warning box for PageSpeed monitor */}
|
{/* Warning box for PageSpeed monitor */}
|
||||||
{(title === "pagespeed monitor" && showPageSpeedWarning) && (
|
{title === "pagespeed monitor" && showPageSpeedWarning && (
|
||||||
<Box sx={{ width: "80%", maxWidth: "600px", zIndex: 1 }}>
|
<Box sx={{ width: "80%", maxWidth: "600px", zIndex: 1 }}>
|
||||||
<Box sx={{
|
<Box
|
||||||
'& .alert.row-stack': {
|
sx={{
|
||||||
backgroundColor: theme.palette.warningSecondary.main,
|
"& .alert.row-stack": {
|
||||||
borderColor: theme.palette.warningSecondary.lowContrast,
|
backgroundColor: theme.palette.warningSecondary.main,
|
||||||
'& .MuiTypography-root': {
|
borderColor: theme.palette.warningSecondary.lowContrast,
|
||||||
color: theme.palette.warningSecondary.contrastText
|
"& .MuiTypography-root": {
|
||||||
|
color: theme.palette.warningSecondary.contrastText,
|
||||||
|
},
|
||||||
|
"& .MuiBox-root > svg": {
|
||||||
|
color: theme.palette.warningSecondary.contrastText,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'& .MuiBox-root > svg': {
|
}}
|
||||||
color: theme.palette.warningSecondary.contrastText
|
>
|
||||||
}
|
{settingsData?.pagespeedKeySet === false && (
|
||||||
}
|
<Alert
|
||||||
}}>
|
variant="warning"
|
||||||
<Alert
|
hasIcon={true}
|
||||||
variant="warning"
|
body={renderWarningMessage()}
|
||||||
hasIcon={true}
|
/>
|
||||||
body={renderWarningMessage()}
|
)}
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Vendored
+1
@@ -22,6 +22,7 @@ services:
|
|||||||
- DB_CONNECTION_STRING=mongodb://mongodb:27017/uptime_db?replicaSet=rs0
|
- DB_CONNECTION_STRING=mongodb://mongodb:27017/uptime_db?replicaSet=rs0
|
||||||
- REDIS_URL=redis://redis:6379
|
- REDIS_URL=redis://redis:6379
|
||||||
- CLIENT_HOST=http://localhost
|
- CLIENT_HOST=http://localhost
|
||||||
|
- JWT_SECRET=my_secret
|
||||||
# volumes:
|
# volumes:
|
||||||
# - /var/run/docker.sock:/var/run/docker.sock:ro
|
# - /var/run/docker.sock:/var/run/docker.sock:ro
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
Reference in new issue
Block a user