Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/js/constants/api.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@
url: '/api/caregivers/patients/'
},
USER: {
method: 'get',
url: '/api/caregivers/profile/',
GET: {
method: 'get',
url: '/api/caregivers/profile/',
},
PATCH: {
method: 'patch',
url: '/api/caregivers/profile/',
},
},
CAREGIVERS: {
method: 'get',
Expand Down
42 changes: 36 additions & 6 deletions src/js/controllers/settings/changeSettingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,43 @@
UserPreferences.setFontSize(newVal);
}

//Function to change the language
function changeLanguage(val) {
/**
* @description Changes the app language and forwards this change to the backend.
* Note that the backend will not save the new value if the requested language isn't supported there.
* @param val The new app language (ISO 639-1 code in uppercase).
* @returns {Promise<void>} Resolves after receiving responses from the listener and backend.
*/
async function changeLanguage(val) {
UserPreferences.setLanguage(val, true);
RequestToServer.sendRequest('AccountChange', {
NewValue: val,
FieldToChange: Params.setLanguageParamProperCase,
});

// Send update to the listener
try {
await RequestToServer.sendRequestWithResponse('AccountChange', {
NewValue: val,
FieldToChange: Params.setLanguageParamProperCase,
});
}
catch (error) {
console.error(`Error updating language to '${val}' in the listener,`
+ ` either because this language is not supported there, or due to some other error.`, error);
}

// Send update to the API
try {
await RequestToServer.apiRequest({
...Params.API.ROUTES.USER.PATCH,
data: {
language: val.toLowerCase(),
},
});
}
catch (error) {
if (error.message?.includes('400')) {
console.warn(`Language update to '${val}' wasn't accepted by the backend,`
+ ` because this language is not supported there.`, error);
}
else console.error(error);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @returns {Promise<void>}
*/
async function initUser() {
const requestParams = Params.API.ROUTES.USER;
const requestParams = Params.API.ROUTES.USER.GET;
const result = await RequestToServer.apiRequest(requestParams);
userInfo = result?.data;
assignColor();
Expand Down