This commit is contained in:
@@ -39,12 +39,14 @@ export interface UserConfigurationUpdates {
|
||||
notifications?: Record<string, unknown>;
|
||||
timezone?: string | null;
|
||||
previousConfig?: Record<string, any>;
|
||||
alarmEmails?: boolean;
|
||||
}
|
||||
|
||||
export async function updateUserConfigurations(
|
||||
updates: UserConfigurationUpdates
|
||||
): Promise<Response | { status: number }> {
|
||||
const coreConfigs: Array<{ name: string; value: any }> = [];
|
||||
const calendarConfigs: Array<{ name: string; value: any }> = [];
|
||||
|
||||
if (updates.language !== undefined) {
|
||||
coreConfigs.push({ name: "language", value: updates.language });
|
||||
@@ -61,17 +63,37 @@ export async function updateUserConfigurations(
|
||||
},
|
||||
});
|
||||
}
|
||||
if (updates.alarmEmails !== undefined) {
|
||||
calendarConfigs.push({
|
||||
name: "alarmEmails",
|
||||
value: updates.alarmEmails,
|
||||
});
|
||||
}
|
||||
|
||||
if (coreConfigs.length === 0) {
|
||||
const modules: Array<{
|
||||
name: string;
|
||||
configurations: Array<{ name: string; value: any }>;
|
||||
}> = [];
|
||||
|
||||
if (coreConfigs.length > 0) {
|
||||
modules.push({
|
||||
name: "core",
|
||||
configurations: coreConfigs,
|
||||
});
|
||||
}
|
||||
|
||||
if (calendarConfigs.length > 0) {
|
||||
modules.push({
|
||||
name: "calendar",
|
||||
configurations: calendarConfigs,
|
||||
});
|
||||
}
|
||||
|
||||
if (modules.length === 0) {
|
||||
return Promise.resolve({ status: 204 });
|
||||
}
|
||||
|
||||
return await api.patch(`api/configurations?scope=user`, {
|
||||
json: [
|
||||
{
|
||||
name: "core",
|
||||
configurations: coreConfigs,
|
||||
},
|
||||
],
|
||||
json: modules,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ export const userSlice = createSlice({
|
||||
timeZone: null as string | null,
|
||||
},
|
||||
} as Record<string, any>,
|
||||
alarmEmailsEnabled: null as boolean | null,
|
||||
loading: true,
|
||||
error: null as unknown as string | null,
|
||||
},
|
||||
@@ -82,6 +83,9 @@ export const userSlice = createSlice({
|
||||
state.userData.timezone = action.payload;
|
||||
}
|
||||
},
|
||||
setAlarmEmails: (state, action) => {
|
||||
state.alarmEmailsEnabled = action.payload;
|
||||
},
|
||||
clearError: (state) => {
|
||||
state.error = null;
|
||||
},
|
||||
@@ -153,6 +157,19 @@ export const userSlice = createSlice({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract alarmEmails from configurations.modules
|
||||
const calendarModule = action.payload.configurations.modules.find(
|
||||
(module: any) => module.name === "calendar"
|
||||
);
|
||||
if (calendarModule?.configurations) {
|
||||
const alarmEmailsConfig = calendarModule.configurations.find(
|
||||
(config: any) => config.name === "alarmEmails"
|
||||
);
|
||||
if (alarmEmailsConfig) {
|
||||
state.alarmEmailsEnabled = alarmEmailsConfig.value === true;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.addCase(getOpenPaasUserDataAsync.pending, (state) => {
|
||||
@@ -181,6 +198,9 @@ export const userSlice = createSlice({
|
||||
state.userData.timezone = action.payload.timezone;
|
||||
}
|
||||
}
|
||||
if (action.payload.alarmEmails !== undefined) {
|
||||
state.alarmEmailsEnabled = action.payload.alarmEmails === true;
|
||||
}
|
||||
})
|
||||
.addCase(updateUserConfigurationsAsync.rejected, (state, action) => {
|
||||
if (action.payload?.status !== 401) {
|
||||
@@ -192,7 +212,13 @@ export const userSlice = createSlice({
|
||||
});
|
||||
|
||||
// Action creators are generated for each case reducer function
|
||||
export const { setUserData, setTokens, setLanguage, setTimezone, clearError } =
|
||||
userSlice.actions;
|
||||
export const {
|
||||
setUserData,
|
||||
setTokens,
|
||||
setLanguage,
|
||||
setTimezone,
|
||||
setAlarmEmails,
|
||||
clearError,
|
||||
} = userSlice.actions;
|
||||
|
||||
export default userSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user