Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oliinyk / Token PersonalInfo read replacement & Removing Subrole concept & Employee role #2649

Merged
merged 13 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -89,6 +91,12 @@ registerLocaleData(localeUk);
provide: MAT_SELECT_CONFIG,
useValue: { overlayPanelClass: 'custom-overlay-panel' }
},
{
provide: APP_INITIALIZER,
useFactory: (store: Store) => (): Observable<unknown> => store.dispatch(new CheckAuth()),
deps: [Store],
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorHandleInterceptor,
Expand Down
4 changes: 2 additions & 2 deletions src/app/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 class="header-descr">{{ headerSubtitle }}</h2>
<a [routerLink]="'./personal-cabinet/' + user.role + '/info'">
<button mat-menu-item>{{ 'ENUM.NAV_BAR_NAME.INFORMATION_ABOUT' | translate }} {{ RoleLinks[user.role] | translate }}</button>
</a>
<a *ngIf="user.role === Role.provider" [routerLink]="'./personal-cabinet/provider/workshops'">
<a *ngIf="isRoleProvider(user.role)" [routerLink]="'./personal-cabinet/provider/workshops'">
<button mat-menu-item>
{{ 'ENUM.NAV_BAR_NAME.MY_WORKSHOPS' | translate }}
</button>
Expand All @@ -139,7 +139,7 @@ <h2 class="header-descr">{{ headerSubtitle }}</h2>
{{ 'ENUM.NAV_BAR_NAME.MESSAGES' | translate }}
</button>
</a>
<a *ngIf="user.role === Role.provider && subrole !== Subrole.ProviderAdmin" [routerLink]="'./personal-cabinet/provider/administration'">
<a *ngIf="user.role === Role.provider || user.role === Role.providerDeputy" [routerLink]="'./personal-cabinet/provider/administration'">
<button mat-menu-item>
{{ 'ENUM.NAV_BAR_NAME.ADMINISTRATION' | translate }}
</button>
Expand Down
6 changes: 3 additions & 3 deletions src/app/header/header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -102,7 +102,6 @@ describe('HeaderComponent', () => {
@State<RegistrationStateModel>({
name: 'registration',
defaults: {
subrole: Subrole.None,
isAuthorized: false,
isLoading: false,
isAuthorizationLoading: true,
Expand All @@ -113,7 +112,8 @@ describe('HeaderComponent', () => {
firstName: '',
id: '',
role: '',
isBlocked: false
isBlocked: false,
emailConfirmed: false
},
provider: undefined,
parent: undefined,
Expand Down
19 changes: 7 additions & 12 deletions src/app/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -45,18 +46,16 @@ export class HeaderComponent implements OnInit, OnDestroy {
public user$: Observable<User>;
@Select(MetaDataState.featuresList)
public featuresList$: Observable<FeaturesList>;
@Select(RegistrationState.subrole)
public subrole$: Observable<string>;
@Select(MainPageState.headerInfo)
public headerInfo$: Observable<CompanyInformation>;

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;
Expand All @@ -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<boolean> = new Subject<boolean>();

constructor(
Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<div class="wrapper">
<div
*ngIf="isProviderView && role === Role.provider && (subrole === Subrole.None || subrole === Subrole.ProviderDeputy)"
class="flex flex-row justify-end">
<div *ngIf="(isProviderView && role === Role.provider) || role === Role.providerDeputy" class="flex flex-row justify-end">
<a [routerLink]="['/create-provider', editLink]" (click)="onActivateEditMode()" class="edit-icon">
<button mat-button><mat-icon>edit</mat-icon>{{ 'BUTTONS.EDIT' | translate }}</button>
</a>
Expand Down
17 changes: 4 additions & 13 deletions src/app/shared/components/provider-info/provider-info.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -32,8 +32,6 @@ export class ProviderInfoComponent implements OnInit, OnDestroy {
public institutionStatuses$: Observable<DataItem[]>;
@Select(RegistrationState.role)
public role$: Observable<Role>;
@Select(RegistrationState.subrole)
public subrole$: Observable<Subrole>;

public readonly constants = Constants;
public readonly ownershipTypes = OwnershipTypes;
Expand All @@ -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<boolean> = new Subject<boolean>();
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
<a [routerLink]="'./personal-cabinet/' + user.role + '/info'" (click)="changeView()">
{{ 'ENUM.NAV_BAR_NAME.INFORMATION_ABOUT' | translate }} {{ RoleLinks[user.role] | translate }}</a
>
<a *ngIf="user.role === Role.provider" [routerLink]="'./personal-cabinet/provider/workshops'" (click)="changeView()">{{
<a *ngIf="isRoleProvider(user.role)" [routerLink]="'./personal-cabinet/provider/workshops'" (click)="changeView()">{{
'ENUM.NAV_BAR_NAME.MY_WORKSHOPS' | translate
}}</a>
<a [routerLink]="'./personal-cabinet/' + user.role + '/applications'" (click)="changeView()">{{
'ENUM.NAV_BAR_NAME.APPLICATIONS' | translate
}}</a>
<a [routerLink]="'./personal-cabinet/messages'" (click)="changeView()">{{ 'ENUM.NAV_BAR_NAME.MESSAGES' | translate }}</a>
<a
*ngIf="user.role === Role.provider && (subrole$ | async) !== Role.ProviderAdmin"
*ngIf="user.role === Role.provider && user.role === Role.providerDeputy"
[routerLink]="'./personal-cabinet/provider/administration'"
(click)="changeView()"
>{{ 'ENUM.NAV_BAR_NAME.ADMINISTRATION' | translate }}</a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SidenavToggle } from 'shared/store/navigation.actions';
import { NavigationState } from 'shared/store/navigation.state';
import { Login, Logout } from 'shared/store/registration.actions';
import { RegistrationState } from 'shared/store/registration.state';
import { isRoleProvider } from 'shared/utils/provider.utils';

@Component({
selector: 'app-sidenav-menu',
Expand All @@ -30,8 +31,6 @@ export class SidenavMenuComponent implements OnInit, OnDestroy {
public sidenavOpenTrue$: Observable<boolean>;
@Select(RegistrationState.user)
public user$: Observable<User>;
@Select(RegistrationState.subrole)
public subrole$: Observable<string>;
@Select(RegistrationState.isAuthorized)
public isAuthorized$: Observable<string>;
@Select(MetaDataState.featuresList)
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@
<th mat-header-cell *matHeaderCellDef sortActionDescription="Sort by actions" style="width: 7%"></th>
<td mat-cell *matCellDef="let user">
<div class="icons flex flex-row justify-between items-center">
<button *ngIf="subrole !== Role.deputy" mat-icon-button [matMenuTriggerFor]="actions">
<button *ngIf="role !== Role.providerDeputy" mat-icon-button [matMenuTriggerFor]="actions">
<mat-icon class="action-icon">more_vert</mat-icon>
</button>
</div>

<mat-menu #actions="matMenu" class="header_menu">
<button *ngIf="isEdit" mat-menu-item (click)="update.emit(user)">{{ 'BUTTONS.EDIT_USER' | translate }}</button>
<!-- user.isBlocked is for Parent's blocking, user.status is for Admin's or Provider Admin's blocking -->
<!-- user.isBlocked is for Parent's blocking, user.status is for Admin's or Employee's blocking -->
<ng-container *ngIf="user.isBlocked || user.status === userStatuses.Blocked; then unBlock; else Block"></ng-container>
<ng-template #Block>
<button mat-menu-item (click)="block.emit({ user, isBlocking: true })">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('UsersListComponent', () => {
fixture = TestBed.createComponent(UsersListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
component.subrole = '' as string;
});

it('should create', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/app/shared/components/users-list/users-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { AfterViewInit, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-table';
import { MatTableDataSource } from '@angular/material/table';
import { MatSort, Sort } from '@angular/material/sort';
import { Store } from '@ngxs/store';

Expand Down Expand Up @@ -41,7 +41,6 @@ export class UsersListComponent implements OnInit, AfterViewInit, OnChanges {
public readonly tooltipPosition = Constants.MAT_TOOL_TIP_POSITION_BELOW;
public readonly Role = Role;

public subrole: string;
public dataSource: MatTableDataSource<object> = new MatTableDataSource([{}]);

constructor(
Expand All @@ -50,7 +49,6 @@ export class UsersListComponent implements OnInit, AfterViewInit, OnChanges {
) {}

public ngOnInit(): void {
this.subrole = this.store.selectSnapshot<string>(RegistrationState.subrole);
this.dataSource = new MatTableDataSource(this.users);
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/constants/changes-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ColumnsListForChangesLogHistory {
'newValue'
];

static readonly ProviderAdmins = [
static readonly Employees = [
'pib',
'email',
'providerTitle',
Expand Down
Loading
Loading