UI: Fix up wrong message when submitting config

This commit is contained in:
Ilija Lazoroski 2022-07-20 15:25:48 +02:00
parent d09958e079
commit 40cb73e7e8
1 changed files with 32 additions and 30 deletions

View File

@ -162,16 +162,10 @@ 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();
}
});
}
@ -277,22 +271,7 @@ class ConfigurePageComponent extends AuthComponent {
sendConfig() {
let config = JSON.parse(JSON.stringify(this.state.configuration))
config = reformatConfig(config, true);
this.authFetch(CONFIGURED_PROPAGATION_CREDENTIALS_URL,
{
method: 'PATCH',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(formatCredentialsForIsland(this.state.credentials))
})
.then(res => {
if (!res.ok) {
throw Error()
}
return res;
}).catch((error) => {
console.log(`bad configuration ${error}`);
this.setState({lastAction: 'invalid_configuration'});
});
console.log(config);
return (
this.authFetch(CONFIG_URL,
@ -301,6 +280,29 @@ class ConfigurePageComponent extends AuthComponent {
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'},
body: JSON.stringify(formatCredentialsForIsland(this.state.credentials))
})
.then(res => {
if (!res.ok) {
throw Error()