-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add schema for creating order item
- Loading branch information
Showing
8 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/modules/ui/src/lib/components/molecules/order-items/order-item-form.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
|
||
import { ComponentLayerRef } from '@vcl/ng-vcl'; | ||
|
||
@Component({ | ||
selector: 'rc-order-item-form', | ||
template: ` | ||
<vcl-panel-dialog | ||
[showCloseButton]="true" | ||
(close)="close()" | ||
> | ||
<vcl-panel-title>Add item</vcl-panel-title> | ||
<vcl-jss-form | ||
autocomplete="off" | ||
ngDefaultControl | ||
#createForm="vclJssForm" | ||
[schema]="schema" | ||
(formAction)="onAction($event)" | ||
(formSubmit)="onSubmit()" | ||
/> | ||
</vcl-panel-dialog> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RcOrderItemFormComponent { | ||
constructor(private layer: ComponentLayerRef) {} | ||
|
||
get schema() { | ||
return this.layer.data.schema; | ||
} | ||
|
||
onAction(_: string): void { | ||
// TODO | ||
} | ||
|
||
onSubmit(): void { | ||
// TODO | ||
} | ||
|
||
close(value?: string) { | ||
this.layer.close({ | ||
value, | ||
}); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/modules/ui/src/lib/components/molecules/order-items/order-item.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Validators } from '@angular/forms'; | ||
|
||
import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; | ||
|
||
import { IOrder } from '@console-core/types'; | ||
|
||
interface ISchemaOptions { | ||
order?: IOrder; | ||
} | ||
|
||
export const buildOrderItemSchema = ( | ||
_: ISchemaOptions | ||
): VCLFormFieldSchemaRoot => { | ||
return { | ||
type: 'form', | ||
fields: [ | ||
{ | ||
name: 'productId', | ||
label: 'Items', | ||
type: 'select', | ||
validators: [Validators.required], | ||
params: { | ||
placeholder: 'Select an items', | ||
options: [ | ||
{ | ||
label: 'Item 1', | ||
value: 'item #1', | ||
}, | ||
{ | ||
label: 'Item 2', | ||
value: 'item #2', | ||
}, | ||
{ | ||
label: 'Item 3', | ||
value: 'item #3', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
type: 'buttons', | ||
buttons: [ | ||
{ | ||
type: 'button', | ||
label: 'Cancel', | ||
action: 'reset', | ||
class: 'transparent', | ||
}, | ||
{ | ||
type: 'submit', | ||
label: 'Save', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}; |
16 changes: 15 additions & 1 deletion
16
packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 40 additions & 2 deletions
42
packages/modules/ui/src/lib/components/molecules/order-items/order-items.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
Input, | ||
OnDestroy, | ||
OnInit, | ||
} from '@angular/core'; | ||
|
||
import { LayerRef, LayerService } from '@vcl/ng-vcl'; | ||
|
||
import { IoRestorecommerceOrderItem } from '@console-core/graphql'; | ||
|
||
import { RcOrderItemFormComponent } from './order-item-form.component'; | ||
import { buildOrderItemSchema } from './order-item.schema'; | ||
|
||
@Component({ | ||
selector: 'rc-order-items', | ||
templateUrl: './order-items.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RcOrderItemsComponent { | ||
export class RcOrderItemsComponent implements OnInit, OnDestroy { | ||
@Input({ required: true }) | ||
items: IoRestorecommerceOrderItem[] = []; | ||
|
||
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: { | ||
schema: buildOrderItemSchema({}), | ||
}, | ||
}) | ||
.subscribe((result) => { | ||
console.log('Result: ' + result?.value); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters