Fixed issue with feature-toggling. Also implemented spinner when organization is changed.
This commit is contained in:
@@ -11,7 +11,7 @@ import { mapResponseToOrganization, Organization } from '@msfa-models/organizati
|
||||
import { Role } from '@msfa-models/role.model';
|
||||
import { mapResponseToUserInfo, UserInfo } from '@msfa-models/user-info.model';
|
||||
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
|
||||
import { filter, map, switchMap } from 'rxjs/operators';
|
||||
import { filter, map, switchMap, tap } from 'rxjs/operators';
|
||||
import { AuthenticationService } from './authentication.service';
|
||||
|
||||
@Injectable({
|
||||
@@ -26,6 +26,10 @@ export class UserService extends UnsubscribeDirective {
|
||||
public organizations$: Observable<Organization[]> = this._organizations$.asObservable();
|
||||
private _user$ = new BehaviorSubject<Employee>(null);
|
||||
public user$: Observable<Employee> = this._user$.asObservable();
|
||||
private _userRolesLoading$ = new BehaviorSubject<boolean>(false);
|
||||
public userRolesLoading$: Observable<boolean> = this._userRolesLoading$.asObservable();
|
||||
private _userLoading$ = new BehaviorSubject<boolean>(false);
|
||||
public userLoading$: Observable<boolean> = this._userLoading$.asObservable();
|
||||
private _userRoles$ = new BehaviorSubject<Role[]>(null);
|
||||
public userRoles$: Observable<Role[]> = this._userRoles$.asObservable();
|
||||
private _selectedOrganizationNumber$ = new BehaviorSubject<string>(null);
|
||||
@@ -45,11 +49,17 @@ export class UserService extends UnsubscribeDirective {
|
||||
combineLatest([this._isLoggedIn$, this.selectedOrganization$])
|
||||
.pipe(
|
||||
filter(([loggedIn, selectedOrganization]) => !!(loggedIn && selectedOrganization)),
|
||||
tap(() => {
|
||||
this._userLoading$.next(true);
|
||||
this._userRolesLoading$.next(true);
|
||||
}),
|
||||
switchMap(() => combineLatest([this._fetchUserInfo$(), this._fetchCurrentUser$()]))
|
||||
)
|
||||
.subscribe(([userInfo, currentUser]) => {
|
||||
this._userRoles$.next(userInfo.roles);
|
||||
this._user$.next(currentUser);
|
||||
this._userLoading$.next(false);
|
||||
this._userRolesLoading$.next(false);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user