diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8d8df25f11..7812daec13 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,7 +1,7 @@ import { registerLocaleData } from '@angular/common'; import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http'; import localeUk from '@angular/common/locales/uk'; -import { LOCALE_ID, NgModule } from '@angular/core'; +import { APP_INITIALIZER, LOCALE_ID, NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { MAT_LEGACY_SELECT_CONFIG as MAT_SELECT_CONFIG } from '@angular/material/legacy-select'; import { BrowserModule } from '@angular/platform-browser'; @@ -11,7 +11,8 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin'; import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin'; import { NgxsStoragePluginModule, StorageOption } from '@ngxs/storage-plugin'; -import { NgxsModule } from '@ngxs/store'; +import { NgxsModule, Store } from '@ngxs/store'; +import { Observable } from 'rxjs'; import { ErrorHandleInterceptor } from 'shared/interceptors/error-handle.interceptor'; import { RegistrationModule } from 'shared/modules/registration.module'; @@ -26,6 +27,7 @@ import { NavigationState } from 'shared/store/navigation.state'; import { NotificationState } from 'shared/store/notification.state'; import { ParentState } from 'shared/store/parent.state'; import { ProviderState } from 'shared/store/provider.state'; +import { CheckAuth } from 'shared/store/registration.actions'; import { RegistrationState } from 'shared/store/registration.state'; import { SharedUserState } from 'shared/store/shared-user.state'; import { environment } from '../environments/environment'; @@ -89,6 +91,12 @@ registerLocaleData(localeUk); provide: MAT_SELECT_CONFIG, useValue: { overlayPanelClass: 'custom-overlay-panel' } }, + { + provide: APP_INITIALIZER, + useFactory: (store: Store) => (): Observable => store.dispatch(new CheckAuth()), + deps: [Store], + multi: true + }, { provide: HTTP_INTERCEPTORS, useClass: ErrorHandleInterceptor, diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html index 6bdbed9896..6f54fd2d45 100644 --- a/src/app/header/header.component.html +++ b/src/app/header/header.component.html @@ -124,7 +124,7 @@

{{ headerSubtitle }}

- + @@ -139,7 +139,7 @@

{{ headerSubtitle }}

