Merge pull request #2231 from bluewave-labs/fix/settings-cleanup
fix: settings cleanup
This commit is contained in:
21 files changed
+865
-532
No files matched your search
@@ -156,7 +156,7 @@ const Select = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
Select.propTypes = {
|
Select.propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ TextInput.displayName = "TextInput";
|
|||||||
|
|
||||||
TextInput.propTypes = {
|
TextInput.propTypes = {
|
||||||
type: PropTypes.string,
|
type: PropTypes.string,
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
value: PropTypes.string,
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
isRequired: PropTypes.bool,
|
isRequired: PropTypes.bool,
|
||||||
isOptional: PropTypes.bool,
|
isOptional: PropTypes.bool,
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { networkService } from "../main";
|
||||||
|
import { createToast } from "../Utils/toastUtils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const UseDeleteMonitorStats = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const deleteMonitorStats = async ({ teamId }) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await networkService.deleteChecksByTeamId({ teamId });
|
||||||
|
createToast({ body: t("settingsStatsCleared") });
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: t("settingsFailedToClearStats") });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [deleteMonitorStats, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { UseDeleteMonitorStats };
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { networkService } from "../main";
|
||||||
|
import { createToast } from "../Utils/toastUtils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const useFetchSettings = ({ setSettingsData }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(undefined);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchSettings = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await networkService.getAppSettings();
|
||||||
|
setSettingsData(response?.data?.data);
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: "Failed to fetch settings" });
|
||||||
|
setError(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchSettings();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return [isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
|
const useSaveSettings = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(undefined);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const saveSettings = async (settings) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await networkService.updateAppSettings({ settings });
|
||||||
|
if (settings.checkTTL) {
|
||||||
|
await networkService.updateChecksTTL({
|
||||||
|
ttl: settings.checkTTL,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
createToast({ body: t("settingsSuccessSaved") });
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: t("settingsFailedToSave") });
|
||||||
|
|
||||||
|
setError(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [isLoading, error, saveSettings];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { useFetchSettings, useSaveSettings };
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import Link from "../../Components/Link";
|
||||||
|
|
||||||
|
const SettingsAbout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsAbout")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Checkmate {2.0}</Typography>
|
||||||
|
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }}>
|
||||||
|
{t("settingsDevelopedBy")}
|
||||||
|
</Typography>
|
||||||
|
<Link
|
||||||
|
level="secondary"
|
||||||
|
url="https://github.com/bluewave-labs/checkmate"
|
||||||
|
label="https://github.com/bluewave-labs/checkmate"
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsAbout;
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import Dialog from "../../Components/Dialog";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const SettingsDemoMonitors = ({ HEADER_SX, handleChange, isLoading }) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
// Local state
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsDemoMonitors")}</Typography>
|
||||||
|
<Typography sx={HEADER_SX}>{t("settingsDemoMonitorsDescription")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsAddDemoMonitors")}</Typography>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
loading={isLoading}
|
||||||
|
onClick={() => {
|
||||||
|
const syntheticEvent = {
|
||||||
|
target: {
|
||||||
|
name: "demo",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
handleChange(syntheticEvent);
|
||||||
|
}}
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("settingsAddDemoMonitorsButton")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsSystemReset")}</Typography>
|
||||||
|
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||||
|
{t("settingsSystemResetDescription")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsRemoveAllMonitors")}</Typography>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
loading={isLoading}
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("settingsRemoveAllMonitorsButton")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Dialog
|
||||||
|
open={isOpen}
|
||||||
|
theme={theme}
|
||||||
|
title={t("settingsRemoveAllMonitorsDialogTitle")}
|
||||||
|
onCancel={() => setIsOpen(false)}
|
||||||
|
confirmationButtonLabel={t("settingsRemoveAllMonitorsDialogConfirm")}
|
||||||
|
onConfirm={() => {
|
||||||
|
const syntheticEvent = {
|
||||||
|
target: {
|
||||||
|
name: "deleteMonitors",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
handleChange(syntheticEvent);
|
||||||
|
setIsOpen(false);
|
||||||
|
}}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
</ConfigBox>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsDemoMonitors.propTypes = {
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
HEADER_SX: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsDemoMonitors;
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
import TextInput from "../../Components/Inputs/TextInput";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
|
||||||
|
const SettingsEmail = ({
|
||||||
|
HEADER_SX,
|
||||||
|
handleChange,
|
||||||
|
settingsData,
|
||||||
|
setSettingsData,
|
||||||
|
isPasswordSet,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [hasBeenReset, setHasBeenReset] = useState(false);
|
||||||
|
|
||||||
|
const handlePasswordChange = (e) => {
|
||||||
|
setPassword(e.target.value);
|
||||||
|
setSettingsData({
|
||||||
|
...settingsData,
|
||||||
|
settings: { ...settingsData.settings, systemEmailPassword: e.target.value },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsEmail")}</Typography>
|
||||||
|
<Typography sx={HEADER_SX}>{t("settingsEmailDescription")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Stack gap={theme.spacing(10)}>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailHost")}</Typography>
|
||||||
|
<TextInput
|
||||||
|
name="systemEmailHost"
|
||||||
|
placeholder="smtp.gmail.com"
|
||||||
|
value={settingsData?.settings?.systemEmailHost ?? ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailPort")}</Typography>
|
||||||
|
<TextInput
|
||||||
|
name="systemEmailPort"
|
||||||
|
placeholder="425"
|
||||||
|
type="number"
|
||||||
|
value={settingsData?.settings?.systemEmailPort ?? ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailUser")}</Typography>
|
||||||
|
<TextInput
|
||||||
|
name="systemEmailUser"
|
||||||
|
placeholder="Leave empty if not required"
|
||||||
|
value={settingsData?.settings?.systemEmailUser ?? ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailAddress")}</Typography>
|
||||||
|
<TextInput
|
||||||
|
name="systemEmailAddress"
|
||||||
|
placeholder="uptime@bluewavelabs.ca"
|
||||||
|
value={settingsData?.settings?.systemEmailAddress ?? ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
{(isPasswordSet === false || hasBeenReset === true) && (
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailPassword")}</Typography>
|
||||||
|
<TextInput
|
||||||
|
name="systemEmailPassword"
|
||||||
|
type="password"
|
||||||
|
placeholder="123 456 789 101112"
|
||||||
|
value={password}
|
||||||
|
onChange={handlePasswordChange}
|
||||||
|
endAdornment={<PasswordEndAdornment />}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
{isPasswordSet === true && hasBeenReset === false && (
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsEmailFieldResetLabel")}</Typography>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setPassword("");
|
||||||
|
setSettingsData({
|
||||||
|
...settingsData,
|
||||||
|
settings: { ...settingsData.settings, systemEmailPassword: "" },
|
||||||
|
});
|
||||||
|
setHasBeenReset(true);
|
||||||
|
}}
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("reset")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsEmail.propTypes = {
|
||||||
|
settingsData: PropTypes.object,
|
||||||
|
setSettingsData: PropTypes.func,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
HEADER_SX: PropTypes.object,
|
||||||
|
isPasswordSet: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsEmail;
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
import TextInput from "../../Components/Inputs/TextInput";
|
||||||
|
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const SettingsPagespeed = ({
|
||||||
|
HEADING_SX,
|
||||||
|
settingsData,
|
||||||
|
setSettingsData,
|
||||||
|
isApiKeySet,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const [apiKey, setApiKey] = useState("");
|
||||||
|
const [hasBeenReset, setHasBeenReset] = useState(false);
|
||||||
|
|
||||||
|
// Handler
|
||||||
|
const handleChange = (e) => {
|
||||||
|
setApiKey(e.target.value);
|
||||||
|
setSettingsData({
|
||||||
|
...settingsData,
|
||||||
|
settings: { ...settingsData.settings, pagespeedApiKey: e.target.value },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("pageSpeedApiKeyFieldTitle")}</Typography>
|
||||||
|
<Typography sx={HEADING_SX}>{t("pageSpeedApiKeyFieldDescription")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
{(isApiKeySet === false || hasBeenReset === true) && (
|
||||||
|
<TextInput
|
||||||
|
name="pagespeedApiKey"
|
||||||
|
label={t("pageSpeedApiKeyFieldLabel")}
|
||||||
|
value={apiKey}
|
||||||
|
type={"password"}
|
||||||
|
onChange={handleChange}
|
||||||
|
optionalLabel="(Optional)"
|
||||||
|
endAdornment={<PasswordEndAdornment />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isApiKeySet === true && hasBeenReset === false && (
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("pageSpeedApiKeyFieldResetLabel")}</Typography>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setApiKey("");
|
||||||
|
setSettingsData({
|
||||||
|
...settingsData,
|
||||||
|
settings: { ...settingsData.settings, pagespeedApiKey: "" },
|
||||||
|
});
|
||||||
|
setHasBeenReset(true);
|
||||||
|
}}
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("reset")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsPagespeed.propTypes = {
|
||||||
|
HEADING_SX: PropTypes.object,
|
||||||
|
settingsData: PropTypes.object,
|
||||||
|
setSettingsData: PropTypes.func,
|
||||||
|
isApiKeySet: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsPagespeed;
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
import TextInput from "../../Components/Inputs/TextInput";
|
||||||
|
import Dialog from "../../Components/Dialog";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const SettingsStats = ({ HEADING_SX, handleChange, settingsData, errors }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h1"
|
||||||
|
sx={HEADING_SX}
|
||||||
|
>
|
||||||
|
{t("settingsHistoryAndMonitoring")}
|
||||||
|
</Typography>
|
||||||
|
<Typography sx={{ mt: theme.spacing(2) }}>
|
||||||
|
{t("settingsHistoryAndMonitoringDescription")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<TextInput
|
||||||
|
name="checkTTL"
|
||||||
|
label={t("settingsTTLLabel")}
|
||||||
|
optionalLabel={t("settingsTTLOptionalLabel")}
|
||||||
|
value={settingsData?.settings?.checkTTL ?? ""}
|
||||||
|
onChange={handleChange}
|
||||||
|
type="number"
|
||||||
|
error={errors.checkTTL ? true : false}
|
||||||
|
helperText={errors.checkTTL}
|
||||||
|
/>
|
||||||
|
<Box>
|
||||||
|
<Typography>{t("settingsClearAllStats")}</Typography>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("settingsClearAllStatsButton")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
<Dialog
|
||||||
|
open={isOpen}
|
||||||
|
theme={theme}
|
||||||
|
title={t("settingsClearAllStatsDialogTitle")}
|
||||||
|
description={t("settingsClearAllStatsDialogDescription")}
|
||||||
|
onCancel={() => setIsOpen(false)}
|
||||||
|
confirmationButtonLabel={t("settingsClearAllStatsDialogConfirm")}
|
||||||
|
onConfirm={() => {
|
||||||
|
const syntheticEvent = {
|
||||||
|
target: {
|
||||||
|
name: "deleteStats",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
handleChange(syntheticEvent);
|
||||||
|
setIsOpen(false);
|
||||||
|
}}
|
||||||
|
isLoading={false}
|
||||||
|
/>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsStats.propTypes = {
|
||||||
|
HEADING_SX: PropTypes.object,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
settingsData: PropTypes.object,
|
||||||
|
errors: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsStats;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
import Select from "../../Components/Inputs/Select";
|
||||||
|
import timezones from "../../Utils/timezones.json";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
const SettingsTimeZone = ({ HEADING_SX, handleChange, timezone }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsGeneralSettings")}</Typography>
|
||||||
|
<Typography sx={HEADING_SX}>
|
||||||
|
<Typography component="span">{t("settingsDisplayTimezone")}</Typography>-{" "}
|
||||||
|
{t("settingsDisplayTimezoneDescription")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<Select
|
||||||
|
label={t("settingsDisplayTimezone")}
|
||||||
|
name="timezone"
|
||||||
|
value={timezone}
|
||||||
|
onChange={handleChange}
|
||||||
|
items={timezones}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsTimeZone.propTypes = {
|
||||||
|
HEADING_SX: PropTypes.object,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
timezone: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsTimeZone;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import ConfigBox from "../../Components/ConfigBox";
|
||||||
|
import Select from "../../Components/Inputs/Select";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { PropTypes } from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const SettingsUI = ({ HEADING_SX, handleChange, mode, language }) => {
|
||||||
|
const { t, i18n } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const languages = Object.keys(i18n.options.resources || {});
|
||||||
|
return (
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h1">{t("settingsAppearance")}</Typography>
|
||||||
|
<Typography sx={HEADING_SX}>{t("settingsAppearanceDescription")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<Select
|
||||||
|
name="mode"
|
||||||
|
label={t("settingsThemeMode")}
|
||||||
|
value={mode}
|
||||||
|
onChange={handleChange}
|
||||||
|
items={[
|
||||||
|
{ _id: "light", name: "Light" },
|
||||||
|
{ _id: "dark", name: "Dark" },
|
||||||
|
]}
|
||||||
|
></Select>
|
||||||
|
<Select
|
||||||
|
name="language"
|
||||||
|
label={t("settingsLanguage")}
|
||||||
|
value={language}
|
||||||
|
onChange={handleChange}
|
||||||
|
items={languages.map((lang) => ({ _id: lang, name: lang.toUpperCase() }))}
|
||||||
|
></Select>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
SettingsUI.propTypes = {
|
||||||
|
HEADING_SX: PropTypes.object,
|
||||||
|
handleChange: PropTypes.func,
|
||||||
|
mode: PropTypes.string,
|
||||||
|
language: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsUI;
|
||||||
+150
-464
@@ -1,116 +1,69 @@
|
|||||||
// Components
|
import Stack from "@mui/material/Stack";
|
||||||
import { Box, Stack, Typography, Button } from "@mui/material";
|
import Typography from "@mui/material/Typography";
|
||||||
import TextInput from "../../Components/Inputs/TextInput";
|
import Breadcrumbs from "../../Components/Breadcrumbs";
|
||||||
import Link from "../../Components/Link";
|
import SettingsTimeZone from "./SettingsTimeZone";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import SettingsUI from "./SettingsUI";
|
||||||
import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
import SettingsPagespeed from "./SettingsPagespeed";
|
||||||
import Dialog from "../../Components/Dialog";
|
import SettingsDemoMonitors from "./SettingsDemoMonitors";
|
||||||
import ConfigBox from "../../Components/ConfigBox";
|
import SettingsAbout from "./SettingsAbout";
|
||||||
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
|
import SettingsEmail from "./SettingsEmail";
|
||||||
import { getAppSettings } from "../../Features/Settings/settingsSlice";
|
import Button from "@mui/material/Button";
|
||||||
// import {
|
// Utils
|
||||||
// WalletMultiButton,
|
import { settingsValidation } from "../../Validation/validation";
|
||||||
// WalletDisconnectButton,
|
|
||||||
// } from "@solana/wallet-adapter-react-ui";
|
|
||||||
|
|
||||||
//Utils
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { logger } from "../../Utils/Logger";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
|
||||||
import { createToast } from "../../Utils/toastUtils";
|
import { createToast } from "../../Utils/toastUtils";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { setTimezone, setMode, setLanguage } from "../../Features/UI/uiSlice";
|
||||||
|
import SettingsStats from "./SettingsStats";
|
||||||
import {
|
import {
|
||||||
deleteMonitorChecksByTeamId,
|
deleteMonitorChecksByTeamId,
|
||||||
addDemoMonitors,
|
addDemoMonitors,
|
||||||
deleteAllMonitors,
|
deleteAllMonitors,
|
||||||
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { update } from "../../Features/Auth/authSlice";
|
import { useFetchSettings, useSaveSettings } from "../../Hooks/useFetchSettings";
|
||||||
import PropTypes from "prop-types";
|
import { UseDeleteMonitorStats } from "../../Hooks/useDeleteMonitorStats";
|
||||||
import { setTimezone, setMode, setLanguage } from "../../Features/UI/uiSlice";
|
|
||||||
import timezones from "../../Utils/timezones.json";
|
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { networkService } from "../../main";
|
|
||||||
import { settingsValidation } from "../../Validation/validation";
|
|
||||||
import { updateAppSettings } from "../../Features/Settings/settingsSlice";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const SECONDS_PER_DAY = 86400;
|
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
||||||
|
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const theme = useTheme();
|
// Redux state
|
||||||
const { t, i18n } = useTranslation();
|
const { mode, language, timezone } = useSelector((state) => state.ui);
|
||||||
const isAdmin = useIsAdmin();
|
|
||||||
const { user } = useSelector((state) => state.auth);
|
const { user } = useSelector((state) => state.auth);
|
||||||
const { language } = useSelector((state) => state.ui);
|
|
||||||
const { checkTTL } = user;
|
// Local state
|
||||||
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
const [settingsData, setSettingsData] = useState({});
|
||||||
const { isLoading: authIsLoading } = useSelector((state) => state.auth);
|
const [errors, setErrors] = useState({});
|
||||||
const { timezone, distributedUptimeEnabled } = useSelector((state) => state.ui);
|
// Network
|
||||||
const { mode } = useSelector((state) => state.ui);
|
const [isSettingsLoading, settingsError] = useFetchSettings({
|
||||||
const { pagespeedApiKey } = useSelector((state) => state.settings);
|
setSettingsData,
|
||||||
const [checksIsLoading, setChecksIsLoading] = useState(false);
|
|
||||||
const [form, setForm] = useState({
|
|
||||||
enableDistributedUptime: distributedUptimeEnabled,
|
|
||||||
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
|
|
||||||
pagespeedApiKey: pagespeedApiKey,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [version, setVersion] = useState("unknown");
|
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
||||||
const [apiKeyFieldType, setApiKeyFieldType] = useState("password");
|
const [deleteMonitorStats, isDeletingMonitorStats] = UseDeleteMonitorStats();
|
||||||
const [isApiKeySet, setIsApiKeySet] = useState(pagespeedApiKey ? true : false);
|
|
||||||
const [tempPSKey, setTempPSKey] = useState("");
|
// Setup
|
||||||
const [errors, setErrors] = useState({});
|
const theme = useTheme();
|
||||||
const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
|
const HEADING_SX = { mt: theme.spacing(2), mb: theme.spacing(2) };
|
||||||
const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
|
const { t, i18n } = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
//Fetching latest release version from github
|
// Handlers
|
||||||
useEffect(() => {
|
const handleChange = async (e) => {
|
||||||
const fetchLatestVersion = async () => {
|
const { name, value } = e.target;
|
||||||
let version = "unknown";
|
|
||||||
try {
|
// Build next state early
|
||||||
const response = await networkService.fetchGithubLatestRelease();
|
const newSettingsData = {
|
||||||
if (!response.status === 200) {
|
...settingsData,
|
||||||
throw new Error("Failed to fetch latest version");
|
settings: { ...settingsData.settings, [name]: value },
|
||||||
}
|
|
||||||
version = response.data.tag_name;
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: error.message || "Error fetching latest version" }); // Set error message
|
|
||||||
} finally {
|
|
||||||
setVersion(version);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
fetchLatestVersion();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
dispatch(getAppSettings());
|
|
||||||
}, [dispatch]);
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
|
||||||
const { type, checked, value, id } = event.target;
|
|
||||||
|
|
||||||
if (type === "checkbox") {
|
|
||||||
setForm((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[id]: checked,
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id === "pagespeedApiKey") {
|
|
||||||
setTempPSKey(value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let inputValue = value;
|
|
||||||
if (id === "ttl") {
|
|
||||||
inputValue = value.replace(/[^0-9]/g, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedForm = { ...form, [id]: inputValue };
|
|
||||||
const { error } = settingsValidation.validate(updatedForm, { abortEarly: false });
|
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
const { error } = settingsValidation.validate(newSettingsData.settings, {
|
||||||
|
abortEarly: false,
|
||||||
|
});
|
||||||
if (!error || error.details.length === 0) {
|
if (!error || error.details.length === 0) {
|
||||||
setErrors({});
|
setErrors({});
|
||||||
} else {
|
} else {
|
||||||
@@ -119,397 +72,130 @@ const Settings = () => {
|
|||||||
newErrors[err.path[0]] = err.message;
|
newErrors[err.path[0]] = err.message;
|
||||||
});
|
});
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
logger.error("Validation errors:", error.details);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setForm(updatedForm);
|
if (name === "timezone") {
|
||||||
};
|
dispatch(setTimezone({ timezone: value }));
|
||||||
|
|
||||||
// TODO Handle saving
|
|
||||||
const handleSave = async () => {
|
|
||||||
try {
|
|
||||||
setChecksIsLoading(true);
|
|
||||||
await networkService.updateChecksTTL({
|
|
||||||
ttl: form.ttl,
|
|
||||||
});
|
|
||||||
const updatedUser = { ...user, checkTTL: form.ttl };
|
|
||||||
const [userAction, settingsAction] = await Promise.all([
|
|
||||||
dispatch(update({ localData: updatedUser })),
|
|
||||||
dispatch(
|
|
||||||
updateAppSettings({
|
|
||||||
settings: {
|
|
||||||
language: language,
|
|
||||||
pagespeedApiKey: tempPSKey ? tempPSKey : form.pagespeedApiKey,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (userAction.payload.success && settingsAction.payload.success) {
|
|
||||||
createToast({ body: t("settingsSuccessSaved") });
|
|
||||||
} else {
|
|
||||||
throw new Error("Failed to save settings");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: t("settingsFailedToSave") });
|
|
||||||
} finally {
|
|
||||||
setChecksIsLoading(false);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleClearStats = async () => {
|
if (name === "mode") {
|
||||||
try {
|
dispatch(setMode(value));
|
||||||
const action = await dispatch(deleteMonitorChecksByTeamId({ teamId: user.teamId }));
|
|
||||||
|
|
||||||
if (deleteMonitorChecksByTeamId.fulfilled.match(action)) {
|
|
||||||
createToast({ body: t("settingsStatsCleared") });
|
|
||||||
} else {
|
|
||||||
createToast({ body: t("settingsFailedToClearStats") });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error(error);
|
|
||||||
createToast({ body: t("settingsFailedToClearStats") });
|
|
||||||
} finally {
|
|
||||||
setIsOpen(deleteStatsMonitorsInitState);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleInsertDemoMonitors = async () => {
|
if (name === "language") {
|
||||||
try {
|
dispatch(setLanguage(value));
|
||||||
const action = await dispatch(addDemoMonitors());
|
i18n.changeLanguage(value);
|
||||||
if (addDemoMonitors.fulfilled.match(action)) {
|
}
|
||||||
createToast({ body: t("settingsDemoMonitorsAdded") });
|
|
||||||
} else {
|
if (name === "deleteStats") {
|
||||||
|
await deleteMonitorStats({ teamId: user.teamId });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name === "demo") {
|
||||||
|
try {
|
||||||
|
const action = await dispatch(addDemoMonitors());
|
||||||
|
if (addDemoMonitors.fulfilled.match(action)) {
|
||||||
|
createToast({ body: t("settingsDemoMonitorsAdded") });
|
||||||
|
} else {
|
||||||
|
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
createToast({ body: t("settingsFailedToAddDemoMonitors") });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
return;
|
||||||
logger.error(error);
|
|
||||||
createToast({ Body: t("settingsFailedToAddDemoMonitors") });
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteAllMonitors = async () => {
|
if (name === "deleteMonitors") {
|
||||||
try {
|
try {
|
||||||
const action = await dispatch(deleteAllMonitors());
|
const action = await dispatch(deleteAllMonitors());
|
||||||
if (deleteAllMonitors.fulfilled.match(action)) {
|
if (deleteAllMonitors.fulfilled.match(action)) {
|
||||||
createToast({ body: t("settingsMonitorsDeleted") });
|
createToast({ body: t("settingsMonitorsDeleted") });
|
||||||
} else {
|
} else {
|
||||||
|
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
createToast({ body: t("settingsFailedToDeleteMonitors") });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
return;
|
||||||
logger.error(error);
|
|
||||||
createToast({ Body: t("settingsFailedToDeleteMonitors") });
|
|
||||||
} finally {
|
|
||||||
setIsOpen(deleteStatsMonitorsInitState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSettingsData(newSettingsData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleResetApiKey = () => {
|
const handleSave = () => {
|
||||||
setIsApiKeySet(false);
|
const { error } = settingsValidation.validate(settingsData.settings, {
|
||||||
setForm((prev) => ({
|
abortEarly: false,
|
||||||
...prev,
|
});
|
||||||
pagespeedApiKey: "",
|
if (!error || error.details.length === 0) {
|
||||||
}));
|
setErrors({});
|
||||||
|
} else {
|
||||||
|
const newErrors = {};
|
||||||
|
error.details.forEach((err) => {
|
||||||
|
newErrors[err.path[0]] = err.message;
|
||||||
|
});
|
||||||
|
setErrors(newErrors);
|
||||||
|
}
|
||||||
|
saveSettings(settingsData?.settings);
|
||||||
};
|
};
|
||||||
|
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Stack gap={theme.spacing(10)}>
|
||||||
className="settings"
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
style={{
|
<Typography variant="h1">Settings</Typography>
|
||||||
paddingBottom: 0,
|
<SettingsTimeZone
|
||||||
}}
|
HEADING_SX={HEADING_SX}
|
||||||
>
|
handleChange={handleChange}
|
||||||
|
timezone={timezone}
|
||||||
|
/>
|
||||||
|
<SettingsUI
|
||||||
|
HEADING_SX={HEADING_SX}
|
||||||
|
handleChange={handleChange}
|
||||||
|
mode={mode}
|
||||||
|
language={language}
|
||||||
|
/>
|
||||||
|
<SettingsPagespeed
|
||||||
|
HEADING_SX={HEADING_SX}
|
||||||
|
settingsData={settingsData}
|
||||||
|
setSettingsData={setSettingsData}
|
||||||
|
isApiKeySet={settingsData?.pagespeedKeySet ?? false}
|
||||||
|
/>
|
||||||
|
<SettingsStats
|
||||||
|
HEADING_SX={HEADING_SX}
|
||||||
|
settingsData={settingsData}
|
||||||
|
handleChange={handleChange}
|
||||||
|
errors={errors}
|
||||||
|
/>
|
||||||
|
<SettingsDemoMonitors
|
||||||
|
HEADER_SX={HEADING_SX}
|
||||||
|
handleChange={handleChange}
|
||||||
|
isLoading={isSettingsLoading || isSaving || isDeletingMonitorStats}
|
||||||
|
/>
|
||||||
|
<SettingsEmail
|
||||||
|
HEADER_SX={HEADING_SX}
|
||||||
|
handleChange={handleChange}
|
||||||
|
settingsData={settingsData}
|
||||||
|
setSettingsData={setSettingsData}
|
||||||
|
isPasswordSet={settingsData?.emailPasswordSet ?? false}
|
||||||
|
/>
|
||||||
|
<SettingsAbout />
|
||||||
<Stack
|
<Stack
|
||||||
component="form"
|
direction="row"
|
||||||
gap={theme.spacing(12)}
|
justifyContent="flex-end"
|
||||||
noValidate
|
|
||||||
spellCheck="false"
|
|
||||||
>
|
>
|
||||||
<ConfigBox>
|
<Button
|
||||||
<Box>
|
loading={isSaving || isDeletingMonitorStats || isSettingsLoading}
|
||||||
<Typography component="h1">{t("settingsGeneralSettings")}</Typography>
|
disabled={Object.keys(errors).length > 0}
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(2) }}>
|
variant="contained"
|
||||||
<Typography component="span">{t("settingsDisplayTimezone")}</Typography>-{" "}
|
color="accent"
|
||||||
{t("settingsDisplayTimezoneDescription")}
|
sx={{ px: theme.spacing(12), mt: theme.spacing(20) }}
|
||||||
</Typography>
|
onClick={handleSave}
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<Select
|
|
||||||
id="display-timezones"
|
|
||||||
label={t("settingsDisplayTimezone")}
|
|
||||||
value={timezone}
|
|
||||||
onChange={(e) => {
|
|
||||||
dispatch(setTimezone({ timezone: e.target.value }));
|
|
||||||
}}
|
|
||||||
items={timezones}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsAppearance")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(2) }}>
|
|
||||||
{t("settingsAppearanceDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<Select
|
|
||||||
id="theme-mode"
|
|
||||||
label={t("settingsThemeMode")}
|
|
||||||
value={mode}
|
|
||||||
onChange={(e) => {
|
|
||||||
dispatch(setMode(e.target.value));
|
|
||||||
}}
|
|
||||||
items={[
|
|
||||||
{ _id: "light", name: "Light" },
|
|
||||||
{ _id: "dark", name: "Dark" },
|
|
||||||
]}
|
|
||||||
></Select>
|
|
||||||
<Select
|
|
||||||
id="language"
|
|
||||||
label={t("settingsLanguage")}
|
|
||||||
value={language}
|
|
||||||
onChange={(e) => {
|
|
||||||
dispatch(setLanguage(e.target.value));
|
|
||||||
i18n.changeLanguage(e.target.value);
|
|
||||||
}}
|
|
||||||
items={languages.map((lang) => ({ _id: lang, name: lang.toUpperCase() }))}
|
|
||||||
></Select>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
{/* {isAdmin && (
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsDistributedUptime")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(2) }}>
|
|
||||||
{t("settingsDistributedUptimeDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Switch
|
|
||||||
id="enableDistributedUptime"
|
|
||||||
color="accent"
|
|
||||||
checked={distributedUptimeEnabled}
|
|
||||||
onChange={(e) => {
|
|
||||||
dispatch(setDistributedUptimeEnabled(e.target.checked));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{distributedUptimeEnabled === true
|
|
||||||
? t("settingsEnabled")
|
|
||||||
: t("settingsDisabled")}
|
|
||||||
</Box>
|
|
||||||
</ConfigBox>
|
|
||||||
)} */}
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("pageSpeedApiKeyFieldTitle")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(2) }}>
|
|
||||||
{t("pageSpeedApiKeyFieldDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<TextInput
|
|
||||||
id="pagespeedApiKey"
|
|
||||||
label={t("pageSpeedApiKeyFieldLabel")}
|
|
||||||
value={form.pagespeedApiKey ? form.pagespeedApiKey : tempPSKey}
|
|
||||||
type={apiKeyFieldType}
|
|
||||||
onChange={handleChange}
|
|
||||||
disabled={isApiKeySet}
|
|
||||||
optionalLabel="(Optional)"
|
|
||||||
error={!!errors.pagespeedApiKey}
|
|
||||||
helperText={errors.pagespeedApiKey}
|
|
||||||
endAdornment={
|
|
||||||
!isApiKeySet && (
|
|
||||||
<PasswordEndAdornment
|
|
||||||
fieldType={apiKeyFieldType}
|
|
||||||
setFieldType={setApiKeyFieldType}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
{isApiKeySet && (
|
|
||||||
<Box>
|
|
||||||
<Typography>{t("pageSpeedApiKeyFieldResetLabel")}</Typography>
|
|
||||||
<Button
|
|
||||||
onClick={handleResetApiKey}
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
sx={{ mt: theme.spacing(4) }}
|
|
||||||
>
|
|
||||||
{t("reset")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
{/* {isAdmin && (
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsWallet")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
|
||||||
{t("settingsWalletDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
flexWrap: "wrap",
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
gap: 2,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
spacing={2}
|
|
||||||
>
|
|
||||||
<WalletMultiButton />
|
|
||||||
<WalletDisconnectButton />
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
</ConfigBox>
|
|
||||||
)} */}
|
|
||||||
{isAdmin && (
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsHistoryAndMonitoring")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
|
||||||
{t("settingsHistoryAndMonitoringDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<TextInput
|
|
||||||
id="ttl"
|
|
||||||
label={t("settingsTTLLabel")}
|
|
||||||
optionalLabel={t("settingsTTLOptionalLabel")}
|
|
||||||
value={form.ttl}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={errors.ttl ? true : false}
|
|
||||||
helperText={errors.ttl}
|
|
||||||
/>
|
|
||||||
<Box>
|
|
||||||
<Typography>{t("settingsClearAllStats")}</Typography>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
onClick={() =>
|
|
||||||
setIsOpen({ ...deleteStatsMonitorsInitState, deleteStats: true })
|
|
||||||
}
|
|
||||||
sx={{ mt: theme.spacing(4) }}
|
|
||||||
>
|
|
||||||
{t("settingsClearAllStatsButton")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
<Dialog
|
|
||||||
open={isOpen.deleteStats}
|
|
||||||
theme={theme}
|
|
||||||
title={t("settingsClearAllStatsDialogTitle")}
|
|
||||||
description={t("settingsClearAllStatsDialogDescription")}
|
|
||||||
onCancel={() => setIsOpen(deleteStatsMonitorsInitState)}
|
|
||||||
confirmationButtonLabel={t("settingsClearAllStatsDialogConfirm")}
|
|
||||||
onConfirm={handleClearStats}
|
|
||||||
isLoading={isLoading || authIsLoading || checksIsLoading}
|
|
||||||
/>
|
|
||||||
</ConfigBox>
|
|
||||||
)}
|
|
||||||
{isAdmin && (
|
|
||||||
<>
|
|
||||||
{/* Demo Monitors Section */}
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsDemoMonitors")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
|
||||||
{t("settingsDemoMonitorsDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Typography>{t("settingsAddDemoMonitors")}</Typography>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
loading={isLoading || authIsLoading || checksIsLoading}
|
|
||||||
onClick={handleInsertDemoMonitors}
|
|
||||||
sx={{ mt: theme.spacing(4) }}
|
|
||||||
>
|
|
||||||
{t("settingsAddDemoMonitorsButton")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</ConfigBox>
|
|
||||||
|
|
||||||
{/* System Reset Section */}
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsSystemReset")}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2) }}>
|
|
||||||
{t("settingsSystemResetDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Typography>{t("settingsRemoveAllMonitors")}</Typography>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
loading={isLoading || authIsLoading || checksIsLoading}
|
|
||||||
onClick={() =>
|
|
||||||
setIsOpen({ ...deleteStatsMonitorsInitState, deleteMonitors: true })
|
|
||||||
}
|
|
||||||
sx={{ mt: theme.spacing(4) }}
|
|
||||||
>
|
|
||||||
{t("settingsRemoveAllMonitorsButton")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
<Dialog
|
|
||||||
open={isOpen.deleteMonitors}
|
|
||||||
theme={theme}
|
|
||||||
title={t("settingsRemoveAllMonitorsDialogTitle")}
|
|
||||||
onCancel={() => setIsOpen(deleteStatsMonitorsInitState)}
|
|
||||||
confirmationButtonLabel={t("settingsRemoveAllMonitorsDialogConfirm")}
|
|
||||||
onConfirm={handleDeleteAllMonitors}
|
|
||||||
isLoading={isLoading || authIsLoading || checksIsLoading}
|
|
||||||
/>
|
|
||||||
</ConfigBox>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h1">{t("settingsAbout")}</Typography>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Typography component="h2">Checkmate {version}</Typography>
|
|
||||||
<Typography sx={{ mt: theme.spacing(2), mb: theme.spacing(6), opacity: 0.6 }}>
|
|
||||||
{t("settingsDevelopedBy")}
|
|
||||||
</Typography>
|
|
||||||
<Link
|
|
||||||
level="secondary"
|
|
||||||
url="https://github.com/bluewave-labs/checkmate"
|
|
||||||
label="https://github.com/bluewave-labs/checkmate"
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</ConfigBox>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
>
|
||||||
<Button
|
{t("settingsSave")}
|
||||||
loading={isLoading || authIsLoading || checksIsLoading}
|
</Button>
|
||||||
disabled={Object.keys(errors).length > 0}
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
sx={{ px: theme.spacing(12), mt: theme.spacing(20) }}
|
|
||||||
onClick={handleSave}
|
|
||||||
>
|
|
||||||
{t("settingsSave")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
Settings.propTypes = {
|
|
||||||
isAdmin: PropTypes.bool,
|
|
||||||
};
|
|
||||||
export default Settings;
|
export default Settings;
|
||||||
@@ -11,7 +11,8 @@ const nameSchema = joi
|
|||||||
.messages({
|
.messages({
|
||||||
"string.empty": "Name is required",
|
"string.empty": "Name is required",
|
||||||
"string.max": "Name must be less than 50 characters",
|
"string.max": "Name must be less than 50 characters",
|
||||||
"string.pattern.base": "Name must contain only letters, spaces, apostrophes, or hyphens"
|
"string.pattern.base":
|
||||||
|
"Name must contain only letters, spaces, apostrophes, or hyphens",
|
||||||
});
|
});
|
||||||
|
|
||||||
const passwordSchema = joi
|
const passwordSchema = joi
|
||||||
@@ -152,20 +153,21 @@ const monitorValidation = joi.object({
|
|||||||
"string.invalidUrl": "Please enter a valid URL with optional port",
|
"string.invalidUrl": "Please enter a valid URL with optional port",
|
||||||
"string.pattern.base": "Please enter a valid container ID.",
|
"string.pattern.base": "Please enter a valid container ID.",
|
||||||
}),
|
}),
|
||||||
port: joi.number()
|
port: joi
|
||||||
.integer()
|
.number()
|
||||||
.min(1)
|
.integer()
|
||||||
.max(65535)
|
.min(1)
|
||||||
.when("type", {
|
.max(65535)
|
||||||
is: "port",
|
.when("type", {
|
||||||
then: joi.required().messages({
|
is: "port",
|
||||||
"number.base": "Port must be a number.",
|
then: joi.required().messages({
|
||||||
"number.min": "Port must be at least 1.",
|
"number.base": "Port must be a number.",
|
||||||
"number.max": "Port must be at most 65535.",
|
"number.min": "Port must be at least 1.",
|
||||||
"any.required": "Port is required for port monitors.",
|
"number.max": "Port must be at most 65535.",
|
||||||
|
"any.required": "Port is required for port monitors.",
|
||||||
|
}),
|
||||||
|
otherwise: joi.optional(),
|
||||||
}),
|
}),
|
||||||
otherwise: joi.optional(),
|
|
||||||
}),
|
|
||||||
name: joi.string().trim().max(50).allow("").messages({
|
name: joi.string().trim().max(50).allow("").messages({
|
||||||
"string.max": "This field should not exceed the 50 characters limit.",
|
"string.max": "This field should not exceed the 50 characters limit.",
|
||||||
}),
|
}),
|
||||||
@@ -253,14 +255,19 @@ const statusPageValidation = joi.object({
|
|||||||
showCharts: joi.boolean(),
|
showCharts: joi.boolean(),
|
||||||
});
|
});
|
||||||
const settingsValidation = joi.object({
|
const settingsValidation = joi.object({
|
||||||
ttl: joi.number().required().messages({
|
checkTTL: joi.number().required().messages({
|
||||||
"string.empty": "Please enter a value",
|
"string.empty": "Please enter a value",
|
||||||
"number.base": "Please enter a valid number",
|
"number.base": "Please enter a valid number",
|
||||||
"any.required": "Please enter a value"
|
"any.required": "Please enter a value",
|
||||||
}),
|
}),
|
||||||
pagespeedApiKey: joi.string().allow("").optional(),
|
pagespeedApiKey: joi.string().allow("").optional(),
|
||||||
})
|
language: joi.string().required(),
|
||||||
.unknown(true);
|
systemEmailHost: joi.string().allow(""),
|
||||||
|
systemEmailPort: joi.number().allow(null, ""),
|
||||||
|
systemEmailAddress: joi.string().allow(""),
|
||||||
|
systemEmailPassword: joi.string().allow(""),
|
||||||
|
systemEmailUser: joi.string().allow(""),
|
||||||
|
});
|
||||||
|
|
||||||
const dayjsValidator = (value, helpers) => {
|
const dayjsValidator = (value, helpers) => {
|
||||||
if (!dayjs(value).isValid()) {
|
if (!dayjs(value).isValid()) {
|
||||||
@@ -363,9 +370,12 @@ const infrastructureMonitorValidation = joi.object({
|
|||||||
notifications: joi.array().items(
|
notifications: joi.array().items(
|
||||||
joi.object({
|
joi.object({
|
||||||
type: joi.string().valid("email").required(),
|
type: joi.string().valid("email").required(),
|
||||||
address: joi.string().email({ tlds: { allow: false } }).required(),
|
address: joi
|
||||||
|
.string()
|
||||||
|
.email({ tlds: { allow: false } })
|
||||||
|
.required(),
|
||||||
})
|
})
|
||||||
)
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -377,5 +387,5 @@ export {
|
|||||||
advancedSettingsValidation,
|
advancedSettingsValidation,
|
||||||
infrastructureMonitorValidation,
|
infrastructureMonitorValidation,
|
||||||
statusPageValidation,
|
statusPageValidation,
|
||||||
logoImageValidation
|
logoImageValidation,
|
||||||
};
|
};
|
||||||
@@ -108,6 +108,14 @@
|
|||||||
"settingsFailedToAddDemoMonitors": "Failed to add demo monitors",
|
"settingsFailedToAddDemoMonitors": "Failed to add demo monitors",
|
||||||
"settingsMonitorsDeleted": "Successfully deleted all monitors",
|
"settingsMonitorsDeleted": "Successfully deleted all monitors",
|
||||||
"settingsFailedToDeleteMonitors": "Failed to delete all monitors",
|
"settingsFailedToDeleteMonitors": "Failed to delete all monitors",
|
||||||
|
"settingsEmail": "Email settings",
|
||||||
|
"settingsEmailDescription": "Configure email settings",
|
||||||
|
"settingsEmailHost": "Email host",
|
||||||
|
"settingsEmailPort": "Email port",
|
||||||
|
"settingsEmailAddress": "Email address",
|
||||||
|
"settingsEmailPassword": "Email password",
|
||||||
|
"settingsEmailUser": "Email user",
|
||||||
|
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
|
||||||
"backendUnreachable": "Server Connection Error",
|
"backendUnreachable": "Server Connection Error",
|
||||||
"backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.",
|
"backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.",
|
||||||
"backendUnreachableError": "Cannot connect to the server. Please try again later.",
|
"backendUnreachableError": "Cannot connect to the server. Please try again later.",
|
||||||
@@ -439,6 +447,7 @@
|
|||||||
"pageSpeedApiKeyFieldLabel": "PageSpeed API key",
|
"pageSpeedApiKeyFieldLabel": "PageSpeed API key",
|
||||||
"pageSpeedApiKeyFieldDescription": "Enter your Google PageSpeed API key to enable pagespeed monitoring. Click Reset to update the key.",
|
"pageSpeedApiKeyFieldDescription": "Enter your Google PageSpeed API key to enable pagespeed monitoring. Click Reset to update the key.",
|
||||||
"pageSpeedApiKeyFieldResetLabel": "API key is set. Click Reset to change it.",
|
"pageSpeedApiKeyFieldResetLabel": "API key is set. Click Reset to change it.",
|
||||||
|
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
"createNew": "Create new",
|
"createNew": "Create new",
|
||||||
"greeting": {
|
"greeting": {
|
||||||
@@ -502,5 +511,4 @@
|
|||||||
"profile": "Profile",
|
"profile": "Profile",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"team": "Team"
|
"team": "Team"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -649,9 +649,8 @@ class MonitorController {
|
|||||||
sendTestEmail = async (req, res, next) => {
|
sendTestEmail = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const { to } = req.body;
|
const { to } = req.body;
|
||||||
|
|
||||||
if (!to || typeof to !== "string") {
|
if (!to || typeof to !== "string") {
|
||||||
return res.error({ msg: this.stringService.errorForValidEmailAddress });
|
throw new Error(this.stringService.errorForValidEmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
const subject = this.stringService.testEmailSubject;
|
const subject = this.stringService.testEmailSubject;
|
||||||
|
|||||||
@@ -13,12 +13,25 @@ class SettingsController {
|
|||||||
getAppSettings = async (req, res, next) => {
|
getAppSettings = async (req, res, next) => {
|
||||||
const dbSettings = await this.settingsService.getDBSettings();
|
const dbSettings = await this.settingsService.getDBSettings();
|
||||||
const sanitizedSettings = { ...dbSettings };
|
const sanitizedSettings = { ...dbSettings };
|
||||||
|
|
||||||
|
const returnSettings = {
|
||||||
|
pagespeedKeySet: false,
|
||||||
|
emailPasswordSet: false,
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
|
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
|
||||||
sanitizedSettings.pagespeedApiKey = "********";
|
returnSettings.pagespeedKeySet = true;
|
||||||
|
delete sanitizedSettings.pagespeedApiKey;
|
||||||
}
|
}
|
||||||
|
if (typeof sanitizedSettings.systemEmailPassword !== "undefined") {
|
||||||
|
returnSettings.emailPasswordSet = true;
|
||||||
|
delete sanitizedSettings.systemEmailPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
returnSettings.settings = sanitizedSettings;
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.getAppSettings,
|
msg: this.stringService.getAppSettings,
|
||||||
data: sanitizedSettings,
|
data: returnSettings,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,16 @@ import mongoose from "mongoose";
|
|||||||
|
|
||||||
const AppSettingsSchema = mongoose.Schema(
|
const AppSettingsSchema = mongoose.Schema(
|
||||||
{
|
{
|
||||||
|
checkTTL: {
|
||||||
|
type: Number,
|
||||||
|
default: 30,
|
||||||
|
},
|
||||||
language: {
|
language: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "gb",
|
default: "gb",
|
||||||
},
|
},
|
||||||
pagespeedApiKey: {
|
pagespeedApiKey: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
|
||||||
},
|
},
|
||||||
systemEmailHost: {
|
systemEmailHost: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -22,6 +25,9 @@ const AppSettingsSchema = mongoose.Schema(
|
|||||||
systemEmailPassword: {
|
systemEmailPassword: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
systemEmailUser: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
singleton: {
|
singleton: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true,
|
required: true,
|
||||||
|
|||||||
@@ -14,12 +14,22 @@ const getAppSettings = async () => {
|
|||||||
|
|
||||||
const updateAppSettings = async (newSettings) => {
|
const updateAppSettings = async (newSettings) => {
|
||||||
try {
|
try {
|
||||||
console.log(newSettings);
|
const update = { $set: { ...newSettings } };
|
||||||
const settings = await AppSettings.findOneAndUpdate(
|
|
||||||
{},
|
if (newSettings.pagespeedApiKey === "") {
|
||||||
{ $set: newSettings },
|
update.$unset = { pagespeedApiKey: "" };
|
||||||
{ new: true, upsert: true }
|
delete update.$set.pagespeedApiKey;
|
||||||
);
|
}
|
||||||
|
|
||||||
|
if (newSettings.systemEmailPassword === "") {
|
||||||
|
update.$unset = { systemEmailPassword: "" };
|
||||||
|
delete update.$set.systemEmailPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await AppSettings.findOneAndUpdate({}, update, {
|
||||||
|
new: true,
|
||||||
|
upsert: true,
|
||||||
|
});
|
||||||
return settings;
|
return settings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
|
|||||||
@@ -29,7 +29,10 @@ class EmailService {
|
|||||||
this.mjml2html = mjml2html;
|
this.mjml2html = mjml2html;
|
||||||
this.nodemailer = nodemailer;
|
this.nodemailer = nodemailer;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
init = async () => {
|
||||||
/**
|
/**
|
||||||
* Loads an email template from the filesystem.
|
* Loads an email template from the filesystem.
|
||||||
*
|
*
|
||||||
@@ -67,34 +70,14 @@ class EmailService {
|
|||||||
serverIsUpTemplate: this.loadTemplate("serverIsUp"),
|
serverIsUpTemplate: this.loadTemplate("serverIsUp"),
|
||||||
passwordResetTemplate: this.loadTemplate("passwordReset"),
|
passwordResetTemplate: this.loadTemplate("passwordReset"),
|
||||||
hardwareIncidentTemplate: this.loadTemplate("hardwareIncident"),
|
hardwareIncidentTemplate: this.loadTemplate("hardwareIncident"),
|
||||||
testEmailTemplate: this.loadTemplate("testEmailTemplate")
|
testEmailTemplate: this.loadTemplate("testEmailTemplate"),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The email transporter used to send emails.
|
* The email transporter used to send emails.
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
|
};
|
||||||
const {
|
|
||||||
systemEmailHost,
|
|
||||||
systemEmailPort,
|
|
||||||
systemEmailUser,
|
|
||||||
systemEmailAddress,
|
|
||||||
systemEmailPassword,
|
|
||||||
} = this.settingsService.getSettings();
|
|
||||||
|
|
||||||
const emailConfig = {
|
|
||||||
host: systemEmailHost,
|
|
||||||
port: systemEmailPort,
|
|
||||||
secure: true,
|
|
||||||
auth: {
|
|
||||||
user: systemEmailUser || systemEmailAddress,
|
|
||||||
pass: systemEmailPassword,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.transporter = this.nodemailer.createTransport(emailConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously builds and sends an email using a specified template and context.
|
* Asynchronously builds and sends an email using a specified template and context.
|
||||||
@@ -106,6 +89,28 @@ class EmailService {
|
|||||||
* @returns {Promise<string>} A promise that resolves to the messageId of the sent email.
|
* @returns {Promise<string>} A promise that resolves to the messageId of the sent email.
|
||||||
*/
|
*/
|
||||||
buildAndSendEmail = async (template, context, to, subject) => {
|
buildAndSendEmail = async (template, context, to, subject) => {
|
||||||
|
// TODO - Consider an update transporter method so this only needs to be recreated when smtp settings change
|
||||||
|
const {
|
||||||
|
systemEmailHost,
|
||||||
|
systemEmailPort,
|
||||||
|
systemEmailUser,
|
||||||
|
systemEmailAddress,
|
||||||
|
systemEmailPassword,
|
||||||
|
} = await this.settingsService.getDBSettings();
|
||||||
|
|
||||||
|
const emailConfig = {
|
||||||
|
host: systemEmailHost,
|
||||||
|
port: systemEmailPort,
|
||||||
|
secure: true,
|
||||||
|
auth: {
|
||||||
|
user: systemEmailUser || systemEmailAddress,
|
||||||
|
pass: systemEmailPassword,
|
||||||
|
},
|
||||||
|
connectionTimeout: 5000,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.transporter = this.nodemailer.createTransport(emailConfig);
|
||||||
|
|
||||||
const buildHtml = async (template, context) => {
|
const buildHtml = async (template, context) => {
|
||||||
try {
|
try {
|
||||||
const mjml = this.templateLookup[template](context);
|
const mjml = this.templateLookup[template](context);
|
||||||
|
|||||||
@@ -59,7 +59,17 @@ class SettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getDBSettings() {
|
async getDBSettings() {
|
||||||
const settings = await this.appSettings.findOne({ singleton: true }).lean();
|
let settings = await this.appSettings
|
||||||
|
.findOne({ singleton: true })
|
||||||
|
.select("-__v -_id -createdAt -updatedAt -singleton")
|
||||||
|
.lean();
|
||||||
|
if (settings === null) {
|
||||||
|
await this.appSettings.create({});
|
||||||
|
settings = await this.appSettings
|
||||||
|
.findOne({ singleton: true })
|
||||||
|
.select("-__v -_id -createdAt -updatedAt -singleton")
|
||||||
|
.lean();
|
||||||
|
}
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -424,21 +424,14 @@ const editMaintenanceByIdWindowBodyValidation = joi.object({
|
|||||||
// SettingsValidation
|
// SettingsValidation
|
||||||
//****************************************
|
//****************************************
|
||||||
const updateAppSettingsBodyValidation = joi.object({
|
const updateAppSettingsBodyValidation = joi.object({
|
||||||
apiBaseUrl: joi.string().allow(""),
|
checkTTL: joi.number().allow(""),
|
||||||
logLevel: joi.string().valid("debug", "none", "error", "warn").allow(""),
|
|
||||||
clientHost: joi.string().allow(""),
|
|
||||||
dbType: joi.string().allow(""),
|
|
||||||
dbConnectionString: joi.string().allow(""),
|
|
||||||
redisHost: joi.string().allow(""),
|
|
||||||
redisPort: joi.number().allow(null, ""),
|
|
||||||
redisUrl: joi.string().allow(""),
|
|
||||||
jwtTTL: joi.string().allow(""),
|
|
||||||
pagespeedApiKey: joi.string().allow(""),
|
pagespeedApiKey: joi.string().allow(""),
|
||||||
language: joi.string().allow(""),
|
language: joi.string().allow(""),
|
||||||
systemEmailHost: joi.string().allow(""),
|
systemEmailHost: joi.string().allow(""),
|
||||||
systemEmailPort: joi.number().allow(""),
|
systemEmailPort: joi.number().allow(""),
|
||||||
systemEmailAddress: joi.string().allow(""),
|
systemEmailAddress: joi.string().allow(""),
|
||||||
systemEmailPassword: joi.string().allow(""),
|
systemEmailPassword: joi.string().allow(""),
|
||||||
|
systemEmailUser: joi.string().allow(""),
|
||||||
});
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
|
|||||||
Reference in new issue
Block a user