diff --git a/frontend/src/api/actions/updateAppsettingsConfig.ts b/frontend/src/api/actions/updateAppsettingsConfig.ts index f1254705..60c82dde 100644 --- a/frontend/src/api/actions/updateAppsettingsConfig.ts +++ b/frontend/src/api/actions/updateAppsettingsConfig.ts @@ -4,6 +4,33 @@ import getFetchCredentials from '../../configuration/getFetchCredentials'; import getCookie from '../../functions/getCookie'; import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig'; +type ObjectType = Record< + string, + string | number | boolean | Record +>; + +function flattenObject(ob: ObjectType) { + // source: https://stackoverflow.com/a/53739792 + const toReturn: ObjectType = {}; + + for (const i in ob) { + if (!Object.prototype.hasOwnProperty.call(ob, i)) continue; + + if (typeof ob[i] == 'object' && ob[i] !== null) { + const flatObject = flattenObject(ob[i]); + for (const x in flatObject) { + if (!Object.prototype.hasOwnProperty.call(flatObject, x)) continue; + + toReturn[i + '.' + x] = flatObject[x]; + } + } else { + toReturn[i] = ob[i]; + } + } + + return toReturn; +} + const updateAppsettingsConfig = async (config: AppSettingsConfigType) => { const apiUrl = getApiUrl(); const csrfCookie = getCookie('csrftoken'); @@ -15,7 +42,7 @@ const updateAppsettingsConfig = async (config: AppSettingsConfigType) => { 'X-CSRFToken': csrfCookie || '', }, credentials: getFetchCredentials(), - body: JSON.stringify(config), + body: JSON.stringify(flattenObject(config)), }); const appSettingsConfig = await response.json();