33 EventEmitter ,
44 OnInit ,
55 Output ,
6- ViewChild ,
76} from '@angular/core' ;
7+ import { MatDialog } from '@angular/material/dialog' ;
88import { TableHeaderElementModel } from 'src/app/common/models' ;
99import { CustomersPnFieldStatusEnum } from '../../enums' ;
1010import {
@@ -15,6 +15,11 @@ import {
1515} from '../../models' ;
1616import { CustomersPnFieldsService , CustomersPnService } from '../../services' ;
1717import { 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} )
2530export 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