|
1 | 1 | import { ChangeDetectionStrategy, Component } from '@angular/core'; |
2 | | -import { combineLatest } from 'rxjs'; |
| 2 | +import { combineLatest, map, shareReplay } from 'rxjs'; |
3 | 3 |
|
4 | 4 | import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; |
5 | 5 |
|
6 | | -import { InvoiceFacade } from '@console-core/state'; |
| 6 | +import { |
| 7 | + CustomerFacade, |
| 8 | + IamFacade, |
| 9 | + InvoiceFacade, |
| 10 | + ShopFacade, |
| 11 | +} from '@console-core/state'; |
7 | 12 |
|
8 | 13 | import { buildInvoiceSchema } from '../jss-forms'; |
9 | 14 |
|
10 | 15 | @Component({ |
11 | 16 | selector: 'app-module-invoice-create', |
12 | 17 | template: ` |
13 | | - <ng-container *ngIf="vm$ | async as vm"> |
14 | | - <div class="mt-2"> |
15 | | - <rc-crud-create |
16 | | - [schema]="schema" |
17 | | - [create]="create" |
18 | | - /> |
19 | | - </div> |
20 | | - </ng-container> |
| 18 | + @if (vm$ | async; as vm) { |
| 19 | + <div class="mt-2"> |
| 20 | + <rc-crud-create |
| 21 | + [schema]="vm.schema" |
| 22 | + [create]="create" |
| 23 | + /> |
| 24 | + </div> |
| 25 | + } |
21 | 26 | `, |
22 | 27 | changeDetection: ChangeDetectionStrategy.OnPush, |
23 | 28 | standalone: false, |
24 | 29 | }) |
25 | 30 | export class InvoiceCreateComponent { |
26 | | - schema: VCLFormFieldSchemaRoot = buildInvoiceSchema({ |
27 | | - customers: [], |
28 | | - users: [], |
29 | | - shops: [], |
30 | | - }); |
| 31 | + schema!: VCLFormFieldSchemaRoot; |
31 | 32 |
|
32 | 33 | create = this.invoiceFacade.create; |
33 | 34 |
|
34 | 35 | readonly vm$ = combineLatest({ |
35 | | - invoice: this.invoiceFacade.selected$, |
36 | | - }); |
| 36 | + customers: this.customerFacade.all$, |
| 37 | + shops: this.shopFacade.all$, |
| 38 | + users: this.iamFacade.all$, |
| 39 | + }).pipe( |
| 40 | + map(({ customers, shops, users }) => { |
| 41 | + const schema = buildInvoiceSchema({ |
| 42 | + customers, |
| 43 | + shops, |
| 44 | + users, |
| 45 | + }); |
37 | 46 |
|
38 | | - constructor(private readonly invoiceFacade: InvoiceFacade) {} |
| 47 | + return { |
| 48 | + schema, |
| 49 | + }; |
| 50 | + }), |
| 51 | + shareReplay({ bufferSize: 1, refCount: true }) |
| 52 | + ); |
| 53 | + |
| 54 | + constructor( |
| 55 | + private readonly invoiceFacade: InvoiceFacade, |
| 56 | + private readonly shopFacade: ShopFacade, |
| 57 | + private readonly customerFacade: CustomerFacade, |
| 58 | + private readonly iamFacade: IamFacade |
| 59 | + ) {} |
39 | 60 | } |
0 commit comments