Files
Checkmate/client/src/Components/v2/common/controls/HeaderMonitorControls.tsx
T

102 lines
2.4 KiB
TypeScript
Raw Normal View History

2026-01-25 02:09:33 +00:00
import Stack from "@mui/material/Stack";
2026-01-25 03:20:58 +00:00
import { Icon, MonitorStatus } from "@/Components/v2/design-elements";
import { Button } from "@/Components/v2/inputs";
import { Settings, Pause, Play, Mail, Bug } from "lucide-react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { useTheme } from "@mui/material/styles";
2026-01-26 02:37:59 +00:00
import { usePost } from "@/Hooks/UseApi";
2026-01-25 02:09:33 +00:00
import type { Monitor } from "@/Types/Monitor.js";
interface HeaderMonitorControlsProps {
2026-01-25 03:20:58 +00:00
path: string;
2026-01-25 04:09:40 +00:00
monitor?: Monitor;
2026-01-25 03:20:58 +00:00
isAdmin: boolean;
2026-01-26 02:37:59 +00:00
refetch: Function;
2026-01-25 02:09:33 +00:00
}
2026-01-25 03:20:58 +00:00
export const HeaderMonitorControls = ({
path,
monitor,
isAdmin,
2026-01-26 02:37:59 +00:00
refetch,
2026-01-25 03:20:58 +00:00
}: HeaderMonitorControlsProps) => {
const { t } = useTranslation();
const navigate = useNavigate();
const theme = useTheme();
2026-01-26 02:37:59 +00:00
const {
post,
loading: isPosting,
// error: postError,
} = usePost<any, Monitor>();
2026-01-25 04:09:40 +00:00
if (!monitor) {
return null;
}
2026-01-25 02:09:33 +00:00
return (
<Stack
2026-01-25 04:09:40 +00:00
spacing={{ xs: theme.spacing(8), md: 0 }}
2026-01-25 03:20:58 +00:00
direction={{ xs: "column", md: "row" }}
alignItems={"center"}
2026-01-25 02:09:33 +00:00
justifyContent={"space-between"}
>
<MonitorStatus monitor={monitor} />
2026-01-25 03:20:58 +00:00
<Stack
width={{ xs: "100%", md: "auto" }}
direction={{ xs: "column", md: "row" }}
gap={theme.spacing(2)}
>
<Button
variant="contained"
color="secondary"
2026-01-26 02:37:59 +00:00
loading={isPosting}
2026-01-25 03:20:58 +00:00
startIcon={<Icon icon={Mail} />}
2026-01-26 02:37:59 +00:00
onClick={async () => {
await post(`/notifications/test/all`, { monitorId: monitor.id });
2026-01-25 03:20:58 +00:00
}}
sx={{
whiteSpace: "nowrap",
}}
>
{t("common.buttons.testNotifications")}
</Button>
<Button
variant="contained"
color="secondary"
startIcon={<Icon icon={Bug} />}
2026-01-26 17:15:08 +00:00
onClick={() => {
2026-01-25 03:20:58 +00:00
navigate(`/incidents/${monitor?.id}`);
}}
>
{t("common.buttons.incidents")}
</Button>
{isAdmin && (
<Button
variant="contained"
color="secondary"
2026-01-26 02:37:59 +00:00
loading={isPosting}
2026-01-25 03:20:58 +00:00
startIcon={monitor?.isActive ? <Icon icon={Pause} /> : <Icon icon={Play} />}
2026-01-26 02:37:59 +00:00
onClick={async () => {
await post(`/monitors/pause/${monitor.id}`, {});
await refetch();
2026-01-25 03:20:58 +00:00
}}
>
{monitor?.isActive ? t("pause") : t("resume")}
</Button>
)}
{isAdmin && (
<Button
variant="contained"
color="secondary"
startIcon={<Icon icon={Settings} />}
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
>
Configure
</Button>
)}
</Stack>
2026-01-25 02:09:33 +00:00
</Stack>
);
};