From 953c98106e0ad2911c79b0b8c32e628ddb1844a7 Mon Sep 17 00:00:00 2001 From: yuliaklochai Date: Thu, 24 Jul 2025 11:41:14 +0300 Subject: [PATCH] UI: fixed Trendz settings update in AuthState --- ui-ngx/src/app/core/auth/auth.actions.ts | 10 +++++++++- ui-ngx/src/app/core/auth/auth.reducer.ts | 3 +++ .../home/pages/admin/trendz-settings.component.ts | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ui-ngx/src/app/core/auth/auth.actions.ts b/ui-ngx/src/app/core/auth/auth.actions.ts index dedd67bcb9..f9d63f4182 100644 --- a/ui-ngx/src/app/core/auth/auth.actions.ts +++ b/ui-ngx/src/app/core/auth/auth.actions.ts @@ -18,6 +18,7 @@ import { Action } from '@ngrx/store'; import { AuthUser, User } from '@shared/models/user.model'; import { AuthPayload } from '@core/auth/auth.models'; import { UserSettings } from '@shared/models/user-settings.models'; +import { TrendzSettings } from "@shared/models/trendz-settings.models"; export enum AuthActionTypes { AUTHENTICATED = '[Auth] Authenticated', @@ -31,6 +32,7 @@ export enum AuthActionTypes { UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section', PUT_USER_SETTINGS = '[Preferences] Put user settings', DELETE_USER_SETTINGS = '[Preferences] Delete user settings', + UPDATE_TRENDZ_SETTINGS = '[Auth] Update Trendz Settings', } export class ActionAuthAuthenticated implements Action { @@ -97,7 +99,13 @@ export class ActionPreferencesDeleteUserSettings implements Action { constructor(readonly payload: Array>) {} } +export class ActionAuthUpdateTrendzSettings implements Action { + readonly type = AuthActionTypes.UPDATE_TRENDZ_SETTINGS; + + constructor(readonly payload: { trendzSettings: TrendzSettings }) {} +} + export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated | ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository | ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings | - ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled; + ActionAuthUpdateAuthUser | ActionUpdateMobileQrCodeEnabled | ActionAuthUpdateTrendzSettings; diff --git a/ui-ngx/src/app/core/auth/auth.reducer.ts b/ui-ngx/src/app/core/auth/auth.reducer.ts index fde778284d..6752679261 100644 --- a/ui-ngx/src/app/core/auth/auth.reducer.ts +++ b/ui-ngx/src/app/core/auth/auth.reducer.ts @@ -99,6 +99,9 @@ export const authReducer = ( action.payload.forEach(path => unset(userSettings, path)); return { ...state, ...{ userSettings }}; + case AuthActionTypes.UPDATE_TRENDZ_SETTINGS: + return { ...state, ...action.payload }; + default: return state; } diff --git a/ui-ngx/src/app/modules/home/pages/admin/trendz-settings.component.ts b/ui-ngx/src/app/modules/home/pages/admin/trendz-settings.component.ts index 16ae6bf1da..7aec9cd9eb 100644 --- a/ui-ngx/src/app/modules/home/pages/admin/trendz-settings.component.ts +++ b/ui-ngx/src/app/modules/home/pages/admin/trendz-settings.component.ts @@ -21,6 +21,9 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { TrendzSettingsService } from '@core/http/trendz-settings.service'; import { TrendzSettings } from '@shared/models/trendz-settings.models'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { Store } from "@ngrx/store"; +import { AppState } from "@core/core.state"; +import { ActionAuthUpdateTrendzSettings } from "@core/auth/auth.actions"; @Component({ selector: 'tb-trendz-settings', @@ -31,7 +34,8 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha trendzSettingsForm: FormGroup; - constructor(private fb: FormBuilder, + constructor(protected store: Store, + private fb: FormBuilder, private trendzSettingsService: TrendzSettingsService, private destroyRef: DestroyRef) { super(); @@ -93,6 +97,7 @@ export class TrendzSettingsComponent extends PageComponent implements OnInit, Ha this.trendzSettingsService.saveTrendzSettings(trendzSettings) .subscribe(() => { this.setTrendzSettings(trendzSettings); + this.store.dispatch(new ActionAuthUpdateTrendzSettings({ trendzSettings: trendzSettings})) }) } }