Skip to content

Commit ce301a8

Browse files
committed
feat(invoice): implement UI for invoice creation
1 parent eab7494 commit ce301a8

3 files changed

Lines changed: 48 additions & 25 deletions

File tree

‎packages/core/state/src/lib/+state/invoice/invoice.effects.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
import { ErrorHandlingService, InvoiceService } from '../../services';
2323
import { AppFacade } from '../app';
2424
import * as CustomerActions from '../management/customer/customer.actions';
25+
import * as IamActions from '../management/iam/iam.actions';
2526
import * as ShopActions from '../management/shop/shop.actions';
2627

2728
import * as invoiceActions from './invoice.actions';
@@ -109,14 +110,13 @@ export class InvoiceEffects {
109110
preloadOnEdit$ = createEffect(() => {
110111
return this.actions$.pipe(
111112
ofType(routerNavigationAction),
112-
tap(() => console.log('Here is our edit page router action')),
113113
map((a) => a.payload.routerState?.url as string),
114114
filter(isInvoiceEdit),
115-
tap(() => console.log('Should be ready to load something...')),
116115
// eslint-disable-next-line @ngrx/no-multiple-actions-in-effects
117116
mergeMap(() => [
118117
CustomerActions.customerReadRequest({ payload: {} }),
119118
ShopActions.shopReadRequest({ payload: {} }),
119+
IamActions.userReadRequest({ payload: {} }),
120120
])
121121
);
122122
});
@@ -130,8 +130,7 @@ export class InvoiceEffects {
130130
mergeMap(() => [
131131
CustomerActions.customerReadRequest({ payload: {} }),
132132
ShopActions.shopReadRequest({ payload: {} }),
133-
// data only the create page needs (e.g. default terms, next invoice number, templates)
134-
// InvoiceMetaActions.loadCreationDefaultsIfNeeded(),
133+
IamActions.userReadRequest({ payload: {} }),
135134
])
136135
);
137136
});
Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,60 @@
11
import { ChangeDetectionStrategy, Component } from '@angular/core';
2-
import { combineLatest } from 'rxjs';
2+
import { combineLatest, map, shareReplay } from 'rxjs';
33

44
import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl';
55

6-
import { InvoiceFacade } from '@console-core/state';
6+
import {
7+
CustomerFacade,
8+
IamFacade,
9+
InvoiceFacade,
10+
ShopFacade,
11+
} from '@console-core/state';
712

813
import { buildInvoiceSchema } from '../jss-forms';
914

1015
@Component({
1116
selector: 'app-module-invoice-create',
1217
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+
}
2126
`,
2227
changeDetection: ChangeDetectionStrategy.OnPush,
2328
standalone: false,
2429
})
2530
export class InvoiceCreateComponent {
26-
schema: VCLFormFieldSchemaRoot = buildInvoiceSchema({
27-
customers: [],
28-
users: [],
29-
shops: [],
30-
});
31+
schema!: VCLFormFieldSchemaRoot;
3132

3233
create = this.invoiceFacade.create;
3334

3435
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+
});
3746

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+
) {}
3960
}

‎packages/modules/invoice/src/lib/components/invoice-edit.component.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl';
88
import { ROUTER } from '@console-core/config';
99
import {
1010
CustomerFacade,
11+
IamFacade,
1112
InvoiceFacade,
1213
RouterFacade,
1314
ShopFacade,
@@ -56,13 +57,14 @@ export class InvoiceEditComponent {
5657
),
5758
customers: this.customerFacade.all$,
5859
shops: this.shopFacade.all$,
60+
users: this.iamFacade.all$,
5961
}).pipe(
60-
map(({ id, invoice, customers, shops }) => {
62+
map(({ id, invoice, customers, shops, users }) => {
6163
const schema = buildInvoiceSchema({
6264
invoice,
6365
customers,
6466
shops,
65-
users: [],
67+
users,
6668
});
6769

6870
return {
@@ -79,6 +81,7 @@ export class InvoiceEditComponent {
7981
private readonly routerFacade: RouterFacade,
8082
private readonly shopFacade: ShopFacade,
8183
private readonly customerFacade: CustomerFacade,
82-
private readonly invoiceFacade: InvoiceFacade
84+
private readonly invoiceFacade: InvoiceFacade,
85+
private readonly iamFacade: IamFacade
8386
) {}
8487
}

0 commit comments

Comments
 (0)