Skip to content

Commit d23c3b3

Browse files
committed
feat(shop): add logic for deleting domain
1 parent 3583081 commit d23c3b3

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

packages/modules/management/src/lib/components/shop/view/shop-view-details.component.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ <h4>Data</h4>
115115
}
116116
]"
117117
>
118-
<vcl-select-list>
118+
<vcl-select-list value="">
119119
<vcl-select-list-item
120120
(click)="onEditDomain(vm.shop, domain, domainIndex); popover.close()"
121121
>
122122
Edit
123123
</vcl-select-list-item>
124-
<vcl-select-list-item value=""> Delete </vcl-select-list-item>
124+
<vcl-select-list-item (click)="onDeleteDomain(vm.shop, domainIndex)">
125+
Delete
126+
</vcl-select-list-item>
125127
</vcl-select-list>
126128
</ng-template>
127129
</ng-template>

packages/modules/management/src/lib/components/shop/view/shop-view-details.component.ts

+47-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {
22
ChangeDetectionStrategy,
33
Component,
44
Input,
5+
OnDestroy,
56
OnInit,
67
} from '@angular/core';
8+
import { SubSink } from 'subsink';
79

8-
import { LayerRef, LayerService } from '@vcl/ng-vcl';
10+
import { AlertService, AlertType, LayerRef, LayerService } from '@vcl/ng-vcl';
911

1012
import { ModeType } from '@console-core/graphql';
1113
import { ShopFacade } from '@console-core/state';
@@ -19,7 +21,7 @@ import { ShopDomainModalComponent } from './shop-domain-modal.component';
1921
changeDetection: ChangeDetectionStrategy.OnPush,
2022
standalone: false,
2123
})
22-
export class ShopViewDetailComponent implements OnInit {
24+
export class ShopViewDetailComponent implements OnInit, OnDestroy {
2325
@Input({
2426
required: true,
2527
})
@@ -30,8 +32,11 @@ export class ShopViewDetailComponent implements OnInit {
3032

3133
domainLayer!: LayerRef;
3234

35+
private readonly subscriptions = new SubSink();
36+
3337
constructor(
3438
private readonly layerService: LayerService,
39+
private readonly alertService: AlertService,
3540
private readonly shopFacade: ShopFacade
3641
) {}
3742

@@ -42,6 +47,10 @@ export class ShopViewDetailComponent implements OnInit {
4247
});
4348
}
4449

50+
ngOnDestroy(): void {
51+
this.subscriptions.unsubscribe();
52+
}
53+
4554
onAddDomain(shop: IShop) {
4655
this.domainLayer
4756
.open({
@@ -51,14 +60,14 @@ export class ShopViewDetailComponent implements OnInit {
5160
})
5261
.subscribe((result: { value: string } | undefined) => {
5362
if (result) {
54-
this.shopFacade.create({
63+
this.shopFacade.update({
5564
items: [
5665
{
5766
...shop,
5867
domains: [...(shop?.domains || []), result.value],
5968
},
6069
],
61-
mode: ModeType.Create,
70+
mode: ModeType.Update,
6271
});
6372
}
6473
});
@@ -93,4 +102,38 @@ export class ShopViewDetailComponent implements OnInit {
93102
}
94103
});
95104
}
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+
}
96139
}

0 commit comments

Comments
 (0)