169 lines
5.6 KiB
TypeScript
169 lines
5.6 KiB
TypeScript
import { CommonModule } from '@angular/common';
|
|
import { Component, inject, ViewChild } from '@angular/core';
|
|
import { AngularMaterialModule } from '../../shared/module/angular-material.module';
|
|
import { ReactiveFormsModule } from '@angular/forms';
|
|
import { ApplicationComponent } from '../application/application.component';
|
|
import { StepperSelectionEvent } from '@angular/cdk/stepper';
|
|
import { GoodsComponent } from '../goods/goods.component';
|
|
import { HolderComponent } from '../holder/holder.component';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { ShippingComponent } from '../shipping/shipping.component';
|
|
import { TravelPlanComponent } from '../travel-plan/travel-plan.component';
|
|
import { UserPreferences } from '../../core/models/user-preference';
|
|
import { UserPreferencesService } from '../../core/services/user-preference.service';
|
|
import { ReplacementSetComponent } from '../replacement-set/replacement-set.component';
|
|
|
|
@Component({
|
|
selector: 'app-edit-carnet',
|
|
imports: [AngularMaterialModule, CommonModule, ReactiveFormsModule,
|
|
ApplicationComponent, HolderComponent, GoodsComponent, TravelPlanComponent, ShippingComponent, ReplacementSetComponent],
|
|
templateUrl: './edit-carnet.component.html',
|
|
styleUrl: './edit-carnet.component.scss'
|
|
})
|
|
export class EditCarnetComponent {
|
|
currentStep = 0;
|
|
isLinear = false;
|
|
applicationType: 'new' | 'edit' | 'additional' | 'duplicate' | 'extend' | null = 'edit';
|
|
isEditMode = true; // Set to true for edit mode
|
|
headerid: number = 0;
|
|
userPreferences: UserPreferences;
|
|
applicationName: string = '';
|
|
missingSectionMessage: string = '';
|
|
|
|
|
|
@ViewChild(ShippingComponent, { static: false })
|
|
private shippingComponent!: ShippingComponent;
|
|
|
|
// Track completion of each step
|
|
stepsCompleted = {
|
|
applicationDetail: true,
|
|
holderSelection: false,
|
|
goodsSection: false,
|
|
travelPlan: false,
|
|
shipping: false,
|
|
extension: false
|
|
};
|
|
|
|
private route = inject(ActivatedRoute);
|
|
|
|
constructor(userPrefenceService: UserPreferencesService) {
|
|
this.userPreferences = userPrefenceService.getPreferences();
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
const idParam = this.route.snapshot.paramMap.get('headerid');
|
|
this.headerid = idParam ? parseInt(idParam, 10) : 0;
|
|
|
|
this.applicationName = this.route.snapshot.queryParamMap.get('applicationname') || '';
|
|
|
|
let returnTo = this.route.snapshot.queryParamMap.get('return');
|
|
|
|
// set application type based on the route url
|
|
const urlSegments = this.route.snapshot.url.map(segment => segment.path);
|
|
if (urlSegments.includes('duplicate-carnet') || urlSegments.includes('process-duplicate-carnet')) {
|
|
this.applicationType = 'duplicate';
|
|
} else if (urlSegments.includes('extend-carnet') || urlSegments.includes('process-extend-carnet')) {
|
|
this.applicationType = 'extend';
|
|
}
|
|
else if (urlSegments.includes('additional-sets') || urlSegments.includes('process-additional-sets')) {
|
|
this.applicationType = 'additional';
|
|
} else {
|
|
this.applicationType = 'edit';
|
|
}
|
|
|
|
if (returnTo === 'holder') {
|
|
this.currentStep = 1;
|
|
} else if (returnTo === 'shipping' && this.applicationType === 'extend') {
|
|
this.currentStep = 5;
|
|
} else if (returnTo === 'shipping') {
|
|
this.currentStep = 4;
|
|
} else if (this.applicationType === 'additional') {
|
|
this.currentStep = 3;
|
|
} else if (this.applicationType === 'duplicate') {
|
|
this.currentStep = 4;
|
|
}
|
|
}
|
|
|
|
onStepChange(event: StepperSelectionEvent): void {
|
|
this.currentStep = event.selectedIndex;
|
|
}
|
|
|
|
onHolderSelectionSaved(completed: boolean): void {
|
|
this.stepsCompleted.holderSelection = completed;
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
onGoodsSectionSaved(completed: boolean): void {
|
|
this.stepsCompleted.goodsSection = completed;
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
onHolderSelectionUpdated(updated: boolean): void {
|
|
if (updated) {
|
|
this.shippingComponent?.refreshShippingData();
|
|
}
|
|
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
onTravelPlanSaved(completed: boolean): void {
|
|
this.stepsCompleted.travelPlan = completed;
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
onShippingSaved(completed: boolean): void {
|
|
this.stepsCompleted.shipping = completed;
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
onNeedsInsurance(data: boolean): void {
|
|
this.shippingComponent?.refreshInsuranceData(data);
|
|
}
|
|
|
|
onExtensionApplicationSaved(completed: boolean): void {
|
|
this.stepsCompleted.extension = completed;
|
|
this.isAllSectionsCompleted();
|
|
}
|
|
|
|
isAllSectionsCompleted() {
|
|
let allSectionsCompleted = this.stepsCompleted.applicationDetail
|
|
&& this.stepsCompleted.holderSelection && this.stepsCompleted.goodsSection
|
|
&& this.stepsCompleted.shipping && this.stepsCompleted.travelPlan
|
|
&& (this.applicationType !== 'extend' || this.stepsCompleted.extension);
|
|
|
|
if (allSectionsCompleted) {
|
|
this.missingSectionMessage = '';
|
|
}
|
|
else {
|
|
let message = 'Missing details in: ';
|
|
|
|
if(this.applicationType === 'extend' && !this.stepsCompleted.extension) {
|
|
message += 'Extension Application, ';
|
|
}
|
|
|
|
if (!this.stepsCompleted.applicationDetail) {
|
|
message += 'Application Name, ';
|
|
}
|
|
|
|
if (!this.stepsCompleted.holderSelection) {
|
|
message += 'Holder Selection, ';
|
|
}
|
|
|
|
if (!this.stepsCompleted.goodsSection) {
|
|
message += 'Goods Section, ';
|
|
}
|
|
|
|
if (!this.stepsCompleted.travelPlan) {
|
|
message += 'Travel Plan, ';
|
|
}
|
|
|
|
if (!this.stepsCompleted.shipping) {
|
|
message += 'Shipping & Payment, ';
|
|
}
|
|
|
|
// Remove trailing comma and space
|
|
this.missingSectionMessage = message.replace(/, $/, '');
|
|
}
|
|
}
|
|
}
|