Merge pull request #2128 from bluewave-labs/fix/save-settings
fix: save settings
This commit is contained in:
6 files changed
+20
-48
No files matched your search
@@ -30,26 +30,9 @@ export const getAppSettings = createAsyncThunk(
|
||||
export const updateAppSettings = createAsyncThunk(
|
||||
"settings/updateSettings",
|
||||
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 {
|
||||
const parsedSettings = {
|
||||
apiBaseUrl: settings.apiBaseUrl,
|
||||
logLevel: settings.logLevel,
|
||||
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 });
|
||||
return res.data;
|
||||
|
||||
@@ -123,31 +123,17 @@ const Settings = () => {
|
||||
ttl: form.ttl,
|
||||
});
|
||||
const updatedUser = { ...user, checkTTL: form.ttl };
|
||||
const action = await dispatch(update({ localData: updatedUser }));
|
||||
const settingsAction = await dispatch(
|
||||
updateAppSettings({ settings: { language: language } })
|
||||
);
|
||||
const [userAction, settingsAction] = await Promise.all([
|
||||
dispatch(update({ localData: updatedUser })),
|
||||
dispatch(updateAppSettings({ settings: { language: language } })),
|
||||
]);
|
||||
|
||||
if (action.payload.success && settingsAction.payload.success) {
|
||||
createToast({
|
||||
body: t("settingsSuccessSaved"),
|
||||
});
|
||||
if (userAction.payload.success && settingsAction.payload.success) {
|
||||
createToast({ body: t("settingsSuccessSaved") });
|
||||
} else {
|
||||
if (action.payload) {
|
||||
console.log(action.payload);
|
||||
// dispatch errors
|
||||
createToast({
|
||||
body: action.payload.msg,
|
||||
});
|
||||
} else {
|
||||
// unknown errors
|
||||
createToast({
|
||||
body: "Unknown error.",
|
||||
});
|
||||
}
|
||||
throw new Error("Failed to save settings");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createToast({ body: t("settingsFailedToSave") });
|
||||
} finally {
|
||||
setChecksIsLoading(false);
|
||||
|
||||
@@ -41,7 +41,7 @@ const isAllowed = (allowedRoles) => {
|
||||
return;
|
||||
} else {
|
||||
const error = new Error(stringService.insufficientPermissions);
|
||||
error.status = 401;
|
||||
error.status = 403;
|
||||
error.service = SERVICE_NAME;
|
||||
next(error);
|
||||
return;
|
||||
|
||||
@@ -12,7 +12,7 @@ class SettingsRoutes {
|
||||
this.router.get("/", this.settingsController.getAppSettings);
|
||||
this.router.put(
|
||||
"/",
|
||||
isAllowed(["superadmin"]),
|
||||
isAllowed(["admin", "superadmin"]),
|
||||
this.settingsController.updateAppSettings
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
const envConfig = {
|
||||
logLevel: process.env.LOG_LEVEL,
|
||||
apiBaseUrl: undefined,
|
||||
language: process.env.LANGUAGE,
|
||||
clientHost: process.env.CLIENT_HOST,
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
|
||||
@@ -189,26 +189,26 @@ class StringService {
|
||||
get telegramRequiresBotTokenAndChatId() {
|
||||
return this.translationService.getTranslation("telegramRequiresBotTokenAndChatId");
|
||||
}
|
||||
|
||||
|
||||
get webhookUrlRequired() {
|
||||
return this.translationService.getTranslation("webhookUrlRequired");
|
||||
}
|
||||
|
||||
|
||||
get platformRequired() {
|
||||
return this.translationService.getTranslation("platformRequired");
|
||||
}
|
||||
|
||||
|
||||
get testNotificationFailed() {
|
||||
return this.translationService.getTranslation("testNotificationFailed");
|
||||
}
|
||||
|
||||
get monitorUpAlert() {
|
||||
return this.translationService.getTranslation("monitorUpAlert");
|
||||
}
|
||||
|
||||
get monitorDownAlert() {
|
||||
}
|
||||
|
||||
get monitorDownAlert() {
|
||||
return this.translationService.getTranslation("monitorDownAlert");
|
||||
}
|
||||
}
|
||||
|
||||
getWebhookUnsupportedPlatform(platform) {
|
||||
return this.translationService
|
||||
@@ -415,6 +415,10 @@ class StringService {
|
||||
return this.translationService.getTranslation("updateAppSettings");
|
||||
}
|
||||
|
||||
get insufficientPermissions() {
|
||||
return this.translationService.getTranslation("insufficientPermissions");
|
||||
}
|
||||
|
||||
getDbFindMonitorById(monitorId) {
|
||||
return this.translationService
|
||||
.getTranslation("dbFindMonitorById")
|
||||
|
||||
Reference in new issue
Block a user