From bb2fcd8e69be066ed8aae3672d591e87c355caa5 Mon Sep 17 00:00:00 2001 From: Bello Babakolo Date: Thu, 29 Aug 2024 12:40:19 +0100 Subject: [PATCH] feat: replace add order item jss with normal forms --- .../order-item-form.component.html | 84 +++++++++++++++++++ .../order-items/order-item-form.component.ts | 35 ++++---- .../order-items/order-item.schema.ts | 20 ++++- .../order-items/order-items.component.ts | 5 +- 4 files changed, 120 insertions(+), 24 deletions(-) create mode 100644 packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.html diff --git a/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.html b/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.html new file mode 100644 index 00000000..bb1ba976 --- /dev/null +++ b/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.html @@ -0,0 +1,84 @@ + + Add item + +
+ + Select a product + + +
No Product found!
+
+ + @for (product of products; track product.id) { + {{ + product.product.name + }} + } + +
+
+ + + Select a variant + + +
No Variant found!
+
+ + @for (variant of variants; track variant.id) { + {{ + variant.name + }} + } + +
+
+ + + Quantity + + + + + +
+ + Select currency + + + France + + Germany + + UK + + + + + + Regular price + + + + + + Sale + + + Sale price + + + + +
+
+
diff --git a/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.ts b/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.ts index 67133436..c547ce82 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.ts +++ b/packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.ts @@ -2,31 +2,30 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; import { ComponentLayerRef } from '@vcl/ng-vcl'; +import { IoRestorecommerceProductPhysicalVariant } from '@console-core/graphql'; +import { IProduct } from '@console-core/types'; + @Component({ selector: 'rc-order-item-form', - template: ` - - Add item - - - `, + templateUrl: './order-item-form.component.html', changeDetection: ChangeDetectionStrategy.OnPush, }) export class RcOrderItemFormComponent { + selectedProduct = ''; + selectedVariant = ''; + variants: IoRestorecommerceProductPhysicalVariant[] = []; + constructor(private layer: ComponentLayerRef) {} - get schema() { - return this.layer.data.schema; + get products(): IProduct[] { + return this.layer.data.products; + } + + onSelectProduct(id: string) { + this.selectedProduct = id; + this.selectedVariant = ''; + this.variants = + this.products.find((p) => p.id === id)?.product.physical?.variants || []; } onAction(_: string): void { diff --git a/packages/modules/ui/src/lib/components/molecules/order-items/order-item.schema.ts b/packages/modules/ui/src/lib/components/molecules/order-items/order-item.schema.ts index 9d203d48..6ace3ee5 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-items/order-item.schema.ts +++ b/packages/modules/ui/src/lib/components/molecules/order-items/order-item.schema.ts @@ -1,6 +1,6 @@ import { Validators } from '@angular/forms'; -import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; +import { conditional, VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; import { IProduct } from '@console-core/types'; @@ -20,7 +20,7 @@ export const buildOrderItemSchema = ( type: 'select', validators: [Validators.required], params: { - placeholder: 'Select an items', + placeholder: 'Select an item', search: true, options: options.products.map((product) => ({ value: product.id, @@ -28,6 +28,22 @@ export const buildOrderItemSchema = ( })), }, }, + { + name: 'variantId', + label: 'Item variants', + type: 'select', + validators: [Validators.required], + params: { + placeholder: 'Select a variant', + // search: true, + options: (() => { + const x = conditional(['productId'], (enabled) => !!enabled.value); + console.log('xxx', x); + return [{ value: 'ex', label: 'ddd' }]; + })(), + }, + visible: conditional(['productId'], (enabled) => !!enabled.value), + }, { type: 'buttons', buttons: [ 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 63b42f1c..0e241e1a 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 @@ -12,7 +12,6 @@ import { IoRestorecommerceOrderItem } from '@console-core/graphql'; import { IProduct } from '@console-core/types'; import { RcOrderItemFormComponent } from './order-item-form.component'; -import { buildOrderItemSchema } from './order-item.schema'; @Component({ selector: 'rc-order-items', @@ -45,9 +44,7 @@ export class RcOrderItemsComponent implements OnInit, OnDestroy { this.addItemLayer .open({ data: { - schema: buildOrderItemSchema({ - products: this.products, - }), + products: this.products, }, }) .subscribe((result) => {