From 40cb73e7e858cf002df99d16be29db163b59b371 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 20 Jul 2022 15:25:48 +0200 Subject: [PATCH] UI: Fix up wrong message when submitting config --- .../ui/src/components/pages/ConfigurePage.js | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js index cbf124cdf..8b801d79d 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/ConfigurePage.js @@ -162,17 +162,11 @@ class ConfigurePageComponent extends AuthComponent { } configSubmit() { - this.sendConfig() - .then(() => { - this.setState({ - lastAction: configSaveAction - }); - this.setInitialConfig(this.state.configuration); - this.props.onStatusChange(); - }).catch(error => { - console.log('Bad configuration: ' + error.toString()); - this.setState({lastAction: 'invalid_configuration'}); - }); + this.sendCredentials().then(res => { + if(res.ok) { + this.sendConfig(); + } + }); } onChange = (formData) => { @@ -277,8 +271,33 @@ class ConfigurePageComponent extends AuthComponent { sendConfig() { let config = JSON.parse(JSON.stringify(this.state.configuration)) config = reformatConfig(config, true); + console.log(config); - this.authFetch(CONFIGURED_PROPAGATION_CREDENTIALS_URL, + return ( + this.authFetch(CONFIG_URL, + { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(config) + }) + .then(res => { + if (!res.ok) { + console.log(`bad configuration submited ${res.status}`); + this.setState({lastAction: 'invalid_configuration'}); + } else { + this.setState({ + lastAction: configSaveAction + }); + this.setInitialConfig(this.state.configuration); + this.props.onStatusChange(); + } + return res; + })); + } + + sendCredentials() { + return ( + this.authFetch(CONFIGURED_PROPAGATION_CREDENTIALS_URL, { method: 'PATCH', headers: {'Content-Type': 'application/json'}, @@ -292,24 +311,7 @@ class ConfigurePageComponent extends AuthComponent { }).catch((error) => { console.log(`bad configuration ${error}`); this.setState({lastAction: 'invalid_configuration'}); - }); - - return ( - this.authFetch(CONFIG_URL, - { - method: 'POST', - headers: {'Content-Type': 'application/json'}, - body: JSON.stringify(config) - }) - .then(res => { - if (!res.ok) { - throw Error() - } - return res; - }).catch((error) => { - console.log(`bad configuration ${error}`); - this.setState({lastAction: 'invalid_configuration'}); - })); + })); } renderConfigContent = (displayedSchema) => {