import { MwUserService } from 'projects/core/src//auth'; import { Component, OnInit, OnDestroy } from '@angular/core'; import { Subject } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; import { Config, MwAppConfigService } from 'projects/core/src//config'; @Component({ selector: 'mw-no-access', templateUrl: 'no-access.component.html', styleUrls: ['./no-access.component.scss'], }) export class NoAccessComponent implements OnInit, OnDestroy { get companyHasAccess(): boolean { return this._companyHasAccess; } get title(): string { return !this._companyHasAccess ? this._config?.pages?.noAccess?.title || '' : 'CORE.AUTH.PAGE.NO_ACCESS.company_level_title'; } get subTitle(): string { return !this._companyHasAccess ? this._config?.pages?.noAccess?.subTitle || '' : 'CORE.AUTH.PAGE.NO_ACCESS.company_level_sub_title'; } get readMoreText(): string { return !this._companyHasAccess ? this._config?.pages?.noAccess?.readMoreText || '' : ''; } get contactText(): string { return !this._companyHasAccess ? this._config?.pages?.noAccess?.contactSalesText || '' : 'CORE.AUTH.PAGE.NO_ACCESS.company_level_contact'; } get readMoreLink(): string { return this._config?.pages?.noAccess?.readMoreLink || ''; } get contactLink(): string { return !this._companyHasAccess ? this._config?.pages?.noAccess?.contactSalesLink ?? 'salg@mworker.no' : this._primaryAdminEmail; } private _companyHasAccess = false; private _config?: Config = undefined; private _primaryAdminEmail: string = ''; private unsubscribeAll$ = new Subject(); constructor( private readonly configService: MwAppConfigService, private readonly userService: MwUserService ) {} ngOnDestroy(): void { this.unsubscribeAll$.next(true); this.unsubscribeAll$.complete(); } ngOnInit(): void { this.configService.setConfigChunk('layout.toolbar.showToggler', false); this.configService .getConfig() .pipe(takeUntil(this.unsubscribeAll$)) .subscribe((config) => (this._config = config)); this.userService.userProfile$ .pipe( takeUntil(this.unsubscribeAll$), filter((profile) => !!profile) ) .subscribe((profile) => { if (profile) { this._companyHasAccess = profile.companyHasAccessToModule; this._primaryAdminEmail = profile.primaryAdminEmail; } }); } }