From 994352aabfd678983c20dfa14cb415a2faac9844 Mon Sep 17 00:00:00 2001 From: Bello Babakolo Date: Sat, 31 Aug 2024 19:50:57 +0100 Subject: [PATCH] feat: add edit context action to the Order item --- .../lib/components/order-view.component.ts | 24 ++++++++++++++ .../order-items/order-item.component.html | 8 ++--- .../order-items/order-item.component.ts | 13 +++++++- .../order-items/order-items.component.html | 33 ++++--------------- .../order-items/order-items.component.ts | 2 ++ .../organisms/order/order-view.component.html | 1 + .../organisms/order/order-view.component.ts | 3 ++ 7 files changed, 51 insertions(+), 33 deletions(-) diff --git a/packages/modules/order/src/lib/components/order-view.component.ts b/packages/modules/order/src/lib/components/order-view.component.ts index 5564cc33..fad23e99 100644 --- a/packages/modules/order/src/lib/components/order-view.component.ts +++ b/packages/modules/order/src/lib/components/order-view.component.ts @@ -11,6 +11,7 @@ import { map, tap } from 'rxjs/operators'; import { LayerRef, LayerService } from '@vcl/ng-vcl'; import { ROUTER } from '@console-core/config'; +import { IoRestorecommerceOrderItem } from '@console-core/graphql'; import { OrderFacade, ProductFacade, @@ -31,6 +32,7 @@ import { OrderItemFormComponent } from '../modals/order-item/order-item-form.com [order]="vm.order" (openAddItemModal)="onAddOrder(vm.order, vm.products)" (openAddressModal)="onOpenAddress(vm.order)" + (openEditOrderItemModal)="onOpenEditOrderItem($event)" /> `, @@ -60,8 +62,11 @@ export class OrderViewComponent implements OnInit, OnDestroy { products: this.productFacade.all$, }); + // TODO REFACTOR the openAddItemModal to openAddOrderItemModal. + addItemLayer!: LayerRef; addressLayer!: LayerRef; + editItemLayer!: LayerRef; constructor( private readonly router: Router, @@ -81,6 +86,11 @@ export class OrderViewComponent implements OnInit, OnDestroy { closeOnBackdropClick: false, closeOnEscape: false, }); + + this.editItemLayer = this.layerService.create(OrderItemFormComponent, { + closeOnBackdropClick: false, + closeOnEscape: false, + }); } ngOnDestroy() { @@ -114,4 +124,18 @@ export class OrderViewComponent implements OnInit, OnDestroy { console.log('Result: ' + result?.value); }); } + + onOpenEditOrderItem(orderItem: IoRestorecommerceOrderItem) { + console.log(orderItem); + this.editItemLayer + .open({ + data: { + // order, + // products, + }, + }) + .subscribe((result) => { + console.log('Result: ' + result?.value); + }); + } } diff --git a/packages/modules/ui/src/lib/components/molecules/order-items/order-item.component.html b/packages/modules/ui/src/lib/components/molecules/order-items/order-item.component.html index 63bb5a2f..afac9ffc 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-items/order-item.component.html +++ b/packages/modules/ui/src/lib/components/molecules/order-items/order-item.component.html @@ -1,7 +1,5 @@ -
-
-

{{ item.product?.product?.name }}

-
+
+

{{ item.product?.product?.name }}

-
-
-
-

{{ item.product?.product?.name }}

-
-
- [Qty: {{ item.quantity }}] -
-
- - -

- Price: {{ item.unitPrice?.currency || 'EUR' }} - {{ item.unitPrice?.regularPrice }} -

-
+ @for (item of items; track item.id) { + + }
diff --git a/packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.ts b/packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.ts index 3de01541..3a9ca614 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.ts +++ b/packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.ts @@ -18,4 +18,6 @@ export class RcOrderItemsComponent { items: IoRestorecommerceOrderItem[] = []; @Output() openAddItemModal = new EventEmitter(); + @Output() openEditOrderItemModal = + new EventEmitter(); } diff --git a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html index bbbecbc0..000c2253 100644 --- a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html +++ b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.html @@ -11,6 +11,7 @@
diff --git a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.ts b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.ts index 847db094..26295592 100644 --- a/packages/modules/ui/src/lib/components/organisms/order/order-view.component.ts +++ b/packages/modules/ui/src/lib/components/organisms/order/order-view.component.ts @@ -8,6 +8,7 @@ import { } from '@angular/core'; import { + IoRestorecommerceOrderItem, IoRestorecommerceProductPhysicalVariant, IoRestorecommerceUserUser, } from '@console-core/graphql'; @@ -23,6 +24,8 @@ export class RcOrderViewComponent implements OnInit { @Output() openAddItemModal = new EventEmitter(); @Output() openAddressModal = new EventEmitter(); + @Output() openEditOrderItemModal = + new EventEmitter(); product?: IoRestorecommerceProductPhysicalVariant | null; customer?: IoRestorecommerceUserUser | null;