import PropTypes from "prop-types"; import { useTheme } from "@emotion/react"; import { Box, Button, Stack, Typography, Link } from "@mui/material"; import { Link as RouterLink } from "react-router-dom"; import Skeleton from "../../assets/Images/create-placeholder.svg?react"; import SkeletonDark from "../../assets/Images/create-placeholder-dark.svg?react"; import Background from "../../assets/Images/background-grid.svg?react"; import Check from "../Check/Check"; import { useNavigate } from "react-router-dom"; import { useSelector } from "react-redux"; import Alert from "../Alert"; import { useTranslation } from "react-i18next"; import "./index.css"; import { useFetchSettings } from "../../Hooks/settingsHooks"; import { useState } from "react"; /** * Fallback component to display a fallback UI with a title, a list of checks, and a navigation button. * * @param {Object} props - The component props. * @param {string} props.title - The title to be displayed in the fallback UI. * @param {Array} props.checks - An array of strings representing the checks to display. * @param {string} [props.link="/"] - The link to navigate to. * @param {boolean} [props.vowelStart=false] - Whether the title starts with a vowel. * @param {boolean} [props.showPageSpeedWarning=false] - Whether to show the PageSpeed API warning. * @returns {JSX.Element} The rendered fallback UI. */ const Fallback = ({ title, checks, link = "/", isAdmin, vowelStart = false, showPageSpeedWarning = false, }) => { const theme = useTheme(); const navigate = useNavigate(); const mode = useSelector((state) => state.ui.mode); const { t } = useTranslation(); const [settingsData, setSettingsData] = useState(undefined); const [isLoading, error] = useFetchSettings({ setSettingsData, setIsApiKeySet: () => {}, setIsEmailPasswordSet: () => {}, }); // Custom warning message with clickable link const renderWarningMessage = () => { return ( <> {t("pageSpeedWarning")}{" "} {t("pageSpeedLearnMoreLink")} {" "} {t("pageSpeedAddApiKey")} ); }; return ( {mode === "light" ? ( ) : ( )} {vowelStart ? "An" : "A"} {title} is used to: {checks?.map((check, index) => ( ))} {/* TODO - display a different fallback if user is not an admin*/} {isAdmin && ( <> {/* Bulk create of uptime monitors */} {title === "uptime monitor" && ( )} {/* Warning box for PageSpeed monitor */} {title === "pagespeed monitor" && showPageSpeedWarning && ( svg": { color: theme.palette.warningSecondary.contrastText, }, }, }} > {settingsData?.pagespeedKeySet === false && ( )} )} )} ); }; Fallback.propTypes = { title: PropTypes.string.isRequired, checks: PropTypes.arrayOf(PropTypes.string).isRequired, link: PropTypes.string, isAdmin: PropTypes.bool, vowelStart: PropTypes.bool, showPageSpeedWarning: PropTypes.bool, }; export default Fallback;