From 63874e461e0b5fbd2e373b61e0157b961f82346f Mon Sep 17 00:00:00 2001 From: Bozhen Date: Wed, 30 Oct 2024 15:24:58 +0200 Subject: [PATCH] fix: Fix order error occured after refactoring Changed input type of saveLocation() to correct one. Disabled saving location object from the getLocations() to the localStorage, because it accepts locations from getInfoAboutTariff() request that gives us different structure of locations. Refactored deprecated .subscribe() signature. --- .../ubs-main-page/ubs-main-page.component.ts | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/app/ubs/ubs/components/ubs-main-page/ubs-main-page.component.ts b/src/app/ubs/ubs/components/ubs-main-page/ubs-main-page.component.ts index 410c3ba430..8817345f54 100644 --- a/src/app/ubs/ubs/components/ubs-main-page/ubs-main-page.component.ts +++ b/src/app/ubs/ubs/components/ubs-main-page/ubs-main-page.component.ts @@ -7,13 +7,12 @@ import { Subject, Subscription } from 'rxjs'; import { takeUntil, finalize, tap, concatMap, switchMap } from 'rxjs/operators'; import { ubsMainPageImages } from '../../../../main/image-pathes/ubs-main-page-images'; import { - AllLocationsDtos, - CourierLocations, Bag, OrderDetails, LocationsDtosList, ActiveCourierDto, - AllActiveLocationsDtosResponse + AllActiveLocationsDtosResponse, + ActiveRegionDto } from '../../models/ubs.interface'; import { OrderService } from '../../services/order.service'; import { UbsOrderLocationPopupComponent } from '../ubs-order-details/ubs-order-location-popup/ubs-order-location-popup.component'; @@ -34,7 +33,7 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked private subs = new Subscription(); private destroy: Subject = new Subject(); ubsMainPageImages = ubsMainPageImages; - locations: CourierLocations; + locations: ActiveRegionDto; selectedLocationId: number; isFetching: boolean; currentLocation: string; @@ -244,8 +243,8 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked this.isFetching = false; }) ) - .subscribe( - (res: any) => { + .subscribe({ + next: (res: AllActiveLocationsDtosResponse) => { if (res.orderIsPresent) { this.saveLocation(res); this.router.navigate(['ubs', 'order']); @@ -253,10 +252,10 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked this.openLocationDialog(res); } }, - (e) => { + error: (e) => { console.error(e); } - ); + }); } private getActiveLocationsToShow(): Observable { @@ -279,19 +278,17 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked ); } - saveLocation(locationsData: AllLocationsDtos): void { - this.locations = locationsData.tariffsForLocationDto; - this.selectedLocationId = locationsData.tariffsForLocationDto.locationsDtosList[0].locationId; - this.selectedTariffId = locationsData.tariffsForLocationDto.tariffInfoId; - this.currentLocation = locationsData.tariffsForLocationDto.locationsDtosList[0].nameEn; + saveLocation(locationsData: AllActiveLocationsDtosResponse): void { + this.locations = locationsData.allActiveLocationsDtos[0]; + this.selectedLocationId = locationsData.allActiveLocationsDtos[0].locations[0].locationId; + this.selectedTariffId = locationsData.allActiveLocationsDtos[0].locations[0].tariffInfoDto.tariffInfoId; + this.currentLocation = locationsData.allActiveLocationsDtos[0].nameEn; this.orderService.completedLocation(true); this.localStorageService.setLocationId(this.selectedLocationId); this.localStorageService.setTariffId(this.selectedTariffId); - this.localStorageService.setLocations(this.locations); - this.orderService.setLocationData(this.currentLocation); } - openLocationDialog(locationsData: AllLocationsDtos): void { + openLocationDialog(locationsData: AllActiveLocationsDtosResponse): void { const dialogRef = this.dialog.open(UbsOrderLocationPopupComponent, { hasBackdrop: true, disableClose: false, @@ -302,16 +299,16 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked dialogRef .afterClosed() .pipe(takeUntil(this.destroy)) - .subscribe( - (res) => { + .subscribe({ + next: (res) => { if (res?.data) { this.router.navigate(['ubs', 'order']); } }, - (e) => { + error: (e) => { console.error(e); } - ); + }); } getElementDescription(nameUk: string, nameEng: string, capacity: number): string {