import { Component, Input, OnInit } from '@angular/core'; import { BatchItem, ProcessingTypes } from '@core/typings/payment.typing'; import { BatchStatuses } from '@core/typings/status.typing'; import { TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-update-batch-status-modal', templateUrl: './update-batch-status-modal.component.html', styleUrls: ['./update-batch-status-modal.component.scss'] }) export class UpdateBatchStatusModalComponent extends YCModalComponent<{ notes: string; }> implements OnInit { @Input() newStatus: BatchStatuses; @Input() item: BatchItem; formGroup: TypeSafeFormGroup<{ notes: string }>; ProcessingTypes = ProcessingTypes; BatchStatuses = BatchStatuses; modalHeader = ''; primaryButtonText = ''; confirmText = ''; constructor ( private formBuilder: TypeSafeFormBuilder, private i18n: I18nService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { const helpers = this.getHelpers(); this.modalHeader = helpers.header; this.primaryButtonText = helpers.primaryButtonText; this.confirmText = this.getHelpers().alert; this.formGroup = this.formBuilder.group({ notes: [''] }); } getHelpers () { switch (this.newStatus) { case BatchStatuses.Open: default: return { text: 'Open', alert: this.item.statusId !== BatchStatuses.Reviewed ? this.i18n.translate( 'MANAGE:textUseOptionToSetOpenAndChangePaymentStatus', {}, 'Are you sure you want to mark the batch as open? All payments in the batch will be updated with a status of Scheduled.' ) : this.i18n.translate( 'MANAGE:textMarkBatchOpen', {}, 'Are you sure you want to mark the batch as open?' ), header: this.i18n.translate( 'MANAGE:hdrModalMarkAsOpen', {}, 'Mark as Open' ), primaryButtonText: this.i18n.translate( 'MANAGE:btnMarkAsOpen', {}, 'Mark as open' ) }; case BatchStatuses.Reviewed: return { text: 'Reviewed', alert: this.i18n.translate( 'MANAGE:textMarkBatchReviewed', {}, 'Are you sure you want to mark the batch as Reviewed?' ), header: this.i18n.translate( 'MANAGE:hdrModalMarkAsReviewed', {}, 'Mark as Reviewed' ), primaryButtonText: this.i18n.translate( 'MANAGE:btnMarkAsReviewed', {}, 'Mark as reviewed' ) }; case BatchStatuses.Processing: return { text: 'Pending', alert: this.i18n.translate( 'MANAGE:textMarkBatchPending', {}, 'Are you sure you want to mark the batch as Pending? All payments in the batch will be updated with a status of Pending.' ), header: this.i18n.translate( 'MANAGE:hdrModalMarkAsPending', {}, 'Mark as Pending' ), primaryButtonText: this.i18n.translate( 'MANAGE:btnMarkAsPending', {}, 'Mark as pending' ) }; case BatchStatuses.Funded: return { text: 'Funded', alert: this.i18n.translate( 'MANAGE:textMarkBatchFunded', {}, 'Are you sure you want to mark the batch as Funded?' ), header: this.i18n.translate( 'MANAGE:hdrModalMarkAsFunded', {}, 'Mark as Funded' ), primaryButtonText: this.i18n.translate( 'MANAGE:btnMarkAsFunded', {}, 'Mark as funded' ) }; case BatchStatuses.Disbursed: return { text: 'Disbursed', alert: this.i18n.translate( 'MANAGE:textMarkBatchDisbursed', {}, 'Are you sure you want to mark the batch as Disbursed?' ), header: this.i18n.translate( 'MANAGE:hdrModalMarkAsDisbursed', {}, 'Mark as Disbursed' ), primaryButtonText: this.i18n.translate( 'MANAGE:btnMarkAsDisbursed', {}, 'Mark as disbursed' ) }; } } save () { this.closeModal.emit({ notes: this.formGroup.value.notes }); this.analyticsService.emitEvent({ eventName: 'Update batch status modal save', eventType: EventType.Click, extras: null }); } }