Fixed issue with deltagare-state when loading a new deltagare
This commit is contained in:
@@ -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<string> = this.deltagareCardService.activeTab$;
|
||||
|
||||
private _reportsParams$ = new BehaviorSubject<PaginationParams>({ page: 1, limit: 20 });
|
||||
@@ -43,8 +43,8 @@ export class DeltagareCardComponent extends UnsubscribeDirective {
|
||||
workLanguages$: Observable<string[]> = this.deltagareCardService.workLanguages$;
|
||||
disabilities$: Observable<Disability[]> = this.deltagareCardService.disabilities$;
|
||||
availableHandledare$: Observable<Handledare[]> = 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<ReportsData> = 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
|
||||
|
||||
@@ -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<string | null>(null);
|
||||
|
||||
currentGenomforandeReferens$: Observable<number> = this._genomforandeReferensFromParams$.pipe(
|
||||
filter(gr => !!gr),
|
||||
map(genomforandeReferens => +genomforandeReferens)
|
||||
map(genomforandeReferens => (genomforandeReferens ? +genomforandeReferens : null))
|
||||
);
|
||||
avropNeedsUpdate$: Observable<void> = this.handledareService.lastSavedHandledare$.pipe(mapTo(undefined as void));
|
||||
|
||||
contactInformation$: Observable<ContactInformation> = 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<WorkExperience[]> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchWorkExperiences$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
highestEducation$: Observable<HighestEducation> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchHighestEducation$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchHighestEducation$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
educations$: Observable<Education[]> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchEducations$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchEducations$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
driversLicense$: Observable<DriversLicense> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchDriversLicense$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchDriversLicense$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
workLanguages$: Observable<string[]> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchWorkLanguages$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
disabilities$: Observable<Disability[]> = this.currentGenomforandeReferens$.pipe(
|
||||
switchMap(genomforandeReferens => this.deltagareApiService.fetchDisabilities$(genomforandeReferens)),
|
||||
switchMap(genomforandeReferens =>
|
||||
genomforandeReferens ? this.deltagareApiService.fetchDisabilities$(genomforandeReferens) : null
|
||||
),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user