Skip to content

Commit

Permalink
feat: add order address form modal
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Aug 29, 2024
1 parent 97ef2ae commit 7e71323
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 9 deletions.
24 changes: 24 additions & 0 deletions packages/modules/order/src/lib/components/order-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -28,6 +30,7 @@ import { OrderItemFormComponent } from '../modals/order-item/order-item-form.com
<rc-order-view
[order]="vm.order"
(openAddItemModal)="onAddOrder(vm.order, vm.products)"
(openAddressModal)="onOpenAddress(vm.order)"
/>
</ng-container>
`,
Expand Down Expand Up @@ -58,6 +61,7 @@ export class OrderViewComponent implements OnInit, OnDestroy {
});

addItemLayer!: LayerRef;
addressLayer!: LayerRef;

constructor(
private readonly router: Router,
Expand All @@ -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[]) {
Expand All @@ -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);
});
}
}
1 change: 1 addition & 0 deletions packages/modules/order/src/lib/jss-forms/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './order.jss-form';
export * from './order-address-jss-form';
221 changes: 221 additions & 0 deletions packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
],
};
};
63 changes: 63 additions & 0 deletions packages/modules/order/src/lib/modals/jss-form-modal.component.ts
Original file line number Diff line number Diff line change
@@ -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: `
<vcl-panel-dialog
[showCloseButton]="true"
(close)="close()"
>
<vcl-panel-title>{{ title }}</vcl-panel-title>
<vcl-jss-form
autocomplete="off"
#form="vclJssForm"
[schema]="schema"
(formSubmit)="onSubmit()"
(formAction)="onAction($event)"
>
</vcl-jss-form>
</vcl-panel-dialog>
`,
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,
});
}
}
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 { JSSFormModalComponent } from './modals/jss-form-modal.component';
import { OrderItemFormComponent } from './modals/order-item/order-item-form.component';

@NgModule({
Expand All @@ -19,6 +20,7 @@ import { OrderItemFormComponent } from './modals/order-item/order-item-form.comp
OrderEditComponent,
OrderViewComponent,
OrderItemFormComponent,
JSSFormModalComponent,
],
imports: [
ModulesUiModule.forChild(),
Expand Down
Loading

0 comments on commit 7e71323

Please sign in to comment.