From 73ed2f2c6fbdac2abce05f4f9726bdb95c082f34 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Mon, 25 Oct 2021 14:33:09 +0200 Subject: [PATCH] Fixed issue with deltagare-state when loading a new deltagare --- .../deltagare-card.component.ts | 10 +++-- .../deltagare-card/deltagare-card.service.ts | 37 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.component.ts b/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.component.ts index 6a96a07..2a00750 100644 --- a/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.component.ts +++ b/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive'; import { Feature } from '@msfa-enums/feature.enum'; @@ -27,7 +27,7 @@ import { DeltagareCardService } from './deltagare-card.service'; styleUrls: ['./deltagare-card.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class DeltagareCardComponent extends UnsubscribeDirective { +export class DeltagareCardComponent extends UnsubscribeDirective implements OnDestroy { activeTab$: Observable = this.deltagareCardService.activeTab$; private _reportsParams$ = new BehaviorSubject({ page: 1, limit: 20 }); @@ -43,8 +43,8 @@ export class DeltagareCardComponent extends UnsubscribeDirective { workLanguages$: Observable = this.deltagareCardService.workLanguages$; disabilities$: Observable = this.deltagareCardService.disabilities$; availableHandledare$: Observable = this.avropInformation$.pipe( - filter(() => !!this.handledarePickerVisible), distinctUntilChanged((prevAvrop, currAvrop) => prevAvrop.id === currAvrop.id), + filter(() => !!this.handledarePickerVisible), switchMap(avropInformation => this.handledareService.fetchAvailableHandledare$([avropInformation.id])) ); reportsData$: Observable = this._reportsParams$.pipe( @@ -90,6 +90,10 @@ export class DeltagareCardComponent extends UnsubscribeDirective { ); } + ngOnDestroy(): void { + this.deltagareCardService.setGenomforandereferens(null); + } + get deltagareTjanstVisible(): boolean { return this._userRoles?.some( role => role.type === RoleEnum.MSFA_ReportAndPlanning || role.type === RoleEnum.MSFA_ReceiveDeltagare diff --git a/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.service.ts b/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.service.ts index 96c0094..50d8480 100644 --- a/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.service.ts +++ b/apps/mina-sidor-fa/src/app/pages/deltagare/pages/deltagare-details/pages/deltagare-card/deltagare-card.service.ts @@ -11,7 +11,7 @@ import { WorkExperience } from '@msfa-models/work-experience.model'; import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service'; import { HandledareService } from '@msfa-services/handledare.service'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; -import { filter, map, mapTo, shareReplay, switchMap } from 'rxjs/operators'; +import { map, mapTo, shareReplay, switchMap } from 'rxjs/operators'; @Injectable() export class DeltagareCardService { @@ -21,13 +21,14 @@ export class DeltagareCardService { private _genomforandeReferensFromParams$ = new BehaviorSubject(null); currentGenomforandeReferens$: Observable = this._genomforandeReferensFromParams$.pipe( - filter(gr => !!gr), - map(genomforandeReferens => +genomforandeReferens) + map(genomforandeReferens => (genomforandeReferens ? +genomforandeReferens : null)) ); avropNeedsUpdate$: Observable = this.handledareService.lastSavedHandledare$.pipe(mapTo(undefined as void)); contactInformation$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchContactInformation$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchContactInformation$(genomforandeReferens) : null + ), shareReplay(1) ); @@ -35,37 +36,51 @@ export class DeltagareCardService { this.currentGenomforandeReferens$, this.avropNeedsUpdate$, ]).pipe( - switchMap(([genomforandeReferens]) => this.deltagareApiService.fetchAvropInformation$(genomforandeReferens)), + switchMap(([genomforandeReferens]) => + genomforandeReferens ? this.deltagareApiService.fetchAvropInformation$(genomforandeReferens) : null + ), shareReplay(1) ); workExperiences$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens) : null + ), shareReplay(1) ); highestEducation$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchHighestEducation$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchHighestEducation$(genomforandeReferens) : null + ), shareReplay(1) ); educations$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchEducations$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchEducations$(genomforandeReferens) : null + ), shareReplay(1) ); driversLicense$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchDriversLicense$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchDriversLicense$(genomforandeReferens) : null + ), shareReplay(1) ); workLanguages$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens) : null + ), shareReplay(1) ); disabilities$: Observable = this.currentGenomforandeReferens$.pipe( - switchMap(genomforandeReferens => this.deltagareApiService.fetchDisabilities$(genomforandeReferens)), + switchMap(genomforandeReferens => + genomforandeReferens ? this.deltagareApiService.fetchDisabilities$(genomforandeReferens) : null + ), shareReplay(1) );