Skip to content

Conversation

witolDark
Copy link
Contributor

@witolDark witolDark commented Oct 10, 2025

Summary by CodeRabbit

  • New Features
    • Auto-populates and activates certificates when editing an existing order.
    • Restores existing bag quantities in the order form.
  • Improvements
    • Smoother post-load behavior: auto-opening relevant orders and improved scrolling/visibility.
    • More reliable loading of existing order info and redirection flow.
    • Handles existing-payment scenarios by attempting cancellation before redirect; shows an error message if cancellation fails.
  • Bug Fixes
    • Reduced timing issues during scroll/init after view render.
    • Prevents premature redirects when a prior payment link exists.

@witolDark witolDark added this to the UI S61.7 milestone Oct 10, 2025
@witolDark witolDark self-assigned this Oct 10, 2025
@witolDark witolDark added bug Something isn't working UI labels Oct 10, 2025
@witolDark witolDark changed the title fixed editing existing order, fixed scroll to existing order Bugfix/fixed editing existing order, fixed scroll to existing order Oct 10, 2025
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Updates adjust order processing and UI flows: introduce conditional payment-cancel-before-redirect in user orders list, add AfterViewInit with requestAnimationFrame scrolling in user orders, integrate existing order details into certificate component with auto-population, map existing bags into forms, and simplify existing-order processing API by removing hasLink logic.

Changes

Cohort / File(s) Summary of Changes
User orders list: conditional cancel & redirect
src/app/ubs/ubs-user/components/ubs-user-orders-list/ubs-user-orders-list.component.ts
Import take; inject MatSnackBarService; remove hasPaymentLink from local storage model; after persisting data, if orderDetails.hasPaymentLink, call orderService.cancelExistingPayment(...).take(1) then redirect or show snack on error; otherwise redirect immediately; update set/get local storage flows accordingly.
User orders: lifecycle and scrolling updates
src/app/ubs/ubs-user/components/ubs-user-orders/ubs-user-orders.component.ts
Implement AfterViewInit; add ngAfterViewInit; replace setTimeout with requestAnimationFrame for scroll actions; click header before scrolling; initialize potential extended order and fetch active couriers post-view init.
Order details & certificate integration
src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts, src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.html, src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts
Add input setter orderDetails to auto-populate/activate certificates from IUserOrderInfo; log payload on init. Pass [orderDetails]="existingOrderInfo" from parent template. In parent TS: filter truthy existingOrderInfo, store it, always call initExistingOrderValues; on bag changes, log and reinit bag controls; map existing bags to current controls via serviceEn/nameEn and update quantities.
Order processing API simplification
src/app/ubs/ubs/components/ubs-submit-order/ubs-submit-order.component.ts, src/app/ubs/ubs/services/order.service.ts
Remove hasLink path: processExistingOrder signature changes to (order, id); call sites updated; service now always POSTs processOrder for orderId; remove conditional cancel logic and related RxJS operators (keep map).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant OrdersList as UbsUserOrdersListComponent
  participant OrderSvc as OrderService
  participant Router as Router
  participant Snack as MatSnackBarService

  User->>OrdersList: Trigger "Continue order"
  OrdersList->>OrdersList: Persist orderDetails to localStorage
  alt hasPaymentLink is truthy
    OrdersList->>OrderSvc: cancelExistingPayment(orderId)
    OrderSvc-->>OrdersList: success
    OrdersList->>Router: navigate to submit order
  else
    OrdersList->>Router: navigate to submit order
  end
  opt cancelExistingPayment fails
    OrderSvc-->>OrdersList: error
    OrdersList->>Snack: open("Cancellation failed", ...)
  end
Loading
sequenceDiagram
  autonumber
  participant Parent as UbsOrderDetailsComponent
  participant Cert as UbsOrderCertificateComponent

  Parent-->>Parent: existingOrderInfo (truthy)
  Parent->>Cert: [orderDetails]=existingOrderInfo
  alt orderDetails.certificate has entries
    loop for each certificate
      Cert->>Cert: addNewCertificate()
      Cert->>Cert: set form code
      Cert->>Cert: onActivateCertififcate(i)
    end
  end
Loading
sequenceDiagram
  autonumber
  participant Submit as UBSSubmitOrderComponent
  participant OrderSvc as OrderService
  participant Backend as API

  Submit->>Submit: if existingOrderId >= 0
  alt Existing order
    Submit->>OrderSvc: processExistingOrder(order, id)
    OrderSvc->>Backend: POST /processOrder/{id}
    Backend-->>OrderSvc: IProcessOrderResponse
    OrderSvc-->>Submit: response
  else New order
    Submit->>OrderSvc: processNewOrder(order)
    OrderSvc->>Backend: POST /processOrder
    Backend-->>OrderSvc: response
    OrderSvc-->>Submit: response
  end
  Submit-->>Submit: continue existing redirect flow
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I thump my paws at tidy code,
Cancel links, then hit the road.
Bags align and certs awake—
AfterViewInit, no more wait!
Requests hop straight, no extra link,
A carrot snack for every sync. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly communicates the two primary fixes—editing existing orders and scroll behavior—which align with the pull request’s objectives, even though it uses a “Bugfix/” prefix and repeats “fixed” redundantly. It concisely captures the main changes without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Spelina/editing-order-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/app/ubs/ubs-user/components/ubs-user-orders-list/ubs-user-orders-list.component.ts (1)

239-252: Consider removing the console.error statement.

