Files
Checkmate/client/src/Components/MonitorDetailsControlHeader/index.jsx
T

119 lines
3.1 KiB
React
Raw Normal View History

import Stack from "@mui/material/Stack";
import Status from "./status";
import Skeleton from "./skeleton";
import Button from "@mui/material/Button";
import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
import PauseOutlinedIcon from "@mui/icons-material/PauseOutlined";
import PlayArrowOutlinedIcon from "@mui/icons-material/PlayArrowOutlined";
2025-05-19 23:42:33 +05:30
import EmailIcon from "@mui/icons-material/Email";
// Utils
import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";
import { useTheme } from "@mui/material/styles";
2025-06-12 12:44:46 +08:00
import { usePauseMonitor } from "../../Hooks/monitorHooks";
2025-05-17 11:51:31 +05:30
import { useSendTestEmail } from "../../Hooks/useSendTestEmail";
2025-05-19 23:21:00 +05:30
import { useTranslation } from "react-i18next";
2025-05-15 12:19:39 -07:00
/**
* MonitorDetailsControlHeader component displays the control header for monitor details.
* It includes status display, pause/resume button, and a configure button for admins.
*
* @component
* @param {Object} props - Component props
* @param {string} props.path - The base path for navigation
* @param {boolean} [props.isLoading=false] - Flag indicating if the data is loading
* @param {boolean} [props.isAdmin=false] - Flag indicating if the user is an admin
* @param {Object} props.monitor - The monitor object containing details
* @param {Function} props.triggerUpdate - Function to trigger an update
* @returns {JSX.Element} The rendered component
*/
const MonitorDetailsControlHeader = ({
path,
isLoading = false,
isAdmin = false,
monitor,
triggerUpdate,
}) => {
const navigate = useNavigate();
const theme = useTheme();
2025-05-19 23:21:00 +05:30
const { t } = useTranslation();
2025-06-12 12:44:46 +08:00
const [pauseMonitor, isPausing, error] = usePauseMonitor();
2025-05-17 11:51:31 +05:30
const [isSending, emailError, sendTestEmail] = useSendTestEmail();
if (isLoading) {
return <Skeleton />;
}
return (
<Stack
direction="row"
justifyContent="space-between"
>
<Status monitor={monitor} />
<Stack
direction="row"
gap={theme.spacing(2)}
>
2025-05-17 11:51:31 +05:30
<Button
variant="contained"
2025-05-19 23:21:00 +05:30
color="secondary"
2025-05-17 11:51:31 +05:30
loading={isSending}
startIcon={<EmailIcon />}
2025-05-23 12:22:32 -07:00
onClick={() => {
sendTestEmail();
}}
2025-05-17 11:51:31 +05:30
>
2025-05-19 23:21:00 +05:30
{t("sendTestEmail")}
2025-05-17 11:51:31 +05:30
</Button>
2025-05-19 23:42:33 +05:30
<Button
variant="contained"
color="secondary"
onClick={(e) => {
navigate(`/incidents/${monitor?._id}`);
}}
>
{t("menu.incidents")}
</Button>
<Button
variant="contained"
color="secondary"
2025-05-15 11:19:24 -07:00
loading={isPausing}
startIcon={
monitor?.isActive ? <PauseOutlinedIcon /> : <PlayArrowOutlinedIcon />
}
onClick={() => {
2025-06-12 12:44:46 +08:00
pauseMonitor({
monitorId: monitor?._id,
triggerUpdate,
});
}}
>
{monitor?.isActive ? "Pause" : "Resume"}
</Button>
{isAdmin && (
<Button
variant="contained"
color="secondary"
startIcon={<SettingsOutlinedIcon />}
onClick={() => navigate(`/${path}/configure/${monitor._id}`)}
>
Configure
</Button>
)}
</Stack>
</Stack>
);
};
MonitorDetailsControlHeader.propTypes = {
path: PropTypes.string,
isLoading: PropTypes.bool,
isAdmin: PropTypes.bool,
monitor: PropTypes.object,
triggerUpdate: PropTypes.func,
};
export default MonitorDetailsControlHeader;