feature-libs/order/components/replenishment-order-cancellation-dialog/replenishment-order-cancellation-dialog.component.ts
| changeDetection | ChangeDetectionStrategy.OnPush |
| selector | cx-replenishment-order-cancellation-dialog |
| templateUrl | ./replenishment-order-cancellation-dialog.component.html |
Properties |
Methods |
HostListeners |
constructor(userReplenishmentOrderService: ReplenishmentOrderFacade, globalMessageService: GlobalMessageService, launchDialogService: LaunchDialogService, el: ElementRef)
|
|||||||||||||||
|
Parameters :
|
| click |
Arguments : '$event'
|
click(event: UIEvent)
|
| cancelReplenishment |
cancelReplenishment()
|
|
Returns :
void
|
| close | ||||||
close(reason: string)
|
||||||
|
Parameters :
Returns :
void
|
| handleClick | ||||||
handleClick(event: UIEvent)
|
||||||
Decorators :
@HostListener('click', ['$event'])
|
||||||
|
Parameters :
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| onSuccess | ||||||
onSuccess(value: boolean)
|
||||||
|
Parameters :
Returns :
void
|
| focusConfig |
Type : FocusConfig
|
Default value : {
trap: true,
block: true,
autofocus: 'button',
focusOnEscape: true,
}
|
| replenishmentOrderCode |
Type : string
|
| Private subscription |
Default value : new Subscription()
|
import {
ChangeDetectionStrategy,
Component,
ElementRef,
HostListener,
OnDestroy,
OnInit,
} from '@angular/core';
import { GlobalMessageService, GlobalMessageType } from '@spartacus/core';
import { ReplenishmentOrderFacade } from '@spartacus/order/root';
import { FocusConfig, LaunchDialogService } from '@spartacus/storefront';
import { combineLatest, Subscription } from 'rxjs';
import { startWith } from 'rxjs/operators';
@Component({
selector: 'cx-replenishment-order-cancellation-dialog',
templateUrl: './replenishment-order-cancellation-dialog.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ReplenishmentOrderCancellationDialogComponent
implements OnInit, OnDestroy
{
private subscription = new Subscription();
replenishmentOrderCode: string;
focusConfig: FocusConfig = {
trap: true,
block: true,
autofocus: 'button',
focusOnEscape: true,
};
@HostListener('click', ['$event'])
handleClick(event: UIEvent): void {
// Close on click outside the dialog window
if ((event.target as any).tagName === this.el.nativeElement.tagName) {
this.close('Cross click');
}
}
constructor(
protected userReplenishmentOrderService: ReplenishmentOrderFacade,
protected globalMessageService: GlobalMessageService,
protected launchDialogService: LaunchDialogService,
protected el: ElementRef
) {}
ngOnInit(): void {
this.subscription.add(
combineLatest([
this.userReplenishmentOrderService
.getReplenishmentOrderDetails()
.pipe(startWith(null)),
this.launchDialogService.data$,
]).subscribe(([replenishmentOrder, code]) => {
this.replenishmentOrderCode =
code || replenishmentOrder?.replenishmentOrderCode;
})
);
this.subscription.add(
this.userReplenishmentOrderService
.getCancelReplenishmentOrderSuccess()
.subscribe((value) => this.onSuccess(value))
);
}
onSuccess(value: boolean): void {
if (value) {
this.launchDialogService.closeDialog(
'Successffully cancelled replenishment'
);
this.globalMessageService.add(
{
key: 'orderDetails.cancelReplenishment.cancelSuccess',
params: {
replenishmentOrderCode: this.replenishmentOrderCode,
},
},
GlobalMessageType.MSG_TYPE_CONFIRMATION
);
}
this.userReplenishmentOrderService.clearCancelReplenishmentOrderProcessState();
}
close(reason: string): void {
this.launchDialogService.closeDialog(reason);
}
cancelReplenishment(): void {
this.userReplenishmentOrderService.cancelReplenishmentOrder(
this.replenishmentOrderCode
);
}
ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
<div
[cxFocus]="focusConfig"
(esc)="close('Escape clicked')"
class="cx-cancel-replenishment-dialog-foreground"
>
<div class="cx-cancel-replenishment-dialog-content">
<div class="cx-cancel-replenishment-dialog-header">
<h3>
{{ 'orderDetails.cancelReplenishment.title' | cxTranslate }}
</h3>
</div>
<div class="cx-cancel-replenishment-dialog-description">
{{ 'orderDetails.cancelReplenishment.description' | cxTranslate }}
</div>
<div class="cx-cancel-replenishment-dialog-body">
<div class="cx-cancel-replenishment-btns row">
<div class="col-md-6">
<button
class="btn btn-block btn-action"
(click)="close('Close Replenishment Dialog')"
>
{{ 'orderDetails.cancelReplenishment.reject' | cxTranslate }}
</button>
</div>
<div class="col-md-6">
<button
class="btn btn-block btn-primary"
(click)="cancelReplenishment()"
>
{{ 'orderDetails.cancelReplenishment.accept' | cxTranslate }}
</button>
</div>
</div>
</div>
</div>
</div>