Files
Checkmate/client/src/Pages/StatusPage/Status/Components/ControlsHeader/index.jsx
T

170 lines
3.8 KiB
React
Raw Normal View History

2025-02-04 15:26:24 -08:00
// Components
import { Box, Stack, Typography, Button } from "@mui/material";
import Image from "../../../../../Components/Image";
import SettingsIcon from "../../../../../assets/icons/settings-bold.svg?react";
2025-02-28 13:50:02 -08:00
import ThemeSwitch from "../../../../../Components/ThemeSwitch";
import ArrowOutwardIcon from "@mui/icons-material/ArrowOutward";
2025-02-04 15:26:24 -08:00
//Utils
import { useTheme } from "@mui/material/styles";
import { useNavigate } from "react-router-dom";
import { useLocation } from "react-router-dom";
import PropTypes from "prop-types";
2025-03-17 01:16:42 +05:30
import { useTranslation } from "react-i18next";
2025-02-04 15:26:24 -08:00
const Controls = ({ isDeleteOpen, setIsDeleteOpen, isDeleting, url, type }) => {
2025-02-04 15:26:24 -08:00
const theme = useTheme();
2025-03-17 01:16:42 +05:30
const { t } = useTranslation();
const location = useLocation();
const currentPath = location.pathname;
2025-02-04 15:26:24 -08:00
const navigate = useNavigate();
2025-02-07 15:19:24 -08:00
if (currentPath.startsWith("/status/uptime/public")) {
return null;
}
2025-02-07 15:19:24 -08:00
if (currentPath.startsWith("/status/distributed/public")) {
2025-02-07 15:19:24 -08:00
return null;
}
return (
<Stack
direction="row"
gap={theme.spacing(2)}
>
<Box>
<Button
variant="contained"
color="error"
onClick={() => setIsDeleteOpen(!isDeleteOpen)}
loading={isDeleting}
>
2025-03-17 01:16:42 +05:30
{t("delete")}
</Button>
</Box>
<Box>
<Button
variant="contained"
color="secondary"
onClick={() => {
2025-02-11 09:06:18 -08:00
if (type === "uptime") {
navigate(`/status/uptime/configure/${url}`);
} else {
navigate(`/status/distributed/configure/${url}`);
}
}}
sx={{
px: theme.spacing(5),
"& svg": {
mr: theme.spacing(3),
"& path": {
stroke: theme.palette.secondary.contrastText,
},
},
}}
>
2025-03-17 01:16:42 +05:30
<SettingsIcon /> {t("configure")}
</Button>
</Box>
</Stack>
);
};
Controls.propTypes = {
2025-02-10 14:23:15 -08:00
type: PropTypes.string,
isDeleting: PropTypes.bool,
url: PropTypes.string,
isDeleteOpen: PropTypes.bool.isRequired,
setIsDeleteOpen: PropTypes.func.isRequired,
};
const ControlsHeader = ({
statusPage,
2025-02-28 13:50:02 -08:00
isPublic,
isDeleting,
isDeleteOpen,
setIsDeleteOpen,
url,
type = "uptime",
}) => {
const theme = useTheme();
const { t } = useTranslation();
const publicUrl =
type === "uptime"
? `/status/uptime/public/${url}`
: `/status/distributed/public/${url}`;
2025-02-04 15:26:24 -08:00
return (
<Stack
alignSelf="flex-start"
direction="row"
width="100%"
gap={theme.spacing(2)}
justifyContent="space-between"
alignItems="flex-end"
>
<Stack
2025-02-26 15:53:10 -08:00
direction="row"
2025-02-04 15:26:24 -08:00
gap={theme.spacing(8)}
2025-02-26 15:53:10 -08:00
alignItems="flex-end"
2025-02-04 15:26:24 -08:00
>
<Image
shouldRender={statusPage?.logo?.data ? true : false}
alt={"Company logo"}
2025-02-07 14:49:38 -08:00
maxWidth={"300px"}
maxHeight={"50px"}
2025-02-04 15:26:24 -08:00
base64={statusPage?.logo?.data}
/>
2025-02-28 13:50:02 -08:00
<Typography
variant="h1"
overflow="hidden"
textOverflow="ellipsis"
sx={{
maxWidth: { xs: "200px", sm: "100%" },
}}
>
{statusPage?.companyName}
</Typography>
{statusPage?.isPublished && !isPublic && (
<Stack
direction="row"
alignItems="center"
justifyContent="center"
onClick={() => {
window.open(publicUrl, "_blank", "noopener,noreferrer");
}}
sx={{
display: "inline-flex",
":hover": {
cursor: "pointer",
borderBottom: 1,
},
}}
>
<Typography>{t("publicLink")}</Typography>
<ArrowOutwardIcon />
</Stack>
)}
2025-02-04 15:26:24 -08:00
</Stack>
<Controls
isDeleting={isDeleting}
isDeleteOpen={isDeleteOpen}
setIsDeleteOpen={setIsDeleteOpen}
url={url}
type={type}
/>
2025-02-28 13:50:02 -08:00
{isPublic && <ThemeSwitch />}
2025-02-04 15:26:24 -08:00
</Stack>
);
};
ControlsHeader.propTypes = {
url: PropTypes.string,
statusPage: PropTypes.object,
2025-02-28 13:50:02 -08:00
isPublic: PropTypes.bool,
isDeleting: PropTypes.bool,
isDeleteOpen: PropTypes.bool.isRequired,
setIsDeleteOpen: PropTypes.func.isRequired,
type: PropTypes.string,
};
2025-02-04 15:26:24 -08:00
export default ControlsHeader;