{{ 'ENUM.NAV_BAR_NAME.MESSAGES' | translate }}
- + diff --git a/src/app/header/header.component.spec.ts b/src/app/header/header.component.spec.ts index e099ae922b..76b2bc218c 100644 --- a/src/app/header/header.component.spec.ts +++ b/src/app/header/header.component.spec.ts @@ -13,7 +13,7 @@ import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { NgxsModule, State, Store } from '@ngxs/store'; import { OidcSecurityService } from 'angular-auth-oidc-client'; -import { Role, Subrole } from 'shared/enum/role'; +import { Role } from 'shared/enum/role'; import { MockOidcSecurityService } from 'shared/mocks/mock-services'; import { MainPageStateModel } from 'shared/store/main-page.state'; import { SidenavToggle } from 'shared/store/navigation.actions'; @@ -102,7 +102,6 @@ describe('HeaderComponent', () => { @State({ name: 'registration', defaults: { - subrole: Subrole.None, isAuthorized: false, isLoading: false, isAuthorizationLoading: true, @@ -113,7 +112,8 @@ describe('HeaderComponent', () => { firstName: '', id: '', role: '', - isBlocked: false + isBlocked: false, + emailConfirmed: false }, provider: undefined, parent: undefined, diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index 1541fe3fca..53023eb19e 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -3,14 +3,14 @@ import { DateAdapter } from '@angular/material/core'; import { Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { Select, Store } from '@ngxs/store'; -import { Observable, Subject, combineLatest } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { delay, filter, takeUntil } from 'rxjs/operators'; import { ModeConstants } from 'shared/constants/constants'; import { AdminTabTypes } from 'shared/enum/admins'; import { RoleLinks } from 'shared/enum/enumUA/user'; import { Languages } from 'shared/enum/languages'; -import { Role, Subrole } from 'shared/enum/role'; +import { Role } from 'shared/enum/role'; import { CompanyInformation } from 'shared/models/company-information.model'; import { FeaturesList } from 'shared/models/features-list.model'; import { Navigation } from 'shared/models/navigation.model'; @@ -24,6 +24,7 @@ import { NavigationState } from 'shared/store/navigation.state'; import { Login, Logout } from 'shared/store/registration.actions'; import { RegistrationState } from 'shared/store/registration.state'; import { isRoleAdmin } from 'shared/utils/admin.utils'; +import { isRoleProvider } from 'shared/utils/provider.utils'; @Component({ selector: 'app-header', @@ -45,18 +46,16 @@ export class HeaderComponent implements OnInit, OnDestroy { public user$: Observable; @Select(MetaDataState.featuresList) public featuresList$: Observable; - @Select(RegistrationState.subrole) - public subrole$: Observable; @Select(MainPageState.headerInfo) public headerInfo$: Observable; public readonly defaultAdminTab = AdminTabTypes.AboutPortal; public readonly Languages = Languages; public readonly Role = Role; - public readonly Subrole = Subrole; public readonly RoleLinks = RoleLinks; public readonly ModeConstants = ModeConstants; public readonly isRoleAdmin = isRoleAdmin; + public readonly isRoleProvider = isRoleProvider; public selectedLanguage = localStorage.getItem('ui-culture'); public showModalReg = false; @@ -66,7 +65,6 @@ export class HeaderComponent implements OnInit, OnDestroy { public headerTitle: string; public headerSubtitle: string; public navigationPaths: Navigation[]; - public subrole: string; private destroy$: Subject = new Subject(); constructor( @@ -79,12 +77,9 @@ export class HeaderComponent implements OnInit, OnDestroy { public ngOnInit(): void { this.store.dispatch(new GetMainPageInfo()); - combineLatest([this.subrole$, this.navigationPaths$]) - .pipe(takeUntil(this.destroy$), delay(0)) - .subscribe(([subrole, navigationPaths]: [Role, Navigation[]]) => { - this.subrole = subrole; - this.navigationPaths = navigationPaths; - }); + this.navigationPaths$.pipe(takeUntil(this.destroy$), delay(0)).subscribe((navigationPaths) => { + this.navigationPaths = navigationPaths; + }); this.isMobileScreen$.pipe(takeUntil(this.destroy$)).subscribe((isMobileScreen: boolean) => (this.isMobileScreen = isMobileScreen)); diff --git a/src/app/shared/components/notifications/notifications-list/notifications-list.component.ts b/src/app/shared/components/notifications/notifications-list/notifications-list.component.ts index 636dea4ad4..054abd74e6 100644 --- a/src/app/shared/components/notifications/notifications-list/notifications-list.component.ts +++ b/src/app/shared/components/notifications/notifications-list/notifications-list.component.ts @@ -28,6 +28,7 @@ import { import { NotificationState } from 'shared/store/notification.state'; import { GetPendingApplicationsByProviderId } from 'shared/store/provider.actions'; import { RegistrationState } from 'shared/store/registration.state'; +import { isRoleProvider } from 'shared/utils/provider.utils'; import { Util } from 'shared/utils/utils'; @Component({ @@ -183,7 +184,7 @@ export class NotificationsListComponent implements OnInit, OnChanges, OnDestroy if (receivedNotification.type !== NotificationType.Application && receivedNotification.type !== NotificationType.Chat) { this.notifications.unshift(receivedNotification); return; - } else if (receivedNotification.type === NotificationType.Application && this.role === Role.provider) { + } else if (receivedNotification.type === NotificationType.Application && isRoleProvider(this.role)) { const providerId = this.store.selectSnapshot(RegistrationState.provider).id; this.store.dispatch(new GetPendingApplicationsByProviderId(providerId)); } diff --git a/src/app/shared/components/provider-info/provider-info.component.html b/src/app/shared/components/provider-info/provider-info.component.html index 985a8ea037..9d3b5fbdca 100644 --- a/src/app/shared/components/provider-info/provider-info.component.html +++ b/src/app/shared/components/provider-info/provider-info.component.html @@ -1,7 +1,5 @@
-
+
diff --git a/src/app/shared/components/provider-info/provider-info.component.ts b/src/app/shared/components/provider-info/provider-info.component.ts index a1cb22a80a..33623da1a8 100644 --- a/src/app/shared/components/provider-info/provider-info.component.ts +++ b/src/app/shared/components/provider-info/provider-info.component.ts @@ -1,13 +1,13 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; -import { MatLegacyTabChangeEvent as MatTabChangeEvent } from '@angular/material/legacy-tabs'; +import { MatTabChangeEvent } from '@angular/material/tabs'; import { Select, Store } from '@ngxs/store'; -import { Observable, Subject, combineLatest } from 'rxjs'; +import { Observable, Subject } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; import { Constants } from 'shared/constants/constants'; import { InstitutionTypesEnum, LicenseStatusEnum, OwnershipTypesEnum } from 'shared/enum/enumUA/provider'; import { CreateProviderSteps, InstitutionTypes, OwnershipTypes } from 'shared/enum/provider'; -import { Role, Subrole } from 'shared/enum/role'; +import { Role } from 'shared/enum/role'; import { LicenseStatuses } from 'shared/enum/statuses'; import { DataItem } from 'shared/models/item.model'; import { Provider } from 'shared/models/provider.model'; @@ -32,8 +32,6 @@ export class ProviderInfoComponent implements OnInit, OnDestroy { public institutionStatuses$: Observable; @Select(RegistrationState.role) public role$: Observable; - @Select(RegistrationState.subrole) - public subrole$: Observable; public readonly constants = Constants; public readonly ownershipTypes = OwnershipTypes; @@ -43,10 +41,8 @@ export class ProviderInfoComponent implements OnInit, OnDestroy { public readonly licenseStatusEnum = LicenseStatusEnum; public readonly licenseStatuses = LicenseStatuses; public readonly Role = Role; - public readonly Subrole = Subrole; public role: Role; - public subrole: Subrole; public institutionStatusName: string; public editLink: string = CreateProviderSteps[0]; public destroy$: Subject = new Subject(); @@ -55,12 +51,7 @@ export class ProviderInfoComponent implements OnInit, OnDestroy { public ngOnInit(): void { this.store.dispatch(new GetInstitutionStatuses()); - combineLatest([this.role$, this.subrole$]) - .pipe(takeUntil(this.destroy$)) - .subscribe(([role, subrole]: [Role, Subrole]) => { - this.role = role; - this.subrole = subrole; - }); + this.role$.pipe(takeUntil(this.destroy$)).subscribe((role) => (this.role = role)); this.institutionStatuses$ .pipe(takeUntil(this.destroy$), filter(Boolean)) .subscribe( diff --git a/src/app/shared/components/sidenav-menu/sidenav-menu.component.html b/src/app/shared/components/sidenav-menu/sidenav-menu.component.html index 0a78225806..df4fba6eb4 100644 --- a/src/app/shared/components/sidenav-menu/sidenav-menu.component.html +++ b/src/app/shared/components/sidenav-menu/sidenav-menu.component.html @@ -43,7 +43,7 @@ {{ 'ENUM.NAV_BAR_NAME.INFORMATION_ABOUT' | translate }} {{ RoleLinks[user.role] | translate }} - {{ + {{ 'ENUM.NAV_BAR_NAME.MY_WORKSHOPS' | translate }} {{ @@ -51,7 +51,7 @@ }} {{ 'ENUM.NAV_BAR_NAME.MESSAGES' | translate }} {{ 'ENUM.NAV_BAR_NAME.ADMINISTRATION' | translate }}; @Select(RegistrationState.user) public user$: Observable; - @Select(RegistrationState.subrole) - public subrole$: Observable; @Select(RegistrationState.isAuthorized) public isAuthorized$: Observable; @Select(MetaDataState.featuresList) @@ -42,6 +41,7 @@ export class SidenavMenuComponent implements OnInit, OnDestroy { public readonly Role = Role; public readonly RoleLinks = RoleLinks; public readonly title = 'out-of-school'; + public readonly isRoleProvider = isRoleProvider; public showModalReg = false; public visibleSidenav: boolean; diff --git a/src/app/shared/components/status-info-card/status-info-card.component.ts b/src/app/shared/components/status-info-card/status-info-card.component.ts index c373238197..3c544b4d0d 100644 --- a/src/app/shared/components/status-info-card/status-info-card.component.ts +++ b/src/app/shared/components/status-info-card/status-info-card.component.ts @@ -1,4 +1,5 @@ import { Component, Input } from '@angular/core'; +import { isRoleProvider } from 'shared/utils/provider.utils'; import { ApplicationIcons } from '../../enum/applications'; import { ApplicationStatusDescription, ApplicationTitles } from '../../enum/enumUA/statuses'; import { ApplicationStatuses } from '../../enum/statuses'; @@ -29,9 +30,8 @@ export class StatusInfoCardComponent { } private setStatuses(): void { - this.statuses = - this.role === Role.provider - ? Object.values(ApplicationStatuses) - : Object.values(ApplicationStatuses).filter((status: ApplicationStatuses) => status !== ApplicationStatuses.Banned); + this.statuses = isRoleProvider(this.role) + ? Object.values(ApplicationStatuses) + : Object.values(ApplicationStatuses).filter((status: ApplicationStatuses) => status !== ApplicationStatuses.Banned); } } diff --git a/src/app/shared/components/users-list/users-list.component.html b/src/app/shared/components/users-list/users-list.component.html index 747029928d..6d311191c6 100644 --- a/src/app/shared/components/users-list/users-list.component.html +++ b/src/app/shared/components/users-list/users-list.component.html @@ -111,14 +111,14 @@
-
- +