The conditional cancellation flow correctly handles the payment link scenario by canceling the existing payment before redirecting. However, the error handler includes a console.error statement on line 246 which should be removed or replaced with proper logging in production code.

Apply this diff to remove the console.error:

         .subscribe({
           next: () => this.redirectToStepOne(),
           error: () => {
-            console.error('Error canceling existing order with ID: ', this.orderId);
             this.snackBarService.openSnackBar('error');
           }
         });
src/app/ubs/ubs-user/components/ubs-user-orders/ubs-user-orders.component.ts (1)

218-234: Consider eliminating the nested setTimeout.

The scroll implementation has been improved by using requestAnimationFrame and clicking the panel header before scrolling. However, there's a nested setTimeout (line 227) that might be unnecessary now that you're using requestAnimationFrame.

Consider this refactor to potentially eliminate the nested timeout:

   isPresent.extend = true;
-  requestAnimationFrame(() => this.scroll(this.orderIdToScroll));
+  requestAnimationFrame(() => {
+    const ord: string = this.orderIdToScroll.toString();
+    const element = document.getElementById(ord);
+    if (element) {
+      const panel = element.closest('mat-expansion-panel');
+      (panel.querySelector('mat-expansion-panel-header') as HTMLElement).click();
+      requestAnimationFrame(() => {
+        panel.scrollIntoView({
+          behavior: 'smooth',
+          block: 'nearest',
+          inline: 'nearest'
+        });
+      });
+    }
+  });
 }

 scroll(orderId: number): void {
-  const ord: string = orderId.toString();
-  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);
-  }
+  // This method could potentially be removed if the above refactor is applied
 }

This uses a second requestAnimationFrame instead of setTimeout, which is more performant and ensures the scroll happens after the panel expansion animation begins. However, if the current implementation works well, you can keep it as is.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b82f17 and 3de475d.

📒 Files selected for processing (7)
  • src/app/ubs/ubs-user/components/ubs-user-orders-list/ubs-user-orders-list.component.ts (5 hunks)
  • src/app/ubs/ubs-user/components/ubs-user-orders/ubs-user-orders.component.ts (4 hunks)
  • src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts (3 hunks)
  • src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.html (1 hunks)
  • src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts (3 hunks)
  • src/app/ubs/ubs/components/ubs-submit-order/ubs-submit-order.component.ts (1 hunks)
  • src/app/ubs/ubs/services/order.service.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-01T22:32:58.734Z
Learnt from: AndrewKozovyi
PR: ita-social-projects/GreenCityClient#3770
File: src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.ts:103-110
Timestamp: 2025-08-01T22:32:58.734Z
Learning: In UbsAdminCustomersComponent (src/app/ubs/ubs-admin/components/ubs-admin-customers/ubs-admin-customers.component.ts), using take(1) instead of takeUntilDestroyed(this.destroyRef) for the adminTableOfCustomersSelector$ subscription prevents excessive additional functionality from being triggered and works correctly for the component's initialization sequence.

Applied to files:

  • src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts
  • src/app/ubs/ubs-user/components/ubs-user-orders/ubs-user-orders.component.ts
🧬 Code graph analysis (3)
src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts (2)
src/app/ubs/ubs-user/components/ubs-user-orders-list/models/UserOrder.interface.ts (1)
  • IUserOrderInfo (1-23)
src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts (1)
  • orderDetails (34-42)
src/app/ubs/ubs/services/order.service.ts (1)
src/app/ubs/ubs/models/ubs.interface.ts (2)
  • Order (18-29)
  • IProcessOrderResponse (51-54)
src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts (1)
src/app/ubs/ubs-user/components/ubs-user-orders-list/models/UserOrder.interface.ts (1)
  • IUserOrderInfo (1-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (18.x)
🔇 Additional comments (7)
src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.html (1)

93-93: LGTM!

The input binding correctly passes existingOrderInfo to the certificate component, enabling auto-population of certificate data when editing existing orders.

src/app/ubs/ubs/components/ubs-submit-order/ubs-submit-order.component.ts (1)

119-119: LGTM!

The removal of the hasLink parameter aligns with the simplified API in OrderService.processExistingOrder. The payment cancellation logic has been appropriately moved to ubs-user-orders-list.component.ts where it's handled before redirecting to edit an order.

src/app/ubs/ubs/services/order.service.ts (2)

20-20: LGTM!

Removing unused RxJS operators (first, switchMap) improves code cleanliness.


132-133: LGTM!

The simplified signature improves the API by removing the hasLink parameter and related conditional cancellation logic. The method now has a single responsibility: processing the order. The payment cancellation logic has been appropriately moved to the caller in ubs-user-orders-list.component.ts.

src/app/ubs/ubs/components/ubs-order-details/ubs-order-details.component.ts (1)

296-303: LGTM!

The bag mapping logic correctly finds matching bags by nameEn and updates quantities using changeQuantity. The updated formatting with explicit braces improves readability.

src/app/ubs/ubs/components/ubs-order-details/ubs-order-certificate/ubs-order-certificate.component.ts (1)

33-42: LGTM!

The input setter correctly auto-populates certificate entries from existing order data. The implementation properly:

  • Checks for certificate array existence and length
  • Adds new certificate controls
  • Sets values from existing data
  • Activates each certificate
src/app/ubs/ubs-user/components/ubs-user-orders/ubs-user-orders.component.ts (1)

164-171: LGTM!

Moving the scroll-to-order and active couriers initialization to ngAfterViewInit is correct, as these operations depend on the DOM being ready. This ensures the order element exists before attempting to scroll to it.

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.

.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant