Skip to content

Commit df26d66

Browse files
Copilotrenemadsen
andcommitted
Update customers-pn-page to open modals with MatDialog.open()
Co-authored-by: renemadsen <[email protected]>
1 parent 05fe25e commit df26d66

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

eform-client/src/app/plugins/modules/customers-pn/components/customers-pn-page/customers-pn-page.component.html

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,3 @@
202202
</div>
203203
</div>
204204
</div>
205-
206-
<app-customer-pn-add
207-
#createCustomerModal
208-
[fieldsModel]="fieldsModel"
209-
(onCustomerCreated)="getAllCustomers()"
210-
></app-customer-pn-add>
211-
<app-customer-pn-edit
212-
#editCustomerModal
213-
[fieldsModel]="fieldsModel"
214-
(onCustomerUpdated)="getAllCustomers()"
215-
></app-customer-pn-edit>
216-
<app-customer-pn-delete
217-
#deleteCustomerModal
218-
[fields]="fieldsModel"
219-
(onCustomerDeleted)="onCustomerDeleted()"
220-
></app-customer-pn-delete>

eform-client/src/app/plugins/modules/customers-pn/components/customers-pn-page/customers-pn-page.component.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
EventEmitter,
44
OnInit,
55
Output,
6-
ViewChild,
76
} from '@angular/core';
7+
import { MatDialog } from '@angular/material/dialog';
88
import { TableHeaderElementModel } from 'src/app/common/models';
99
import { CustomersPnFieldStatusEnum } from '../../enums';
1010
import {
@@ -15,6 +15,11 @@ import {
1515
} from '../../models';
1616
import { CustomersPnFieldsService, CustomersPnService } from '../../services';
1717
import { CustomersStateService } from '../store';
18+
import { CustomerPnAddComponent } from '../customer-pn-add/customer-pn-add.component';
19+
import { CustomerPnEditComponent } from '../customer-pn-edit/customer-pn-edit.component';
20+
import { CustomerPnDeleteComponent } from '../customer-pn-delete/customer-pn-delete.component';
21+
import { dialogConfigHelper } from 'src/app/common/helpers';
22+
import { Overlay } from '@angular/cdk/overlay';
1823

1924
@Component({
2025
selector: 'app-customers-pn-page',
@@ -23,9 +28,6 @@ import { CustomersStateService } from '../store';
2328
standalone: false
2429
})
2530
export class CustomersPnPageComponent implements OnInit {
26-
@ViewChild('createCustomerModal', { static: false }) createCustomerModal;
27-
@ViewChild('editCustomerModal', { static: false }) editCustomerModal;
28-
@ViewChild('deleteCustomerModal', { static: false }) deleteCustomerModal;
2931
@Output() onCustomerDuplicated: EventEmitter<void> = new EventEmitter<void>();
3032
get fieldStatusEnum() {
3133
return CustomersPnFieldStatusEnum;
@@ -40,7 +42,9 @@ export class CustomersPnPageComponent implements OnInit {
4042
constructor(
4143
private customersService: CustomersPnService,
4244
private customersFieldsService: CustomersPnFieldsService,
43-
public customersStateService: CustomersStateService
45+
public customersStateService: CustomersStateService,
46+
private dialog: MatDialog,
47+
private overlay: Overlay
4448
) {}
4549

4650
checkFieldStatus(numField: number) {
@@ -101,19 +105,42 @@ export class CustomersPnPageComponent implements OnInit {
101105
}
102106

103107
showCreateCustomerModal() {
104-
this.createCustomerModal.show();
108+
const modal = this.dialog.open(CustomerPnAddComponent, {
109+
...dialogConfigHelper(this.overlay, { fields: this.fieldsModel }),
110+
minWidth: 600
111+
});
112+
modal.componentInstance.customerCreated.subscribe(() => {
113+
this.getAllCustomers();
114+
});
105115
}
106116

107117
showCopyCustomerModal(model: CustomerPnModel) {
108-
this.createCustomerModal.showCopy(model.id);
118+
const modal = this.dialog.open(CustomerPnAddComponent, {
119+
...dialogConfigHelper(this.overlay, { customerId: model.id, fields: this.fieldsModel }),
120+
minWidth: 600
121+
});
122+
modal.componentInstance.customerCreated.subscribe(() => {
123+
this.getAllCustomers();
124+
});
109125
}
110126

111127
showEditCustomerModal(model: CustomerPnModel) {
112-
this.editCustomerModal.show(model.id);
128+
const modal = this.dialog.open(CustomerPnEditComponent, {
129+
...dialogConfigHelper(this.overlay, { customerId: model.id, fields: this.fieldsModel }),
130+
minWidth: 600
131+
});
132+
modal.componentInstance.customerUpdate.subscribe(() => {
133+
this.getAllCustomers();
134+
});
113135
}
114136

115137
showDeleteCustomerModal(model: CustomerPnModel) {
116-
this.deleteCustomerModal.show(model);
138+
const modal = this.dialog.open(CustomerPnDeleteComponent, {
139+
...dialogConfigHelper(this.overlay, { customer: model, fields: this.fieldsModel })
140+
});
141+
modal.componentInstance.customerDeleted.subscribe(() => {
142+
this.onCustomerDeleted();
143+
});
117144
}
118145

119146
onSearchInputChanged(value: string) {

0 commit comments

Comments
 (0)