@@ -28,22 +28,24 @@ import '@shoelace-style/shoelace/dist/components/icon/icon.js';
2828import '@shoelace-style/shoelace/dist/components/select/select.js' ;
2929import '@shoelace-style/shoelace/dist/components/option/option.js' ;
3030import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
31+ import { LanguageService } from '~core/services/language.service' ;
32+ import { AUTH_URLS } from '~core/constants/urls.constants' ;
3133
3234@Component ( {
33- selector : 'app-my-account' ,
34- templateUrl : './my-account.component.html' ,
35- styleUrl : './my-account.component.scss' ,
36- changeDetection : ChangeDetectionStrategy . OnPush ,
37- imports : [
38- RouterModule ,
39- ReactiveFormsModule ,
40- SlInputIconFocusDirective ,
41- PokemonImageComponent ,
42- AppSlSelectControlDirective ,
43- ThemeButtonComponent ,
44- NgOptimizedImage ,
45- ] ,
46- schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
35+ selector : 'app-my-account' ,
36+ templateUrl : './my-account.component.html' ,
37+ styleUrl : './my-account.component.scss' ,
38+ changeDetection : ChangeDetectionStrategy . OnPush ,
39+ imports : [
40+ RouterModule ,
41+ ReactiveFormsModule ,
42+ SlInputIconFocusDirective ,
43+ PokemonImageComponent ,
44+ AppSlSelectControlDirective ,
45+ ThemeButtonComponent ,
46+ NgOptimizedImage ,
47+ ] ,
48+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
4749} )
4850export class MyAccountComponent implements OnInit {
4951 private readonly changeDetectorRef = inject ( ChangeDetectorRef ) ;
@@ -52,6 +54,7 @@ export class MyAccountComponent implements OnInit {
5254 private readonly pokemonService = inject ( PokemonService ) ;
5355 private readonly alertService = inject ( AlertService ) ;
5456 private readonly destroyRef = inject ( DestroyRef ) ;
57+ private readonly languageService = inject ( LanguageService ) ;
5558
5659 translations = translations ;
5760 user : User | undefined ;
@@ -110,25 +113,36 @@ export class MyAccountComponent implements OnInit {
110113 this . updateUserForm . markAllAsTouched ( ) ;
111114 if ( this . updateUserForm . valid ) {
112115 this . isButtonUpdateUserFormLoading = true ;
113- const formValue = this . updateUserForm . getRawValue ( ) ;
114- this . userService
115- . updateUser ( {
116- name : formValue . name ! ,
117- language : formValue . language ! ,
118- } )
119- . pipe ( takeUntilDestroyed ( this . destroyRef ) )
120- . subscribe ( {
121- next : ( ) => {
122- this . isButtonUpdateUserFormLoading = false ;
123- this . alertService . createSuccessAlert ( translations . myAccountSuccessAlert ) ;
124- this . changeDetectorRef . markForCheck ( ) ;
125- } ,
126- error : ( ) => {
127- this . isButtonUpdateUserFormLoading = false ;
128- this . alertService . createErrorAlert ( translations . genericErrorAlert ) ;
129- this . changeDetectorRef . markForCheck ( ) ;
130- } ,
131- } ) ;
116+ this . updateUser ( ) ;
132117 }
133118 }
119+
120+ updateUser ( ) {
121+ const formValue = this . updateUserForm . getRawValue ( ) ;
122+ this . userService
123+ . updateUser ( {
124+ name : formValue . name ! ,
125+ language : formValue . language ! ,
126+ } )
127+ . pipe ( takeUntilDestroyed ( this . destroyRef ) )
128+ . subscribe ( {
129+ next : ( ) => {
130+ this . isButtonUpdateUserFormLoading = false ;
131+ this . alertService . createSuccessAlert ( translations . myAccountSuccessAlert ) ;
132+ this . changeDetectorRef . markForCheck ( ) ;
133+
134+ if ( this . user ?. language !== formValue . language ) {
135+ this . languageService . navigateWithUserLanguage (
136+ formValue . language as string ,
137+ AUTH_URLS . myAccount ,
138+ ) ;
139+ }
140+ } ,
141+ error : ( ) => {
142+ this . isButtonUpdateUserFormLoading = false ;
143+ this . alertService . createErrorAlert ( translations . genericErrorAlert ) ;
144+ this . changeDetectorRef . markForCheck ( ) ;
145+ } ,
146+ } ) ;
147+ }
134148}
0 commit comments