2025-07-22 21:32:12 -03:00
|
|
|
|
|
|
|
|
import { Component, inject } from '@angular/core';
|
|
|
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
|
|
|
import { MatCardModule } from '@angular/material/card';
|
|
|
|
|
import { MatDividerModule } from '@angular/material/divider';
|
|
|
|
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
|
|
|
|
|
import { NavigationService } from '../../core/services/common/navigation.service';
|
|
|
|
|
import { NotificationService } from '../../core/services/common/notification.service';
|
|
|
|
|
import { StorageService } from '../../core/services/common/storage.service';
|
2025-07-23 16:38:54 -03:00
|
|
|
import { CarnetService } from '../../core/services/carnet/carnet.service';
|
|
|
|
|
import { Fees } from '../../core/models/carnet/fee';
|
2025-08-02 22:32:20 -03:00
|
|
|
import { finalize } from 'rxjs';
|
2025-07-22 21:32:12 -03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-terms-conditions',
|
|
|
|
|
imports: [MatCardModule,
|
|
|
|
|
MatButtonModule,
|
|
|
|
|
MatDividerModule,
|
|
|
|
|
MatCheckboxModule,
|
|
|
|
|
CommonModule,
|
|
|
|
|
FormsModule],
|
|
|
|
|
templateUrl: './terms-conditions.component.html',
|
|
|
|
|
styleUrl: './terms-conditions.component.scss'
|
|
|
|
|
})
|
|
|
|
|
export class TermsConditionsComponent {
|
|
|
|
|
|
|
|
|
|
currentDate = new Date();
|
|
|
|
|
hasReadAllTerms = false;
|
|
|
|
|
currentApplicationDetails: { headerid: number, applicationName: string } | null = null;
|
2025-08-02 22:32:20 -03:00
|
|
|
changeInProgress: boolean = false;
|
2025-07-23 16:38:54 -03:00
|
|
|
estimatedFees: Fees = {};
|
2025-07-22 21:32:12 -03:00
|
|
|
|
|
|
|
|
private notificationService = inject(NotificationService);
|
|
|
|
|
private errorHandler = inject(ApiErrorHandlerService);
|
|
|
|
|
private storageService = inject(StorageService);
|
|
|
|
|
private navigationService = inject(NavigationService);
|
2025-07-23 16:38:54 -03:00
|
|
|
private carnetService = inject(CarnetService);
|
2025-07-22 21:32:12 -03:00
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.currentApplicationDetails = this.storageService.get<{ headerid: number, applicationName: string }>('currentapplication')
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-23 16:38:54 -03:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
if (this.currentApplicationDetails?.headerid) {
|
|
|
|
|
this.carnetService.getEstimatedFees(this.currentApplicationDetails?.headerid).subscribe({
|
|
|
|
|
next: (data: Fees) => {
|
|
|
|
|
if (data) {
|
|
|
|
|
this.estimatedFees = data;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: (error: any) => {
|
|
|
|
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get estimated fees');
|
|
|
|
|
this.notificationService.showError(errorMessage);
|
|
|
|
|
console.error('Error getting estimated fees:', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 21:32:12 -03:00
|
|
|
onAccept(): void {
|
2025-08-02 22:32:20 -03:00
|
|
|
this.changeInProgress = true;
|
|
|
|
|
this.carnetService.submitApplication(this.currentApplicationDetails?.headerid!).pipe(finalize(() => {
|
|
|
|
|
this.changeInProgress = false;
|
|
|
|
|
})).subscribe({
|
2025-07-23 16:38:54 -03:00
|
|
|
next: () => {
|
|
|
|
|
this.notificationService.showSuccess('Application submitted successfully');
|
|
|
|
|
this.storageService.removeItem('currentapplication');
|
|
|
|
|
this.navigationService.navigate(["home"]);
|
|
|
|
|
},
|
|
|
|
|
error: (error) => {
|
|
|
|
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to submit application');
|
|
|
|
|
this.notificationService.showError(errorMessage);
|
|
|
|
|
console.error('Error submitting the application', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-07-22 21:32:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDecline(): void {
|
2025-07-23 16:38:54 -03:00
|
|
|
this.storageService.removeItem('currentapplication');
|
2025-07-22 21:32:12 -03:00
|
|
|
this.navigationService.navigate(["edit-carnet", this.currentApplicationDetails?.headerid],
|
|
|
|
|
{
|
|
|
|
|
state: { isEditMode: true },
|
|
|
|
|
queryParams: {
|
|
|
|
|
applicationname: this.currentApplicationDetails?.applicationName,
|
|
|
|
|
return: 'shipping'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|