Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { LocalStorageService } from 'src/app/shared/services/localstorage/local-storage.service';
import { forkJoin, Observable, Subject } from 'rxjs';
import { forkJoin, Observable, Subject, take } from 'rxjs';
import { takeUntil, tap } from 'rxjs/operators';
import { Bag, OrderDetails, PersonalData } from '@ubs/ubs/models/ubs.interface';
import { OrderService } from '@ubs/ubs/services/order.service';
Expand All @@ -13,6 +13,7 @@ import { UbsUserOrderPaymentPopUpComponent } from './ubs-user-order-payment-pop-
import { ubsPdfIcon } from '@ubs/shared/image-paths/ubs-user-images';
import { DialogPopUpComponent } from 'src/app/shared/components/dialog-pop-up/dialog-pop-up.component';
import { PopUpsStyles } from '@ubs/ubs-admin/components/ubs-admin-employee/ubs-admin-employee-table/employee-models.enum';
import { MatSnackBarService } from '@global-service/mat-snack-bar/mat-snack-bar.service';

@Component({
selector: 'app-ubs-user-orders-list',
Expand Down Expand Up @@ -45,7 +46,8 @@ export class UbsUserOrdersListComponent implements OnInit, OnDestroy {
private localStorageService: LocalStorageService,
private router: Router,
public ubsOrderService: UBSOrderFormService,
public orderService: OrderService
public orderService: OrderService,
public snackBarService: MatSnackBarService
) {}

ngOnInit(): void {
Expand Down Expand Up @@ -210,8 +212,7 @@ export class UbsUserOrdersListComponent implements OnInit, OnDestroy {
points: this.bonuses,
pointsSum: 0,
pointsToUse: 0,
total: order.orderFullPrice,
hasPaymentLink: !!order.paymentLink
total: order.orderFullPrice
};

this.personalDetails = personalDataResponse;
Expand All @@ -235,7 +236,20 @@ export class UbsUserOrdersListComponent implements OnInit, OnDestroy {
const personalData = JSON.stringify(this.personalDetails);
const orderData = JSON.stringify(this.orderDetails);
this.localStorageService.setUbsOrderDataBeforeRedirect(personalData, orderData, this.anotherClient, this.orderId);
this.redirectToStepOne();
if (this.orderDetails.hasPaymentLink) {
this.orderService
.cancelExistingPayment(Number(this.orderId))
.pipe(take(1))
.subscribe({
next: () => this.redirectToStepOne(),
error: () => {
console.error('Error canceling existing order with ID: ', this.orderId);
this.snackBarService.openSnackBar('error');
}
});
} else {
this.redirectToStepOne();
}
}

redirectToStepOne(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { Subject, forkJoin } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { UserOrdersService } from '../../services/user-orders.service';
Expand All @@ -20,7 +20,7 @@ import { MatSnackBarService } from '@global-service/mat-snack-bar/mat-snack-bar.
templateUrl: './ubs-user-orders.component.html',
styleUrls: ['./ubs-user-orders.component.scss']
})
export class UbsUserOrdersComponent implements OnInit, OnDestroy {
export class UbsUserOrdersComponent implements OnInit, AfterViewInit, OnDestroy {
destroy: Subject<boolean> = new Subject<boolean>();
currentOrders: IUserOrderInfo[] = [];
closedOrders: IUserOrderInfo[] = [];
Expand Down Expand Up @@ -159,7 +159,9 @@ export class UbsUserOrdersComponent implements OnInit, OnDestroy {
},
error: (err) => this.displayError(err)
});
}

ngAfterViewInit() {
this.orderIdToScroll = this.localStorage.getOrderIdToRedirect();
if (this.orderIdToScroll) {
this.openExtendedOrder();
Expand Down Expand Up @@ -213,16 +215,23 @@ export class UbsUserOrdersComponent implements OnInit, OnDestroy {
}
}
isPresent.extend = true;
setTimeout(() => this.scroll(this.orderIdToScroll), 0);
requestAnimationFrame(() => this.scroll(this.orderIdToScroll));
}

scroll(orderId: number): void {
const ord: string = orderId.toString();
document.getElementById(ord).scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
});
const element = document.getElementById(ord);
if (element) {
const panel = element.closest('mat-expansion-panel');
(panel.querySelector('mat-expansion-panel-header') as HTMLElement).click();
setTimeout(() => {
panel.scrollIntoView({
behavior: 'smooth',
block: 'nearest',
inline: 'nearest'
});
}, 100);
}
}

