From 54a4505085698c36a5e1920f8ad49126a6942a44 Mon Sep 17 00:00:00 2001 From: Cyril Joseph Date: Wed, 23 Jul 2025 17:16:17 -0300 Subject: [PATCH] shipping and travel plan updates --- src/app/carnet/shipping/shipping.component.ts | 12 +++++++++--- src/app/carnet/travel-plan/travel-plan.component.ts | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/carnet/shipping/shipping.component.ts b/src/app/carnet/shipping/shipping.component.ts index fcc0b7f..3b9580f 100644 --- a/src/app/carnet/shipping/shipping.component.ts +++ b/src/app/carnet/shipping/shipping.component.ts @@ -10,7 +10,7 @@ import { Shipping } from '../../core/models/carnet/shipping'; import { Country } from '../../core/models/country'; import { State } from '../../core/models/state'; import { ZipCodeValidator } from '../../shared/validators/zipcode-validator'; -import { finalize, forkJoin, map, Subject, switchMap, takeUntil, throwError } from 'rxjs'; +import { finalize, forkJoin, map, of, Subject, switchMap, takeUntil, throwError } from 'rxjs'; import { DeliveryType } from '../../core/models/delivery-type'; import { DeliveryMethod } from '../../core/models/delivery-method'; import { PaymentType } from '../../core/models/payment-type'; @@ -302,10 +302,11 @@ export class ShippingComponent { loadShippingData(): void { this.isLoading = true; + this.holderService.getHolder(this.headerid).pipe( switchMap((holder: Holder) => { - if (!holder) { - return throwError(() => new Error('Holder not found')); + if (!holder?.holderid) { + return of(undefined); } return forkJoin({ @@ -322,6 +323,11 @@ export class ShippingComponent { finalize(() => this.isLoading = false) ).subscribe({ next: (results) => { + + if (!results) { // do nothing if empty + return; + } + this.holderid = results.holder.holderid; this.holderContacts = results.holderContacts; this.holderAddress = results.holderAddress; diff --git a/src/app/carnet/travel-plan/travel-plan.component.ts b/src/app/carnet/travel-plan/travel-plan.component.ts index 57b3f8e..2d10235 100644 --- a/src/app/carnet/travel-plan/travel-plan.component.ts +++ b/src/app/carnet/travel-plan/travel-plan.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, inject, Input, Output } from '@angular/core'; +import { Component, EventEmitter, inject, Input, Output, SimpleChanges } from '@angular/core'; import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { forkJoin } from 'rxjs'; import { TravelPlanService } from '../../core/services/carnet/travel-plan.service'; @@ -57,6 +57,12 @@ export class TravelPlanComponent { } } + ngOnChanges(changes: SimpleChanges) { + if (changes['headerid'] && this.headerid > 0) { + this.loadTravelPlan(); + } + } + onAvailableVisitCountrySelection(event: any) { this.selectedAvailableVisitCountry = event.value; }