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 b2e949ab..5564cc33 100644 --- a/packages/modules/order/src/lib/components/order-view.component.ts +++ b/packages/modules/order/src/lib/components/order-view.component.ts @@ -19,6 +19,8 @@ import { } from '@console-core/state'; import { IOrder, IProduct } from '@console-core/types'; +import { buildOrderAddressSchema } from '../jss-forms'; +import { JSSFormModalComponent } from '../modals/jss-form-modal.component'; import { OrderItemFormComponent } from '../modals/order-item/order-item-form.component'; @Component({ @@ -28,6 +30,7 @@ import { OrderItemFormComponent } from '../modals/order-item/order-item-form.com `, @@ -58,6 +61,7 @@ export class OrderViewComponent implements OnInit, OnDestroy { }); addItemLayer!: LayerRef; + addressLayer!: LayerRef; constructor( private readonly router: Router, @@ -72,10 +76,16 @@ export class OrderViewComponent implements OnInit, OnDestroy { closeOnBackdropClick: false, closeOnEscape: false, }); + + this.addressLayer = this.layerService.create(JSSFormModalComponent, { + closeOnBackdropClick: false, + closeOnEscape: false, + }); } ngOnDestroy() { this.addItemLayer?.destroy(); + this.addressLayer?.destroy(); } onAddOrder(order: IOrder, products: IProduct[]) { @@ -90,4 +100,18 @@ export class OrderViewComponent implements OnInit, OnDestroy { console.log('Result: ' + result?.value); }); } + + onOpenAddress(order: IOrder) { + this.addressLayer + .open({ + data: { + order, + title: 'Address', + schema: buildOrderAddressSchema({}), + }, + }) + .subscribe((result) => { + console.log('Result: ' + result?.value); + }); + } } diff --git a/packages/modules/order/src/lib/jss-forms/index.ts b/packages/modules/order/src/lib/jss-forms/index.ts index c8863ade..f03c39f7 100644 --- a/packages/modules/order/src/lib/jss-forms/index.ts +++ b/packages/modules/order/src/lib/jss-forms/index.ts @@ -1 +1,2 @@ export * from './order.jss-form'; +export * from './order-address-jss-form'; diff --git a/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts b/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts new file mode 100644 index 00000000..be805790 --- /dev/null +++ b/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts @@ -0,0 +1,221 @@ +// import { Validators } from '@angular/forms'; + +import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; + +interface ISchemaOptions { + item1?: string; // Optional data that can be anything. +} + +export const buildOrderAddressSchema = ( + _: ISchemaOptions +): VCLFormFieldSchemaRoot => { + return { + type: 'form', + fields: [ + { + name: 'buildingNumber', + label: 'Building number', + type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.name || '', + params: {}, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + { + name: 'street', + label: 'Street', + type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.name || '', + params: {}, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + { + name: 'locality', + label: 'Locality', + type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.name || '', + params: {}, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + { + name: 'region', + label: 'Region', + type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.name || '', + params: {}, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + { + name: 'postcode', + label: 'Postcode', + type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.name || '', + params: {}, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + { + name: 'countryId', + label: 'Country', + type: 'select', + // defaultValue: options?.product?.taxIds || [], + // validators: [Validators.required], + params: { + placeholder: 'Country', + options: [ + { + label: 'Germany', + value: 'germany', + }, + { + label: 'Switzerland', + value: 'switzerland', + }, + { + label: 'France', + value: 'france', + }, + ], + }, + hints: [ + { + type: 'error', + error: 'required', + message: 'This field is required.', + }, + ], + }, + // Object references **** + // { + // name: 'price', + // type: 'object', + // fields: [ + // { + // name: 'currencyId', + // label: 'Currency', + // type: 'select', + // // disabled: true, + // defaultValue: options?.product?.price?.currencyId || '', + // validators: [Validators.required], + // params: { + // placeholder: 'Select currency', + // selectionMode: 'single', + // clearable: false, + // search: false, + // options: [ + // { + // label: 'USD', + // value: 'USD', + // }, + // { + // label: 'EURO', + // value: 'EUR', + // }, + // ], + // }, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // ], + // }, + // { + // name: 'regularPrice', + // label: 'Regular price', + // type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.price?.regularPrice || '', + // params: { + // inputType: 'number', + // }, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // { + // type: 'error', + // error: 'min', + // message: '', + // }, + // ], + // }, + // { + // name: 'salePrice', + // label: 'Sale price', + // type: 'input', + // validators: [Validators.required], + // defaultValue: options?.product?.price?.salePrice || '', + // params: { + // inputType: 'number', + // }, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // ], + // }, + // { + // type: 'checkbox', + // defaultValue: options?.product?.price?.sale || false, + // name: 'sale', + // label: 'On sales', + // }, + // ], + // }, + { + type: 'buttons', + buttons: [ + { + type: 'button', + label: 'Cancel', + action: 'reset', + class: 'transparent', + }, + { + type: 'submit', + label: 'Save', + }, + ], + }, + ], + }; +}; diff --git a/packages/modules/order/src/lib/modals/jss-form-modal.component.ts b/packages/modules/order/src/lib/modals/jss-form-modal.component.ts new file mode 100644 index 00000000..ef073394 --- /dev/null +++ b/packages/modules/order/src/lib/modals/jss-form-modal.component.ts @@ -0,0 +1,63 @@ +import { ChangeDetectionStrategy, Component } from '@angular/core'; + +import { ComponentLayerRef, VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; + +// import { IIoRestorecommerceOrderOrder, ModeType } from '@console-core/graphql'; +import { OrderFacade } from '@console-core/state'; +import { IOrder } from '@console-core/types'; + +// import { transformOrderToInput } from '../../utils'; + +@Component({ + selector: 'app-order-item-form', + template: ` + + {{ title }} + + + + + `, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class JSSFormModalComponent { + constructor( + private layer: ComponentLayerRef, + private readonly orderFacade: OrderFacade + ) {} + + get title(): string { + return this.layer.data.title; + } + + get order(): IOrder { + return this.layer.data.order; + } + + get schema(): VCLFormFieldSchemaRoot { + return this.layer.data.schema; + } + + onSubmit(): void { + // TODO + } + + onAction(_: string): void { + // TODO + } + + close(value?: string) { + this.layer.close({ + value, + }); + } +} diff --git a/packages/modules/order/src/lib/modules-order.module.ts b/packages/modules/order/src/lib/modules-order.module.ts index 0a176114..5b05e7ad 100644 --- a/packages/modules/order/src/lib/modules-order.module.ts +++ b/packages/modules/order/src/lib/modules-order.module.ts @@ -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 { JSSFormModalComponent } from './modals/jss-form-modal.component'; import { OrderItemFormComponent } from './modals/order-item/order-item-form.component'; @NgModule({ @@ -19,6 +20,7 @@ import { OrderItemFormComponent } from './modals/order-item/order-item-form.comp OrderEditComponent, OrderViewComponent, OrderItemFormComponent, + JSSFormModalComponent, ], imports: [ ModulesUiModule.forChild(), diff --git a/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html b/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html index f343792a..7054b474 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html +++ b/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html @@ -1,6 +1,8 @@
{{ title }}
+ + @if (rcOrderAddress) { + } @else { + + }
-