displayError(error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { Store, select } from '@ngrx/store';
import { Subject, combineLatest } from 'rxjs';
import { select, Store } from '@ngrx/store';
import { combineLatest, Subject } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators';
import { AddCertificate, RemoveCertificate, SetCertificateUsed, SetCertificates, SetPointsUsed } from 'src/app/store/actions/order.actions';
import { AddCertificate, RemoveCertificate, SetCertificates, SetCertificateUsed, SetPointsUsed } from 'src/app/store/actions/order.actions';
import { GetUserBonuses } from 'src/app/store/actions/ubs-user.actions';
import { certificatesSelector, isFirstFormValidSelector, orderSumSelector } from 'src/app/store/selectors/order.selectors';
import { userBonusesSelector } from 'src/app/store/selectors/ubs-user.selectors';
import { ICertificateResponse } from 'src/app/ubs/ubs/models/ubs.interface';
import { CCertificate } from 'src/app/ubs/ubs/models/ubs.model';
import { Masks, Patterns } from 'src/assets/patterns/patterns';
import { OrderService } from '../../../services/order.service';
import { ICertificate, IUserOrderInfo } from '@ubs/ubs-user/components/ubs-user-orders-list/models/UserOrder.interface';

@Component({
selector: 'app-ubs-order-certificate',
Expand All @@ -29,6 +30,17 @@ export class UbsOrderCertificateComponent implements OnInit, OnDestroy {
certificatePattern = Patterns.serteficatePattern;
private $destroy: Subject<void> = new Subject<void>();

@Input()
set orderDetails(value: IUserOrderInfo) {
if (value?.certificate?.length) {
value.certificate.forEach((c: ICertificate, index) => {
this.addNewCertificate();
this.formArrayCertificates.controls.at(index).setValue(c.code);
this.onActivateCertififcate(index);
});
}
}

get bonus() {
return this.orderBonusesForm?.controls.bonus;
}
Expand All @@ -53,7 +65,7 @@ export class UbsOrderCertificateComponent implements OnInit, OnDestroy {

ngOnInit(): void {
this.store.dispatch(GetUserBonuses());

console.log(this.orderDetails);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the debug console.log statement.

The console.log statement appears to be debug code left in by mistake. It should be removed before merging.

Apply this diff:

   ngOnInit(): void {
     this.store.dispatch(GetUserBonuses());
-    console.log(this.orderDetails);
     this.initForm();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log(this.orderDetails);
ngOnInit(): void {
this.store.dispatch(GetUserBonuses());
this.initForm();
🤖 Prompt for AI Agents
In
src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts
around line 68, remove the debug console.log(this.orderDetails); statement;
delete that line (or replace with an appropriate structured logger call if
needed) and ensure no trailing whitespace remains and tests/linter pass.

this.initForm();
this.initListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h5 *ngIf="!currentLocation" class="error-text">{{ 'order-details.title-without-
</div>
</div>
<h5>{{ 'order-details.question-certificate' | translate }}</h5>
<app-ubs-order-certificate></app-ubs-order-certificate>
<app-ubs-order-certificate [orderDetails]="existingOrderInfo"></app-ubs-order-certificate>
</div>
</div>
<div class="bottom">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ export class UBSOrderDetailsComponent extends FormBaseComponent implements OnIni
this.initListeners();
});

this.store.pipe(select(existingOrderInfoSelector), takeUntil(this.$destroy)).subscribe((orderInfo: IUserOrderInfo) => {
this.store.pipe(select(existingOrderInfoSelector), filter(Boolean), takeUntil(this.$destroy)).subscribe((orderInfo: IUserOrderInfo) => {
this.existingOrderInfo = orderInfo;
if (this.orderDetailsForm) {
this.initExistingOrderValues();
}
this.initExistingOrderValues();
});
}

Expand All @@ -205,6 +203,7 @@ export class UBSOrderDetailsComponent extends FormBaseComponent implements OnIni
.subscribe(([locations, orderDetails]: [CourierLocations, OrderDetails]) => {
if (!this.bags || this.bags[0]?.id !== orderDetails.bags[0].id) {
this.locations = locations;
console.error(orderDetails);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove the debug console.error statement.

The console.error statement appears to be debug code left in by mistake. It should be removed before merging.

Apply this diff:

         if (!this.bags || this.bags[0]?.id !== orderDetails.bags[0].id) {
           this.locations = locations;
-          console.error(orderDetails);
           this.bags = orderDetails.bags;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.error(orderDetails);
if (!this.bags || this.bags[0]?.id !== orderDetails.bags[0].id) {
this.locations = locations;
this.bags = orderDetails.bags;
🤖 Prompt for AI Agents
In src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts
around line 206, remove the stray debug statement "console.error(orderDetails)"
— simply delete that line so no debug console logging remains in production
code; ensure no other references rely on it and run lint/tests to confirm no
unused variables are introduced.

this.bags = orderDetails.bags;
this.initFormBags();
this.dispatchAdditionalOrders();
Expand Down Expand Up @@ -294,9 +293,19 @@ export class UBSOrderDetailsComponent extends FormBaseComponent implements OnIni
initExistingOrderValues(): void {
if (this.existingOrderInfo) {
this.orderComment.setValue(this.existingOrderInfo.orderComment);
if (this.existingOrderInfo.bags?.length > 0) {
this.existingOrderInfo.bags.forEach((bag) => {
const bagIndex = this.bags?.findIndex((b) => b.nameEn === bag.serviceEn);
if (bagIndex !== -1) {
this.changeQuantity(this.bags[bagIndex].id, bag.count);
}
});
}
if (this.existingOrderInfo.additionalOrders?.length > 0) {
this.additionalOrders.clear();
this.existingOrderInfo.additionalOrders.forEach((order) => this.addOrder(order));
this.existingOrderInfo.additionalOrders.forEach((order) => {
this.addOrder(order);
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ export class UBSSubmitOrderComponent extends FormBaseComponent implements OnInit
}

processOrder(shouldBePaid: boolean = true): void {
const hasLink = JSON.parse(localStorage.getItem('UBSorderData'))?.hasPaymentLink || false;
this.isLoadingAnim = true;
iif(
() => this.existingOrderId >= 0,
this.orderService.processExistingOrder(this.getOrder(shouldBePaid), this.existingOrderId, hasLink),
this.orderService.processExistingOrder(this.getOrder(shouldBePaid), this.existingOrderId),
this.orderService.processNewOrder(this.getOrder(shouldBePaid))
)
.pipe(
Expand Down
14 changes: 3 additions & 11 deletions src/app/ubs/ubs/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of, Subject, throwError } from 'rxjs';
import { first, map, switchMap } from 'rxjs/operators';
import { map } from 'rxjs/operators';
import { environment } from '@environment/environment';
import { UBSOrderFormService } from './ubs-order-form.service';
import { OrderClientDto } from '@ubs/ubs-user/components/ubs-user-orders-list/models/OrderClientDto';
Expand Down Expand Up @@ -129,16 +129,8 @@ export class OrderService {
return this.http.post<IProcessOrderResponse>(`${this.url}/cancelPaymentAttempt/${id}`, {});
}

processExistingOrder(order: Order, orderId: number, hasLink: boolean = false): Observable<IProcessOrderResponse> {
return of(hasLink).pipe(
switchMap((hasLink) => {
if (hasLink) {
return this.cancelExistingPayment(orderId).pipe(first());
}
return of(null);
}),
switchMap(() => this.http.post<IProcessOrderResponse>(`${this.url}/processOrder/${orderId}`, order))
);
processExistingOrder(order: Order, orderId: number): Observable<IProcessOrderResponse> {
return this.http.post<IProcessOrderResponse>(`${this.url}/processOrder/${orderId}`, order);
}

processCertificate(certificate): Observable<ICertificateResponse> {
Expand Down
Loading