File
Implements
Metadata
| changeDetection |
ChangeDetectionStrategy.OnPush |
| selector |
cx-close-account-modal |
| templateUrl |
./close-account-modal.component.html |
Methods
|
closeAccount
|
closeAccount()
|
|
|
|
|
|
dismissModal
|
dismissModal(reason?: any)
|
|
|
Parameters :
| Name |
Type |
Optional |
| reason |
any
|
Yes
|
|
|
iconTypes
|
Default value : ICON_TYPE
|
|
|
|
isLoading$
|
Default value : new BehaviorSubject(false)
|
|
|
|
isLoggedIn$
|
Type : Observable<boolean>
|
|
|
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import {
AuthService,
GlobalMessageService,
GlobalMessageType,
RoutingService,
TranslationService,
} from '@spartacus/core';
import { ICON_TYPE, ModalService } from '@spartacus/storefront';
import { BehaviorSubject, Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { UserProfileFacade } from '@spartacus/user/profile/root';
@Component({
selector: 'cx-close-account-modal',
templateUrl: './close-account-modal.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CloseAccountModalComponent implements OnInit {
iconTypes = ICON_TYPE;
isLoggedIn$: Observable<boolean>;
isLoading$ = new BehaviorSubject(false);
constructor(
protected modalService: ModalService,
protected authService: AuthService,
protected globalMessageService: GlobalMessageService,
protected routingService: RoutingService,
protected translationService: TranslationService,
protected userProfile: UserProfileFacade
) {}
ngOnInit() {
this.isLoggedIn$ = this.authService.isUserLoggedIn();
}
onSuccess(): void {
this.dismissModal();
this.translationService
.translate('closeAccount.accountClosedSuccessfully')
.pipe(first())
.subscribe((text) => {
this.globalMessageService.add(
text,
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
});
this.routingService.go({ cxRoute: 'home' });
}
onError(): void {
this.dismissModal();
this.translationService
.translate('closeAccount.accountClosedFailure')
.pipe(first())
.subscribe((text) => {
this.globalMessageService.add(text, GlobalMessageType.MSG_TYPE_ERROR);
});
}
dismissModal(reason?: any): void {
this.modalService.dismissActiveModal(reason);
}
closeAccount() {
this.isLoading$.next(true);
this.userProfile.close().subscribe({
next: () => {
this.onSuccess();
this.isLoading$.next(false);
},
error: () => {
this.onError();
this.isLoading$.next(false);
},
});
}
}
<ng-container *ngIf="isLoggedIn$ | async">
<div class="modal-header cx-dialog-header">
<h3 class="modal-title">
{{ 'closeAccount.confirmAccountClosure' | cxTranslate }}
</h3>
<button
type="button"
class="close"
[attr.aria-label]="'common.close' | cxTranslate"
(click)="dismissModal()"
>
<span aria-hidden="true">
<cx-icon [type]="iconTypes.CLOSE"></cx-icon>
</span>
</button>
</div>
<div *ngIf="isLoading$ | async; else loaded">
<div class="cx-spinner">
<cx-spinner> </cx-spinner>
</div>
</div>
<ng-template #loaded>
<div class="modal-body">
<div class="cx-row">
<p class="cx-confirmation">
{{ 'closeAccount.confirmAccountClosureMessage' | cxTranslate }}
</p>
</div>
<div class="cx-row">
<div class="cx-btn-group">
<button class="btn btn-primary" (click)="closeAccount()">
{{ 'closeAccount.closeMyAccount' | cxTranslate }}
</button>
<button (click)="dismissModal()" class="btn btn-block btn-secondary">
{{ 'common.cancel' | cxTranslate }}
</button>
</div>
</div>
</div>
</ng-template>
</ng-container>
Legend
Html element with directive