From 2a9d9c3281b09abe4525518002d58e2df1aa51e2 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 18 Jul 2024 12:11:27 -0700 Subject: [PATCH 1/2] Add condition to prepending --- .../Pages/Monitors/CreateMonitor/index.jsx | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/Client/src/Pages/Monitors/CreateMonitor/index.jsx b/Client/src/Pages/Monitors/CreateMonitor/index.jsx index 1b19c2bde..26304e726 100644 --- a/Client/src/Pages/Monitors/CreateMonitor/index.jsx +++ b/Client/src/Pages/Monitors/CreateMonitor/index.jsx @@ -85,37 +85,42 @@ const CreateMonitor = () => { //obj to submit let monitor = { ...generalSettings, - url: "https://" + generalSettings.url, + url: + checks.type === "http" + ? "https://" + generalSettings.url + : generalSettings.url, ...checks, }; - const { error } = createMonitorValidation.validate(monitor, { - abortEarly: false, - }); + console.log(monitor); - if (error) { - const newErrors = {}; - error.details.forEach((err) => { - newErrors[err.path[0]] = err.message; - }); - setErrors(newErrors); - } else { - monitor = { - ...monitor, - description: monitor.name, - userId: user._id, - // ...advancedSettings, // TODO frequency should be interval, then we can use spread - interval: advancedSettings.frequency * MS_PER_MINUTE, - }; - try { - const action = await dispatch(createMonitor({ authToken, monitor })); - if (action.meta.requestStatus === "fulfilled") { - navigate("/monitors"); - } - } catch (error) { - alert(error); - } - } + // const { error } = createMonitorValidation.validate(monitor, { + // abortEarly: false, + // }); + + // if (error) { + // const newErrors = {}; + // error.details.forEach((err) => { + // newErrors[err.path[0]] = err.message; + // }); + // setErrors(newErrors); + // } else { + // monitor = { + // ...monitor, + // description: monitor.name, + // userId: user._id, + // // ...advancedSettings, // TODO frequency should be interval, then we can use spread + // interval: advancedSettings.frequency * MS_PER_MINUTE, + // }; + // try { + // const action = await dispatch(createMonitor({ authToken, monitor })); + // if (action.meta.requestStatus === "fulfilled") { + // navigate("/monitors"); + // } + // } catch (error) { + // alert(error); + // } + // } }; //select values From 958a3428752689ff68aa94fd1f20498c18d695ba Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 18 Jul 2024 12:11:53 -0700 Subject: [PATCH 2/2] Removed comment, uncommented code --- .../Pages/Monitors/CreateMonitor/index.jsx | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/Client/src/Pages/Monitors/CreateMonitor/index.jsx b/Client/src/Pages/Monitors/CreateMonitor/index.jsx index 26304e726..e460ccaa2 100644 --- a/Client/src/Pages/Monitors/CreateMonitor/index.jsx +++ b/Client/src/Pages/Monitors/CreateMonitor/index.jsx @@ -92,35 +92,33 @@ const CreateMonitor = () => { ...checks, }; - console.log(monitor); + const { error } = createMonitorValidation.validate(monitor, { + abortEarly: false, + }); - // const { error } = createMonitorValidation.validate(monitor, { - // abortEarly: false, - // }); - - // if (error) { - // const newErrors = {}; - // error.details.forEach((err) => { - // newErrors[err.path[0]] = err.message; - // }); - // setErrors(newErrors); - // } else { - // monitor = { - // ...monitor, - // description: monitor.name, - // userId: user._id, - // // ...advancedSettings, // TODO frequency should be interval, then we can use spread - // interval: advancedSettings.frequency * MS_PER_MINUTE, - // }; - // try { - // const action = await dispatch(createMonitor({ authToken, monitor })); - // if (action.meta.requestStatus === "fulfilled") { - // navigate("/monitors"); - // } - // } catch (error) { - // alert(error); - // } - // } + if (error) { + const newErrors = {}; + error.details.forEach((err) => { + newErrors[err.path[0]] = err.message; + }); + setErrors(newErrors); + } else { + monitor = { + ...monitor, + description: monitor.name, + userId: user._id, + // ...advancedSettings, // TODO frequency should be interval, then we can use spread + interval: advancedSettings.frequency * MS_PER_MINUTE, + }; + try { + const action = await dispatch(createMonitor({ authToken, monitor })); + if (action.meta.requestStatus === "fulfilled") { + navigate("/monitors"); + } + } catch (error) { + alert(error); + } + } }; //select values