Skip to content

Commit

Permalink
chore: refactor order item creation modal
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Aug 29, 2024
1 parent 4735166 commit 74d1c75
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 121 deletions.
43 changes: 39 additions & 4 deletions packages/modules/order/src/lib/components/order-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
OnDestroy,
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
import { combineLatest } from 'rxjs';
import { map, tap } from 'rxjs/operators';

import { LayerRef, LayerService } from '@vcl/ng-vcl';

import { ROUTER } from '@console-core/config';
import {
OrderFacade,
Expand All @@ -11,19 +18,21 @@ import {
filterEmptyAndNullishAndUndefined,
} from '@console-core/state';

import { OrderItemFormComponent } from '../modals/order-item/order-item-form.component';

@Component({
selector: 'app-module-order-view',
template: `
<ng-container *ngIf="vm$ | async as vm">
<rc-order-view
[order]="vm.order"
[products]="vm.products"
(openAddItemModal)="onAddOrder()"
/>
</ng-container>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OrderViewComponent {
export class OrderViewComponent implements OnInit, OnDestroy {
readonly vm$ = combineLatest({
id: this.routerFacade.params$.pipe(
map(({ id }) => id),
Expand All @@ -47,10 +56,36 @@ export class OrderViewComponent {
products: this.productFacade.all$,
});

addItemLayer!: LayerRef;

constructor(
private readonly router: Router,
private readonly routerFacade: RouterFacade,
private readonly productFacade: ProductFacade,
private readonly orderFacade: OrderFacade
private readonly orderFacade: OrderFacade,
private layerService: LayerService
) {}

ngOnInit(): void {
this.addItemLayer = this.layerService.create(OrderItemFormComponent, {
closeOnBackdropClick: false,
closeOnEscape: false,
});
}

ngOnDestroy() {
this.addItemLayer?.destroy();
}

onAddOrder() {
this.addItemLayer
.open({
data: {
products: [], //this.products,
},
})
.subscribe((result) => {
console.log('Result: ' + result?.value);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<vcl-panel-title>Add item</vcl-panel-title>

<form
vclForm
[formGroup]="formGroup"
action=""
(submit)="onSubmit()"
>
<vcl-form-control-group>
<vcl-label>Select a product</vcl-label>
Expand Down Expand Up @@ -89,5 +90,22 @@
</vcl-input-field>
</vcl-form-control-group>
</div>

<div class="loose-button-group">
<button
vcl-button
type="submit"
[disabled]="this.formGroup.invalid"
class="emphasized"
>
Submit
</button>
<button
vcl-button
type="button"
>
Reset
</button>
</div>
</form>
</vcl-panel-dialog>
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { IoRestorecommerceProductPhysicalVariant } from '@console-core/graphql';
import { IProduct } from '@console-core/types';

@Component({
selector: 'rc-order-item-form',
selector: 'app-order-item-form',
templateUrl: './order-item-form.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RcOrderItemFormComponent implements OnInit, OnDestroy {
export class OrderItemFormComponent implements OnInit, OnDestroy {
private readonly subscriptions = new SubSink();
variants: IoRestorecommerceProductPhysicalVariant[] = [];

Expand Down Expand Up @@ -75,12 +75,10 @@ export class RcOrderItemFormComponent implements OnInit, OnDestroy {
return this.layer.data.products;
}

onAction(_: string): void {
// TODO
}

onSubmit(): void {
// TODO
if (this.formGroup.valid) {
console.log(this.formGroup.value);
}
}

close(value?: string) {
Expand Down
2 changes: 2 additions & 0 deletions packages/modules/order/src/lib/modules-order.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OrderIndexComponent } from './components/order-index.component';
import { OrderViewComponent } from './components/order-view.component';
import { OrderTemplateComponent } from './components/template/order-template.component';
import { modulesOrderRoutes } from './lib.routes';
import { OrderItemFormComponent } from './modals/order-item/order-item-form.component';

@NgModule({
declarations: [
Expand All @@ -17,6 +18,7 @@ import { modulesOrderRoutes } from './lib.routes';
OrderCreateComponent,
OrderEditComponent,
OrderViewComponent,
OrderItemFormComponent,
],
imports: [
ModulesUiModule.forChild(),
Expand Down
1 change: 0 additions & 1 deletion packages/modules/ui/src/lib/components/molecules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ export * from './product-variants/product-variant.component';
export * from './product-variants/product-variants.component';
export * from './product-variants/product-images.component';
export * from './order-address/order-address.component';
export * from './order-items/order-item-form.component';
export * from './shop-info/shop-info.component';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
vcl-button
square
class="emphasized-transparent"
(click)="openAddOrderItemComponent()"
(click)="openAddItemModal.emit()"
title="Add order item"
>
<vcl-icon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnDestroy,
OnInit,
Output,
} from '@angular/core';

import { LayerRef, LayerService } from '@vcl/ng-vcl';

import { IoRestorecommerceOrderItem } from '@console-core/graphql';
import { IProduct } from '@console-core/types';

import { RcOrderItemFormComponent } from './order-item-form.component';

@Component({
selector: 'rc-order-items',
templateUrl: './order-items.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RcOrderItemsComponent implements OnInit, OnDestroy {
export class RcOrderItemsComponent {
@Input({ required: true })
items: IoRestorecommerceOrderItem[] = [];

@Input({ required: true })
products: IProduct[] = [];

addItemLayer!: LayerRef;

constructor(private layerService: LayerService) {}

ngOnInit(): void {
this.addItemLayer = this.layerService.create(RcOrderItemFormComponent, {
closeOnBackdropClick: false,
closeOnEscape: false,
});
}

ngOnDestroy() {
this.addItemLayer?.destroy();
}

openAddOrderItemComponent() {
this.addItemLayer
.open({
data: {
products: this.products,
},
})
.subscribe((result) => {
console.log('Result: ' + result?.value);
});
}
@Output() openAddItemModal = new EventEmitter<void>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<div class="order-items">
<rc-order-items
[products]="products"
[items]="order.items || []"
(openAddItemModal)="openAddItemModal.emit()"
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnInit,
Output,
} from '@angular/core';

import {
IoRestorecommerceProductPhysicalVariant,
IoRestorecommerceUserUser,
} from '@console-core/graphql';
import { IOrder, IProduct } from '@console-core/types';
import { IOrder } from '@console-core/types';

@Component({
selector: 'rc-order-view',
Expand All @@ -18,7 +20,8 @@ import { IOrder, IProduct } from '@console-core/types';
})
export class RcOrderViewComponent implements OnInit {
@Input({ required: true }) order!: IOrder;
@Input({ required: true }) products!: IProduct[];

@Output() openAddItemModal = new EventEmitter<void>();

product?: IoRestorecommerceProductPhysicalVariant | null;
customer?: IoRestorecommerceUserUser | null;
Expand Down
2 changes: 0 additions & 2 deletions packages/modules/ui/src/lib/modules-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
RcProductVariantComponent,
RcProductVariantsComponent,
RcProductImagesComponent,
RcOrderItemFormComponent,
} from './components/molecules';
import {
RcAppComponent,
Expand Down Expand Up @@ -167,7 +166,6 @@ const molecules = [
RcProductVariantComponent,
RcProductVariantsComponent,
RcProductImagesComponent,
RcOrderItemFormComponent,
];

const organisms = [
Expand Down
5 changes: 4 additions & 1 deletion packages/modules/ui/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"jest.config.ts",
"src/**/*.test.ts"
],
"include": ["src/**/*.ts"]
"include": [
"src/**/*.ts",
"../order/src/lib/modals/order-item/order-item-form.component.ts"
]
}

0 comments on commit 74d1c75

Please sign in to comment.