2026-01-25 02:09:33 +00:00
|
|
|
import Stack from "@mui/material/Stack";
|
2026-02-20 18:13:39 +00:00
|
|
|
import { Icon, MonitorStatus } from "@/Components/design-elements";
|
|
|
|
|
import { Button } from "@/Components/inputs";
|
2026-01-30 20:55:24 +00:00
|
|
|
import { Settings, Pause, Play, Mail, Bug, Trash } from "lucide-react";
|
2026-01-25 03:20:58 +00:00
|
|
|
|
|
|
|
|
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";
|
2026-01-30 20:55:24 +00:00
|
|
|
interface BaseHeaderProps {
|
|
|
|
|
monitor: Monitor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const BaseHeader = ({ monitor, children }: React.PropsWithChildren<BaseHeaderProps>) => {
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
return (
|
|
|
|
|
<Stack
|
|
|
|
|
spacing={{ xs: theme.spacing(8), md: 0 }}
|
|
|
|
|
direction={{ xs: "column", md: "row" }}
|
|
|
|
|
alignItems={"center"}
|
|
|
|
|
justifyContent={"space-between"}
|
|
|
|
|
>
|
|
|
|
|
<MonitorStatus monitor={monitor} />
|
|
|
|
|
{children}
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
2026-01-25 02:09:33 +00:00
|
|
|
|
|
|
|
|
interface HeaderMonitorControlsProps {
|
2026-01-25 03:20:58 +00:00
|
|
|
path: string;
|
2026-01-30 20:55:24 +00:00
|
|
|
monitor?: Monitor | null;
|
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 theme = useTheme();
|
2026-01-30 21:04:14 +00:00
|
|
|
const navigate = useNavigate();
|
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 (
|
2026-01-30 20:55:24 +00:00
|
|
|
<BaseHeader 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
|
|
|
}}
|
|
|
|
|
>
|
2026-02-02 20:39:16 +00:00
|
|
|
{monitor?.isActive ? t("common.buttons.pause") : t("common.buttons.resume")}
|
2026-01-25 03:20:58 +00:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{isAdmin && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="secondary"
|
|
|
|
|
startIcon={<Icon icon={Settings} />}
|
|
|
|
|
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
|
|
|
|
>
|
2026-02-02 20:39:16 +00:00
|
|
|
{t("common.buttons.configure")}
|
2026-01-25 03:20:58 +00:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
2026-01-30 20:55:24 +00:00
|
|
|
</BaseHeader>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface HeaderDeleteControlsProps {
|
|
|
|
|
monitor?: Monitor | null;
|
|
|
|
|
isAdmin: boolean;
|
|
|
|
|
refetch: Function;
|
2026-01-30 21:04:14 +00:00
|
|
|
onDelete?: () => void;
|
2026-01-30 20:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const HeaderDeleteControls = ({
|
|
|
|
|
monitor,
|
|
|
|
|
isAdmin,
|
|
|
|
|
refetch,
|
2026-01-30 21:04:14 +00:00
|
|
|
onDelete,
|
2026-01-30 20:55:24 +00:00
|
|
|
}: HeaderDeleteControlsProps) => {
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
const {
|
|
|
|
|
post,
|
|
|
|
|
loading: isPosting,
|
|
|
|
|
// error: postError,
|
|
|
|
|
} = usePost<any, Monitor>();
|
|
|
|
|
|
|
|
|
|
if (!monitor) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<BaseHeader monitor={monitor}>
|
|
|
|
|
<Stack
|
|
|
|
|
width={{ xs: "100%", md: "auto" }}
|
|
|
|
|
direction={{ xs: "column", md: "row" }}
|
|
|
|
|
gap={theme.spacing(2)}
|
|
|
|
|
>
|
|
|
|
|
{isAdmin && (
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="secondary"
|
|
|
|
|
loading={isPosting}
|
|
|
|
|
startIcon={monitor?.isActive ? <Icon icon={Pause} /> : <Icon icon={Play} />}
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
await post(`/monitors/pause/${monitor.id}`, {});
|
|
|
|
|
await refetch();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-02-02 20:39:16 +00:00
|
|
|
{monitor?.isActive ? t("common.buttons.pause") : t("common.buttons.resume")}
|
2026-01-30 20:55:24 +00:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{isAdmin && (
|
2026-01-30 21:10:52 +00:00
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="error"
|
|
|
|
|
startIcon={<Icon icon={Trash} />}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
onDelete?.();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-30 20:55:24 +00:00
|
|
|
{t("common.buttons.delete")}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
</BaseHeader>
|
2026-01-25 02:09:33 +00:00
|
|
|
);
|
|
|
|
|
};
|