import ConfigBox from "@/Components/v1/ConfigBox/index.jsx"; import { Box, Stack, Typography } from "@mui/material"; import { CustomThreshold } from "./CustomThreshold/index.jsx"; import { capitalizeFirstLetter } from "../../../../Utils/stringUtils.js"; import { useTheme } from "@emotion/react"; import { useTranslation } from "react-i18next"; import PropTypes from "prop-types"; const CustomAlertsSection = ({ errors, onChange, infrastructureMonitor, handleCheckboxChange, }) => { const theme = useTheme(); const { t } = useTranslation(); const METRICS = ["cpu", "memory", "disk", "temperature"]; const METRIC_PREFIX = "usage_"; const hasAlertError = (errors) => { return Object.keys(errors).filter((k) => k.startsWith(METRIC_PREFIX)).length > 0; }; const getAlertError = (errors) => { const errorKey = Object.keys(errors).find((key) => key.startsWith(METRIC_PREFIX)); return errorKey ? errors[errorKey] : null; }; return ( {t("infrastructureCustomizeAlerts")} {t("infrastructureAlertNotificationDescription")} {METRICS.map((metric) => { return ( ); })} {hasAlertError(errors) && ( {getAlertError(errors)} )} ); }; CustomAlertsSection.propTypes = { errors: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired, infrastructureMonitor: PropTypes.object.isRequired, handleCheckboxChange: PropTypes.func.isRequired, }; export default CustomAlertsSection;