Skip to content

Commit

Permalink
avniproject/avni-product#1561 - fix bug in updating server url via de…
Browse files Browse the repository at this point in the history
…v settings. model version.
  • Loading branch information
petmongrels committed Mar 21, 2024
1 parent 83b7bc4 commit 6bcfd70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"lodash": "4.17.21",
"moment": "2.29.4",
"native-base": "3.4.9",
"openchs-models": "1.31.41",
"openchs-models": "1.31.52",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-native": "0.72.3",
Expand Down
9 changes: 6 additions & 3 deletions packages/openchs-android/src/action/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {LocaleMapping, Settings, UserInfo} from 'avni-models';
import General from "../utility/General";
import MessageService from "../service/MessageService";
import UserInfoService from '../service/UserInfoService';
import {JSONStringify} from "../utility/JsonStringify";

class SettingsActions {
static getInitialState(context) {
Expand Down Expand Up @@ -34,13 +35,15 @@ class SettingsActions {
};
}

static _updateSettingAndSave(state, updateFunc, context) {
static _updateSettingAndSave(state, updateFunc, context, ignoreValidationError = false) {
const newState = SettingsActions.clone(state);
updateFunc(newState.settings);
newState.validationResults = newState.settings.validate();

if (newState.validationResults.hasNoValidationError()) {
if (newState.validationResults.hasNoValidationError() || ignoreValidationError) {
context.get(SettingsService).saveOrUpdate(newState.settings, Settings.schema.name);
} else {
General.logError("SettingsActions", `ValidationError: ${JSONStringify(newState.validationResults)}`);
}

return newState;
Expand All @@ -58,7 +61,7 @@ class SettingsActions {
static onServerURLChange(state, action, context) {
return SettingsActions._updateSettingAndSave(state, (settings) => {
settings.serverURL = action.value
}, context);
}, context, true);
}

static toNumber(str) {
Expand Down

0 comments on commit 6bcfd70

Please sign in to comment.