implement useffect to populate form when editing
This commit is contained in:
1 parent
55bd7d7973
commit
6b15a5814d
1 file changed
+22
@@ -82,6 +82,28 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
secret: "",
|
secret: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Populate form fields if editing
|
||||||
|
useEffect(() => {
|
||||||
|
if (isCreate || !monitor) return;
|
||||||
|
|
||||||
|
setInfrastructureMonitor({
|
||||||
|
url: monitor.url.replace(/^https?:\/\//, ""),
|
||||||
|
name: monitor.name || "",
|
||||||
|
notifications: monitor.notifications || [],
|
||||||
|
interval: monitor.interval / MS_PER_MINUTE,
|
||||||
|
cpu: monitor.cpu || false,
|
||||||
|
usage_cpu: monitor.usage_cpu || "",
|
||||||
|
memory: monitor.memory || false,
|
||||||
|
usage_memory: monitor.usage_memory || "",
|
||||||
|
disk: monitor.disk || false,
|
||||||
|
usage_disk: monitor.usage_disk || "",
|
||||||
|
temperature: monitor.temperature || false,
|
||||||
|
usage_temperature: monitor.usage_temperature || "",
|
||||||
|
secret: monitor.secret || "",
|
||||||
|
});
|
||||||
|
setHttps(monitor.url.startsWith("https"));
|
||||||
|
}, [isCreate, monitor]);
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const handleCreateInfrastructureMonitor = async (event) => {
|
const handleCreateInfrastructureMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
Reference in new issue
Block a user