Fixed issue with deltagare-state when loading a new deltagare

This commit is contained in:
Erik Tiekstra
2021-10-25 14:33:09 +02:00
parent fca91fbbf1
commit 73ed2f2c6f
2 changed files with 33 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'; import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive'; import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive';
import { Feature } from '@msfa-enums/feature.enum'; import { Feature } from '@msfa-enums/feature.enum';
@@ -27,7 +27,7 @@ import { DeltagareCardService } from './deltagare-card.service';
styleUrls: ['./deltagare-card.component.scss'], styleUrls: ['./deltagare-card.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class DeltagareCardComponent extends UnsubscribeDirective { export class DeltagareCardComponent extends UnsubscribeDirective implements OnDestroy {
activeTab$: Observable<string> = this.deltagareCardService.activeTab$; activeTab$: Observable<string> = this.deltagareCardService.activeTab$;
private _reportsParams$ = new BehaviorSubject<PaginationParams>({ page: 1, limit: 20 }); private _reportsParams$ = new BehaviorSubject<PaginationParams>({ page: 1, limit: 20 });
@@ -43,8 +43,8 @@ export class DeltagareCardComponent extends UnsubscribeDirective {
workLanguages$: Observable<string[]> = this.deltagareCardService.workLanguages$; workLanguages$: Observable<string[]> = this.deltagareCardService.workLanguages$;
disabilities$: Observable<Disability[]> = this.deltagareCardService.disabilities$; disabilities$: Observable<Disability[]> = this.deltagareCardService.disabilities$;
availableHandledare$: Observable<Handledare[]> = this.avropInformation$.pipe( availableHandledare$: Observable<Handledare[]> = this.avropInformation$.pipe(
filter(() => !!this.handledarePickerVisible),
distinctUntilChanged((prevAvrop, currAvrop) => prevAvrop.id === currAvrop.id), distinctUntilChanged((prevAvrop, currAvrop) => prevAvrop.id === currAvrop.id),
filter(() => !!this.handledarePickerVisible),
switchMap(avropInformation => this.handledareService.fetchAvailableHandledare$([avropInformation.id])) switchMap(avropInformation => this.handledareService.fetchAvailableHandledare$([avropInformation.id]))
); );
reportsData$: Observable<ReportsData> = this._reportsParams$.pipe( reportsData$: Observable<ReportsData> = this._reportsParams$.pipe(
@@ -90,6 +90,10 @@ export class DeltagareCardComponent extends UnsubscribeDirective {
); );
} }
ngOnDestroy(): void {
this.deltagareCardService.setGenomforandereferens(null);
}
get deltagareTjanstVisible(): boolean { get deltagareTjanstVisible(): boolean {
return this._userRoles?.some( return this._userRoles?.some(
role => role.type === RoleEnum.MSFA_ReportAndPlanning || role.type === RoleEnum.MSFA_ReceiveDeltagare role => role.type === RoleEnum.MSFA_ReportAndPlanning || role.type === RoleEnum.MSFA_ReceiveDeltagare

View File

@@ -11,7 +11,7 @@ import { WorkExperience } from '@msfa-models/work-experience.model';
import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service'; import { DeltagareApiService } from '@msfa-services/api/deltagare.api.service';
import { HandledareService } from '@msfa-services/handledare.service'; import { HandledareService } from '@msfa-services/handledare.service';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { filter, map, mapTo, shareReplay, switchMap } from 'rxjs/operators'; import { map, mapTo, shareReplay, switchMap } from 'rxjs/operators';
@Injectable() @Injectable()
export class DeltagareCardService { export class DeltagareCardService {
@@ -21,13 +21,14 @@ export class DeltagareCardService {
private _genomforandeReferensFromParams$ = new BehaviorSubject<string | null>(null); private _genomforandeReferensFromParams$ = new BehaviorSubject<string | null>(null);
currentGenomforandeReferens$: Observable<number> = this._genomforandeReferensFromParams$.pipe( currentGenomforandeReferens$: Observable<number> = this._genomforandeReferensFromParams$.pipe(
filter(gr => !!gr), map(genomforandeReferens => (genomforandeReferens ? +genomforandeReferens : null))
map(genomforandeReferens => +genomforandeReferens)
); );
avropNeedsUpdate$: Observable<void> = this.handledareService.lastSavedHandledare$.pipe(mapTo(undefined as void)); avropNeedsUpdate$: Observable<void> = this.handledareService.lastSavedHandledare$.pipe(mapTo(undefined as void));
contactInformation$: Observable<ContactInformation> = this.currentGenomforandeReferens$.pipe( contactInformation$: Observable<ContactInformation> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchContactInformation$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchContactInformation$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
@@ -35,37 +36,51 @@ export class DeltagareCardService {
this.currentGenomforandeReferens$, this.currentGenomforandeReferens$,
this.avropNeedsUpdate$, this.avropNeedsUpdate$,
]).pipe( ]).pipe(
switchMap(([genomforandeReferens]) => this.deltagareApiService.fetchAvropInformation$(genomforandeReferens)), switchMap(([genomforandeReferens]) =>
genomforandeReferens ? this.deltagareApiService.fetchAvropInformation$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
workExperiences$: Observable<WorkExperience[]> = this.currentGenomforandeReferens$.pipe( workExperiences$: Observable<WorkExperience[]> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
highestEducation$: Observable<HighestEducation> = this.currentGenomforandeReferens$.pipe( highestEducation$: Observable<HighestEducation> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchHighestEducation$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchHighestEducation$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
educations$: Observable<Education[]> = this.currentGenomforandeReferens$.pipe( educations$: Observable<Education[]> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchEducations$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchEducations$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
driversLicense$: Observable<DriversLicense> = this.currentGenomforandeReferens$.pipe( driversLicense$: Observable<DriversLicense> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchDriversLicense$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchDriversLicense$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
workLanguages$: Observable<string[]> = this.currentGenomforandeReferens$.pipe( workLanguages$: Observable<string[]> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );
disabilities$: Observable<Disability[]> = this.currentGenomforandeReferens$.pipe( disabilities$: Observable<Disability[]> = this.currentGenomforandeReferens$.pipe(
switchMap(genomforandeReferens => this.deltagareApiService.fetchDisabilities$(genomforandeReferens)), switchMap(genomforandeReferens =>
genomforandeReferens ? this.deltagareApiService.fetchDisabilities$(genomforandeReferens) : null
),
shareReplay(1) shareReplay(1)
); );