demo monitors, remove monitors
This commit is contained in:
1 parent
889bb07946
commit
6a04ce5eee
2 files changed
+74
-2
No files matched your search
@@ -7,7 +7,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import DummyChart from "@/Pages/Settings/DummyChart";
|
import DummyChart from "@/Pages/Settings/DummyChart";
|
||||||
import { useGet, usePatch } from "@/Hooks/UseApi";
|
import { useGet, usePatch, usePost } from "@/Hooks/UseApi";
|
||||||
import { useSettingsForm } from "@/Hooks/useSettingsForm";
|
import { useSettingsForm } from "@/Hooks/useSettingsForm";
|
||||||
import { useIsAdmin } from "@/Hooks/useIsAdmin.js";
|
import { useIsAdmin } from "@/Hooks/useIsAdmin.js";
|
||||||
import type { SettingsFormData } from "@/Validation/settings";
|
import type { SettingsFormData } from "@/Validation/settings";
|
||||||
@@ -44,6 +44,10 @@ export const SettingsPage = () => {
|
|||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
|
// Local state for demo monitors dialog
|
||||||
|
const [isDemoMonitorsDialogOpen, setIsDemoMonitorsDialogOpen] = useState(false);
|
||||||
|
const { post: postDemoMonitors, loading: isPostingDemoMonitors } = usePost();
|
||||||
|
const { deleteFn: deleteAllMonitors, loading: isDeletingAllMonitors } = useDelete();
|
||||||
|
|
||||||
// Fetch settings data from API
|
// Fetch settings data from API
|
||||||
const { data: fetchedSettings } = useGet<SettingsResponse>("/settings");
|
const { data: fetchedSettings } = useGet<SettingsResponse>("/settings");
|
||||||
@@ -451,6 +455,47 @@ export const SettingsPage = () => {
|
|||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
{/* Demo Monitors - Admin Only */}
|
||||||
|
{isAdmin && (
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.settings.form.demoMonitors.title")}
|
||||||
|
subtitle={t("pages.settings.form.demoMonitors.description")}
|
||||||
|
rightContent={
|
||||||
|
<Box>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
loading={isPostingDemoMonitors}
|
||||||
|
onClick={async () => {
|
||||||
|
await postDemoMonitors("/monitors/demo", {});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("common.buttons.addDemo")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Remove All Monitors - Admin Only */}
|
||||||
|
{isAdmin && (
|
||||||
|
<ConfigBox
|
||||||
|
title={t("pages.settings.form.removeMonitors.title")}
|
||||||
|
subtitle={t("pages.settings.form.removeMonitors.description")}
|
||||||
|
rightContent={
|
||||||
|
<Box>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
loading={isDeletingAllMonitors}
|
||||||
|
onClick={() => setIsDemoMonitorsDialogOpen(true)}
|
||||||
|
>
|
||||||
|
{t("common.buttons.removeMonitors")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Clear Stats Confirmation Dialog */}
|
{/* Clear Stats Confirmation Dialog */}
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isStatsDialogOpen}
|
open={isStatsDialogOpen}
|
||||||
@@ -461,6 +506,19 @@ export const SettingsPage = () => {
|
|||||||
loading={isDeletingStats}
|
loading={isDeletingStats}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Delete All Monitors Confirmation Dialog */}
|
||||||
|
<Dialog
|
||||||
|
open={isDemoMonitorsDialogOpen}
|
||||||
|
title={t("pages.settings.form.removeMonitors.dialog.title")}
|
||||||
|
content={t("pages.settings.form.removeMonitors.dialog.description")}
|
||||||
|
onCancel={() => setIsDemoMonitorsDialogOpen(false)}
|
||||||
|
onConfirm={async () => {
|
||||||
|
await deleteAllMonitors("/monitors/");
|
||||||
|
setIsDemoMonitorsDialogOpen(false);
|
||||||
|
}}
|
||||||
|
loading={isDeletingAllMonitors}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Sticky Save Button */}
|
{/* Sticky Save Button */}
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
|||||||
@@ -40,7 +40,9 @@
|
|||||||
"notFound": "Go to the main dashboard",
|
"notFound": "Go to the main dashboard",
|
||||||
"resetPassword": "Reset password",
|
"resetPassword": "Reset password",
|
||||||
"reset": "Reset",
|
"reset": "Reset",
|
||||||
"clear": "Clear"
|
"clear": "Clear",
|
||||||
|
"addDemo": "Add demo monitors",
|
||||||
|
"removeMonitors": "Remove monitors"
|
||||||
},
|
},
|
||||||
"charts": {
|
"charts": {
|
||||||
"labels": {
|
"labels": {
|
||||||
@@ -1016,6 +1018,18 @@
|
|||||||
"placeholder": "1 - 150"
|
"placeholder": "1 - 150"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"demoMonitors": {
|
||||||
|
"title": "Demo monitors",
|
||||||
|
"description": "Add sample monitors for demonstration purposes."
|
||||||
|
},
|
||||||
|
"removeMonitors": {
|
||||||
|
"title": "System reset",
|
||||||
|
"description": "Remove all monitors from your system.",
|
||||||
|
"dialog": {
|
||||||
|
"title": "Remove all monitors?",
|
||||||
|
"description": "This cannot be undone."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user