From dca0a08c2ef01f8f32de966c480b19e63072de32 Mon Sep 17 00:00:00 2001 From: erhanilze Date: Thu, 3 Oct 2024 10:52:17 +0300 Subject: [PATCH] fix : ui-culture used in config-state-service --- .../src/lib/services/config-state.service.ts | 36 ++++++++++++------- .../lib/strategies/auth-code-flow-strategy.ts | 10 +++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts index 97fcdbc40b..de98878b0f 100644 --- a/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/config-state.service.ts @@ -17,6 +17,8 @@ export class ConfigStateService { private updateSubject = new Subject(); private readonly store = new InternalStore({} as ApplicationConfigurationDto); + public uiCultureFromAuthCodeFlow: string; + setState(config: ApplicationConfigurationDto) { this.store.set(config); } @@ -53,7 +55,11 @@ export class ConfigStateService { if (!appState.localization.currentCulture.cultureName) { throw new Error('culture name should defined'); } - return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe( + + const cultureName = + this.uiCultureFromAuthCodeFlow ?? appState.localization.currentCulture.cultureName; + + return this.getlocalizationResource(cultureName).pipe( map(result => ({ ...appState, localization: { ...appState.localization, ...result } })), ); } @@ -71,10 +77,10 @@ export class ConfigStateService { } refreshLocalization(lang: string): Observable { - if(this.includeLocalizationResources){ + if (this.includeLocalizationResources) { return this.refreshAppState().pipe(map(() => null)); } - + return this.getlocalizationResource(lang) .pipe( tap(result => @@ -145,7 +151,7 @@ export class ConfigStateService { return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {}); } - getFeatures$(keys: string[]): Observable<{ [key: string]: string; } | undefined> { + getFeatures$(keys: string[]): Observable<{ [key: string]: string } | undefined> { return this.store.sliceState(({ features }) => { if (!features?.values) return; @@ -168,10 +174,13 @@ export class ConfigStateService { const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); - return keysFound.reduce((acc, key) => { - acc[key] = settings[key]; - return acc; - }, {} as Record); + return keysFound.reduce( + (acc, key) => { + acc[key] = settings[key]; + return acc; + }, + {} as Record, + ); } getSettings$(keyword?: string) { @@ -183,10 +192,13 @@ export class ConfigStateService { const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1); - return keysFound.reduce((acc, key) => { - acc[key] = settings[key]; - return acc; - }, {} as Record); + return keysFound.reduce( + (acc, key) => { + acc[key] = settings[key]; + return acc; + }, + {} as Record, + ); }), ); } diff --git a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts index 4626c91aec..3d33d4325a 100644 --- a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts +++ b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts @@ -9,10 +9,10 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { async init() { this.checkRememberMeOption(); + this.setUICulture(); return super .init() - .then(() => this.setLanguageWithUICulture()) .then(() => this.oAuthService.tryLogin().catch(noop)) .then(() => this.oAuthService.setupAutomaticSilentRefresh()); } @@ -70,14 +70,14 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { return { ...(lang && culture), ...queryParams }; } - private setLanguageWithUICulture() { + private setUICulture() { this.oAuthService.events .pipe( filter(event => event.type === 'token_received'), tap(e => { - const urlParams = window.location.search; - const uiCulture = new URLSearchParams(urlParams).get('ui-culture'); - this.sessionState.setLanguage(uiCulture); + const urlParams = new URLSearchParams(window.location.search); + this.configState.uiCultureFromAuthCodeFlow = urlParams.get('ui-culture'); + window.history.replaceState(null, '', window.location.pathname); }), ) .subscribe();