Used Parent State And Set Minor Changes
This commit is contained in:
1 parent
af010e138d
commit
da7d9c02c8
2 files changed
+11
-34
No files matched your search
@@ -302,7 +302,7 @@ const useCreateMonitor = () => {
|
|||||||
|
|
||||||
const useFetchGlobalSettings = () => {
|
const useFetchGlobalSettings = () => {
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [globalSettings, setGlobalSettings] = useState(null);
|
const [globalSettings, setGlobalSettings] = useState(undefined);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchGlobalSettings = async () => {
|
const fetchGlobalSettings = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import TextInput from "../../Components/Inputs/TextInput";
|
|||||||
|
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { PropTypes } from "prop-types";
|
import { PropTypes } from "prop-types";
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const SettingsGlobalThresholds = ({
|
const SettingsGlobalThresholds = ({
|
||||||
@@ -18,26 +17,7 @@ const SettingsGlobalThresholds = ({
|
|||||||
const { t } = useTranslation(); // For language translation
|
const { t } = useTranslation(); // For language translation
|
||||||
const theme = useTheme(); // MUI theme access
|
const theme = useTheme(); // MUI theme access
|
||||||
|
|
||||||
// Local state for thresholds
|
// Handles input change and updates parent state
|
||||||
const [thresholds, setThresholds] = useState({
|
|
||||||
cpu: "",
|
|
||||||
memory: "",
|
|
||||||
disk: "",
|
|
||||||
temperature: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load existing thresholds from settingsData
|
|
||||||
|
|
||||||
if (settingsData?.settings?.globalThresholds) {
|
|
||||||
setThresholds({
|
|
||||||
cpu: settingsData.settings.globalThresholds.cpu || "",
|
|
||||||
memory: settingsData.settings.globalThresholds.memory || "",
|
|
||||||
disk: settingsData.settings.globalThresholds.disk || "",
|
|
||||||
temperature: settingsData.settings.globalThresholds.temperature || "",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles input change and updates state & parent data
|
|
||||||
const handleChange = (e, min, max) => {
|
const handleChange = (e, min, max) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
|
|
||||||
@@ -47,19 +27,16 @@ const SettingsGlobalThresholds = ({
|
|||||||
(!isNaN(numValue) && isFinite(numValue) && numValue >= min && numValue <= max);
|
(!isNaN(numValue) && isFinite(numValue) && numValue >= min && numValue <= max);
|
||||||
|
|
||||||
if (isValidNumber) {
|
if (isValidNumber) {
|
||||||
const updatedThresholds = {
|
setSettingsData((prev) => ({
|
||||||
...thresholds,
|
...prev,
|
||||||
[name]: value,
|
|
||||||
};
|
|
||||||
|
|
||||||
setThresholds(updatedThresholds);
|
|
||||||
setSettingsData({
|
|
||||||
...settingsData,
|
|
||||||
settings: {
|
settings: {
|
||||||
...settingsData.settings,
|
...prev.settings,
|
||||||
globalThresholds: updatedThresholds,
|
globalThresholds: {
|
||||||
|
...prev.settings?.globalThresholds,
|
||||||
|
[name]: value,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -98,7 +75,7 @@ const SettingsGlobalThresholds = ({
|
|||||||
label={label}
|
label={label}
|
||||||
placeholder={`${min} - ${max}`}
|
placeholder={`${min} - ${max}`}
|
||||||
type="number"
|
type="number"
|
||||||
value={thresholds[name]}
|
value={settingsData?.settings?.globalThresholds?.[name] || ""}
|
||||||
onChange={(e) => handleChange(e, min, max)}
|
onChange={(e) => handleChange(e, min, max)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in new issue
Block a user