Browse Source

UI: Fixed profile update

pull/9057/head
Artem Dzhereleiko 3 years ago
parent
commit
1882cbdf4a
  1. 12
      ui-ngx/src/app/core/auth/auth.actions.ts
  2. 3
      ui-ngx/src/app/core/auth/auth.reducer.ts
  3. 11
      ui-ngx/src/app/modules/home/pages/profile/profile.component.ts
  4. 1
      ui-ngx/src/app/shared/models/user.model.ts

12
ui-ngx/src/app/core/auth/auth.actions.ts

@ -15,7 +15,7 @@
///
import { Action } from '@ngrx/store';
import { User } from '@shared/models/user.model';
import { AuthUser, User } from '@shared/models/user.model';
import { AuthPayload } from '@core/auth/auth.models';
import { UserSettings } from '@shared/models/user-settings.models';
@ -24,6 +24,7 @@ export enum AuthActionTypes {
UNAUTHENTICATED = '[Auth] Unauthenticated',
LOAD_USER = '[Auth] Load User',
UPDATE_USER_DETAILS = '[Auth] Update User Details',
UPDATE_AUTH_USER = '[Auth] Update Auth User',
UPDATE_LAST_PUBLIC_DASHBOARD_ID = '[Auth] Update Last Public Dashboard Id',
UPDATE_HAS_REPOSITORY = '[Auth] Change Has Repository',
UPDATE_OPENED_MENU_SECTION = '[Preferences] Update Opened Menu Section',
@ -53,6 +54,12 @@ export class ActionAuthUpdateUserDetails implements Action {
constructor(readonly payload: { userDetails: User }) {}
}
export class ActionAuthUpdateAuthUser implements Action {
readonly type = AuthActionTypes.UPDATE_AUTH_USER;
constructor(readonly payload: { authUser: AuthUser }) {}
}
export class ActionAuthUpdateLastPublicDashboardId implements Action {
readonly type = AuthActionTypes.UPDATE_LAST_PUBLIC_DASHBOARD_ID;
@ -85,4 +92,5 @@ export class ActionPreferencesDeleteUserSettings implements Action {
export type AuthActions = ActionAuthAuthenticated | ActionAuthUnauthenticated |
ActionAuthLoadUser | ActionAuthUpdateUserDetails | ActionAuthUpdateLastPublicDashboardId | ActionAuthUpdateHasRepository |
ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings;
ActionPreferencesUpdateOpenedMenuSection | ActionPreferencesPutUserSettings | ActionPreferencesDeleteUserSettings |
ActionAuthUpdateAuthUser;

3
ui-ngx/src/app/core/auth/auth.reducer.ts

@ -58,6 +58,9 @@ export const authReducer = (
case AuthActionTypes.UPDATE_USER_DETAILS:
return { ...state, ...action.payload};
case AuthActionTypes.UPDATE_AUTH_USER:
return { ...state, ...action.payload};
case AuthActionTypes.UPDATE_LAST_PUBLIC_DASHBOARD_ID:
return { ...state, ...action.payload};

11
ui-ngx/src/app/modules/home/pages/profile/profile.component.ts

@ -23,13 +23,14 @@ import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { HasConfirmForm } from '@core/guards/confirm-on-exit.guard';
import { ActionAuthUpdateUserDetails } from '@core/auth/auth.actions';
import { ActionAuthUpdateAuthUser, ActionAuthUpdateUserDetails } from '@core/auth/auth.actions';
import { environment as env } from '@env/environment';
import { TranslateService } from '@ngx-translate/core';
import { ActionSettingsChangeLanguage } from '@core/settings/settings.actions';
import { ActivatedRoute } from '@angular/router';
import { isDefinedAndNotNull } from '@core/utils';
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
import { AuthService } from '@core/auth/auth.service';
@Component({
selector: 'tb-profile',
@ -47,6 +48,7 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
constructor(protected store: Store<AppState>,
private route: ActivatedRoute,
private userService: UserService,
private authService: AuthService,
private translate: TranslateService,
public fb: UntypedFormBuilder) {
super(store);
@ -93,7 +95,14 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
id: user.id,
lastName: user.lastName,
} }));
this.store.dispatch(new ActionAuthUpdateAuthUser({ authUser: {...this.authUser, ...{
sub: user.email,
phone: user.phone,
firstName: user.firstName,
lastName: user.lastName,
}}}));
this.store.dispatch(new ActionSettingsChangeLanguage({ userLang: user.additionalInfo.lang }));
this.authService.refreshJwtToken(false);
}
);
}

1
ui-ngx/src/app/shared/models/user.model.ts

@ -54,6 +54,7 @@ export interface AuthUser {
customerId: string;
isPublic: boolean;
authority: Authority;
phone: string;
}
export interface UserEmailInfo {

Loading…
Cancel
Save