@@ -2,10 +2,12 @@ import {
2
2
ChangeDetectionStrategy ,
3
3
Component ,
4
4
Input ,
5
+ OnDestroy ,
5
6
OnInit ,
6
7
} from '@angular/core' ;
8
+ import { SubSink } from 'subsink' ;
7
9
8
- import { LayerRef , LayerService } from '@vcl/ng-vcl' ;
10
+ import { AlertService , AlertType , LayerRef , LayerService } from '@vcl/ng-vcl' ;
9
11
10
12
import { ModeType } from '@console-core/graphql' ;
11
13
import { ShopFacade } from '@console-core/state' ;
@@ -19,7 +21,7 @@ import { ShopDomainModalComponent } from './shop-domain-modal.component';
19
21
changeDetection : ChangeDetectionStrategy . OnPush ,
20
22
standalone : false ,
21
23
} )
22
- export class ShopViewDetailComponent implements OnInit {
24
+ export class ShopViewDetailComponent implements OnInit , OnDestroy {
23
25
@Input ( {
24
26
required : true ,
25
27
} )
@@ -30,8 +32,11 @@ export class ShopViewDetailComponent implements OnInit {
30
32
31
33
domainLayer ! : LayerRef ;
32
34
35
+ private readonly subscriptions = new SubSink ( ) ;
36
+
33
37
constructor (
34
38
private readonly layerService : LayerService ,
39
+ private readonly alertService : AlertService ,
35
40
private readonly shopFacade : ShopFacade
36
41
) { }
37
42
@@ -42,6 +47,10 @@ export class ShopViewDetailComponent implements OnInit {
42
47
} ) ;
43
48
}
44
49
50
+ ngOnDestroy ( ) : void {
51
+ this . subscriptions . unsubscribe ( ) ;
52
+ }
53
+
45
54
onAddDomain ( shop : IShop ) {
46
55
this . domainLayer
47
56
. open ( {
@@ -51,14 +60,14 @@ export class ShopViewDetailComponent implements OnInit {
51
60
} )
52
61
. subscribe ( ( result : { value : string } | undefined ) => {
53
62
if ( result ) {
54
- this . shopFacade . create ( {
63
+ this . shopFacade . update ( {
55
64
items : [
56
65
{
57
66
...shop ,
58
67
domains : [ ...( shop ?. domains || [ ] ) , result . value ] ,
59
68
} ,
60
69
] ,
61
- mode : ModeType . Create ,
70
+ mode : ModeType . Update ,
62
71
} ) ;
63
72
}
64
73
} ) ;
@@ -93,4 +102,38 @@ export class ShopViewDetailComponent implements OnInit {
93
102
}
94
103
} ) ;
95
104
}
105
+
106
+ onDeleteDomain ( shop : IShop , index : number ) {
107
+ this . subscriptions . sink = this . alertService
108
+ . open ( {
109
+ text : 'Do you really want to delete the domain?' ,
110
+ type : AlertType . Question ,
111
+ showCloseButton : true ,
112
+ showCancelButton : true ,
113
+ cancelButtonLabel : 'Cancel' ,
114
+ cancelButtonClass : 'transparent' ,
115
+ confirmButtonLabel : 'Delete domain' ,
116
+ confirmButtonClass : 'button' ,
117
+ } )
118
+ . subscribe ( ( result ) => {
119
+ if ( result . action !== 'confirm' ) {
120
+ return ;
121
+ }
122
+
123
+ const domains = shop ?. domains ;
124
+ if ( domains ) {
125
+ const domainsWithUpdate = domains . filter ( ( _ , idx ) => idx !== index ) ;
126
+
127
+ this . shopFacade . update ( {
128
+ items : [
129
+ {
130
+ ...shop ,
131
+ domains : domainsWithUpdate ,
132
+ } ,
133
+ ] ,
134
+ mode : ModeType . Update ,
135
+ } ) ;
136
+ }
137
+ } ) ;
138
+ }
96
139
}
0 commit comments