Skip to content

Commit

Permalink
fix: Fix order error occured after refactoring
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzhn committed Oct 30, 2024
1 parent ead8836 commit 63874e4
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/app/ubs/ubs/components/ubs-main-page/ubs-main-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,7 +33,7 @@ export class UbsMainPageComponent implements OnInit, OnDestroy, AfterViewChecked
private subs = new Subscription();
private destroy: Subject<boolean> = new Subject<boolean>();
ubsMainPageImages = ubsMainPageImages;
locations: CourierLocations;
locations: ActiveRegionDto;
selectedLocationId: number;
isFetching: boolean;
currentLocation: string;
Expand Down Expand Up @@ -244,19 +243,19 @@ 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']);
} else {
this.openLocationDialog(res);
}
},
(e) => {
error: (e) => {
console.error(e);
}
);
});
}

private getActiveLocationsToShow(): Observable<AllActiveLocationsDtosResponse> {
Expand All @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 63874e4

Please sign in to comment.