Merge pull request #2128 from bluewave-labs/fix/save-settings
fix: save settings
This commit is contained in:
6 files changed
+16
-44
No files matched your search
@@ -30,26 +30,9 @@ export const getAppSettings = createAsyncThunk(
|
|||||||
export const updateAppSettings = createAsyncThunk(
|
export const updateAppSettings = createAsyncThunk(
|
||||||
"settings/updateSettings",
|
"settings/updateSettings",
|
||||||
async ({ settings }, thunkApi) => {
|
async ({ settings }, thunkApi) => {
|
||||||
// The reason for commenting is that, previously, we had the flexibility to set the API base.
|
|
||||||
// However, now this could lead to an issue where it gets set to undefined.
|
|
||||||
// networkService.setBaseUrl(settings.apiBaseUrl);
|
|
||||||
try {
|
try {
|
||||||
const parsedSettings = {
|
const parsedSettings = {
|
||||||
apiBaseUrl: settings.apiBaseUrl,
|
|
||||||
logLevel: settings.logLevel,
|
|
||||||
language: settings.language,
|
language: settings.language,
|
||||||
clientHost: settings.clientHost,
|
|
||||||
jwtSecret: settings.jwtSecret,
|
|
||||||
dbType: settings.dbType,
|
|
||||||
dbConnectionString: settings.dbConnectionString,
|
|
||||||
redisHost: settings.redisHost,
|
|
||||||
redisPort: settings.redisPort,
|
|
||||||
jwtTTL: settings.jwtTTL,
|
|
||||||
pagespeedApiKey: settings.pagespeedApiKey,
|
|
||||||
systemEmailHost: settings.systemEmailHost,
|
|
||||||
systemEmailPort: settings.systemEmailPort,
|
|
||||||
systemEmailAddress: settings.systemEmailAddress,
|
|
||||||
systemEmailPassword: settings.systemEmailPassword,
|
|
||||||
};
|
};
|
||||||
const res = await networkService.updateAppSettings({ settings: parsedSettings });
|
const res = await networkService.updateAppSettings({ settings: parsedSettings });
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
@@ -123,31 +123,17 @@ const Settings = () => {
|
|||||||
ttl: form.ttl,
|
ttl: form.ttl,
|
||||||
});
|
});
|
||||||
const updatedUser = { ...user, checkTTL: form.ttl };
|
const updatedUser = { ...user, checkTTL: form.ttl };
|
||||||
const action = await dispatch(update({ localData: updatedUser }));
|
const [userAction, settingsAction] = await Promise.all([
|
||||||
const settingsAction = await dispatch(
|
dispatch(update({ localData: updatedUser })),
|
||||||
updateAppSettings({ settings: { language: language } })
|
dispatch(updateAppSettings({ settings: { language: language } })),
|
||||||
);
|
]);
|
||||||
|
|
||||||
if (action.payload.success && settingsAction.payload.success) {
|
if (userAction.payload.success && settingsAction.payload.success) {
|
||||||
createToast({
|
createToast({ body: t("settingsSuccessSaved") });
|
||||||
body: t("settingsSuccessSaved"),
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
if (action.payload) {
|
throw new Error("Failed to save settings");
|
||||||
console.log(action.payload);
|
|
||||||
// dispatch errors
|
|
||||||
createToast({
|
|
||||||
body: action.payload.msg,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// unknown errors
|
|
||||||
createToast({
|
|
||||||
body: "Unknown error.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
createToast({ body: t("settingsFailedToSave") });
|
createToast({ body: t("settingsFailedToSave") });
|
||||||
} finally {
|
} finally {
|
||||||
setChecksIsLoading(false);
|
setChecksIsLoading(false);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ const isAllowed = (allowedRoles) => {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const error = new Error(stringService.insufficientPermissions);
|
const error = new Error(stringService.insufficientPermissions);
|
||||||
error.status = 401;
|
error.status = 403;
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class SettingsRoutes {
|
|||||||
this.router.get("/", this.settingsController.getAppSettings);
|
this.router.get("/", this.settingsController.getAppSettings);
|
||||||
this.router.put(
|
this.router.put(
|
||||||
"/",
|
"/",
|
||||||
isAllowed(["superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
this.settingsController.updateAppSettings
|
this.settingsController.updateAppSettings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import dotenv from "dotenv";
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
logLevel: process.env.LOG_LEVEL,
|
logLevel: process.env.LOG_LEVEL,
|
||||||
apiBaseUrl: undefined,
|
|
||||||
language: process.env.LANGUAGE,
|
language: process.env.LANGUAGE,
|
||||||
clientHost: process.env.CLIENT_HOST,
|
clientHost: process.env.CLIENT_HOST,
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
|
|||||||
@@ -204,11 +204,11 @@ class StringService {
|
|||||||
|
|
||||||
get monitorUpAlert() {
|
get monitorUpAlert() {
|
||||||
return this.translationService.getTranslation("monitorUpAlert");
|
return this.translationService.getTranslation("monitorUpAlert");
|
||||||
}
|
}
|
||||||
|
|
||||||
get monitorDownAlert() {
|
get monitorDownAlert() {
|
||||||
return this.translationService.getTranslation("monitorDownAlert");
|
return this.translationService.getTranslation("monitorDownAlert");
|
||||||
}
|
}
|
||||||
|
|
||||||
getWebhookUnsupportedPlatform(platform) {
|
getWebhookUnsupportedPlatform(platform) {
|
||||||
return this.translationService
|
return this.translationService
|
||||||
@@ -415,6 +415,10 @@ class StringService {
|
|||||||
return this.translationService.getTranslation("updateAppSettings");
|
return this.translationService.getTranslation("updateAppSettings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get insufficientPermissions() {
|
||||||
|
return this.translationService.getTranslation("insufficientPermissions");
|
||||||
|
}
|
||||||
|
|
||||||
getDbFindMonitorById(monitorId) {
|
getDbFindMonitorById(monitorId) {
|
||||||
return this.translationService
|
return this.translationService
|
||||||
.getTranslation("dbFindMonitorById")
|
.getTranslation("dbFindMonitorById")
|
||||||
|
|||||||
Reference in new issue
Block a user