import { Component, Input, OnInit } from '@angular/core'; import { Validators } from '@angular/forms'; import { StatusService } from '@core/services/status.service'; import { ArchiveModalData } from '@core/typings/application.typing'; import { TypeaheadSelectOption, TypeSafeFormBuilder, TypeSafeFormGroup } from '@yourcause/common'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; export interface ArchiveGroup { code: number; ids: number[]; notes: string; } @Component({ selector: 'gc-archive-modal', templateUrl: './archive-modal.component.html', styleUrls: ['./archive-modal.component.scss'] }) export class ArchiveModalComponent extends YCModalComponent implements OnInit { @Input() isNomination = false; @Input() context: 'archiveApp'|'unarchiveApp'|'archiveProgram'|'unarchiveProgram'; @Input() modalData: ArchiveModalData; @Input() programName: string; formGroup: TypeSafeFormGroup; reasonOptions: TypeaheadSelectOption[] = []; summaryText: string; modalHeader: string; primaryButtonText: string; showReason = false; showComment = false; paymentsCanBeAdded = this.i18n.translate( 'GLOBAL:textPaymentsCanBeAdded', {}, 'Payments that are available for processing can be added to a batch and processed' ); applicantsCanMakeChanges = this.i18n.translate( 'GLOBAL:textApplicantsCanMakeChanges', {}, 'Applicants can make changes to the application' ); archiveText = this.i18n.translate( 'GLOBAL:textArchive', {}, 'Archive' ); unarchiveText = this.i18n.translate( 'GLOBAL:textUnarchive', {}, 'Unarchive' ); grantManagersMakeChangesText = this.i18n.translate( 'GLOBAL:textGrantsManagersMakeChanges', {}, 'Grant manager users may make changes to archived applications, if needed' ); applicantsMayNotMakeChangesText = this.i18n.translate( 'GLOBAL:textApplicantsMayNotMakeChanges', {}, 'Applicants may not make changes to archived applications' ); archivedPaymentsCannotBeAddedText = this.i18n.translate( 'GLOBAL:textArchivedPaymentsCannotBeAdded', {}, 'Archived payments cannot be added to a new processing batch' ); constructor ( private formBuilder: TypeSafeFormBuilder, private i18n: I18nService, private statusService: StatusService, private analyticsService: AnalyticsService ) { super(); } ngOnInit () { this.reasonOptions = this.statusService.get('archiveReasonCodes'); this.formGroup = this.formBuilder.group({ ids: [this.modalData.ids], notes: '', code: this.context === 'archiveApp' ? [null, Validators.required] : null }); this.setModalText(); } setModalText () { if (this.isNomination) { switch (this.context) { case 'archiveApp': this.primaryButtonText = this.archiveText; this.showComment = true; this.showReason = true; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveNominationSummary', { appID: this.modalData.ids[0] }, 'Once archived, nomination __appID__ will be removed from the default view for Nominations and Insights, but may still be edited. Nominators will not be notified that this has been archived.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveNomination', {}, 'Archive Nomination' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveNominationsSummary', {}, 'Once archived, these nominations will be removed from the default view for Nominations and Insights, but may still be edited. Nominators will not be notified that these have been archived.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveNominations', {}, 'Archive Nominations' ); } break; case 'unarchiveApp': this.primaryButtonText = this.unarchiveText; this.showComment = false; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveNominationSummary', { appID: this.modalData.ids[0] }, 'Once unarchived, __appID__ will be shown in the default view for Nominations and Insights. Nominators will not be notified that this has been unarchived.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveNomination', {}, 'Unarchive Nomination' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveNominationssSummary', {}, 'Once unarchived, these nominations will be shown in the default view for Nominations and Insights. Nominators will not be notified that these have been unarchived.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveNominations', {}, 'Unarchive Nominations' ); } break; case 'unarchiveProgram': this.primaryButtonText = this.unarchiveText; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveNominationProgramSummary', { programName: this.modalData.programName }, 'Once unarchived, __programName__ will be shown in the default view for Nominations and Insights.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveNominationProgram', {}, 'Unarchive Nomination Program' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveNominationProgramssSummary', {}, 'Once unarchived, nomination programs will be shown in the default view for Nominations and Insights.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveNominationPrograms', {}, 'Unarchive Nomination Programs' ); } break; case 'archiveProgram': this.primaryButtonText = this.archiveText; this.showComment = true; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveNominationProgramSummary', { programName: this.programName }, 'Archiving __programName__ will archive all nominations, removing them from most views.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveNominationProgram', {}, 'Archive Nomination Program' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveNominationsSummary', {}, 'Once archived, these nomination programs will be removed from the default view for Nominations and Insights.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveNominationProgramss', {}, 'Archive Nomination Programs' ); } break; } } else { switch (this.context) { case 'archiveApp': this.primaryButtonText = this.archiveText; this.showComment = true; this.showReason = true; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveApplicationSummary', { appID: this.modalData.ids[0] }, 'Archiving application __appID__ will archive the application, its awards and payments, removing them from most views.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveApplication', {}, 'Archive Application' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveBulkApplicationsSummary', {}, 'Archiving applications will archive related awards and payments, removing them from most views.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveApplications', {}, 'Archive Applications' ); } break; case 'unarchiveApp': this.primaryButtonText = this.unarchiveText; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveApplicationSummaryShort', { appID: this.modalData.ids[0] }, 'Unarchiving application __appID__ will unarchive the application and its awards and payments' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveApplication', {}, 'Unarchive Application' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveApplicationsSummaryPayments', {}, 'Unarchiving applications will unarchive the application and its awards and payments' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveApplications', {}, 'Unarchive Applications' ); } break; case 'archiveProgram': this.primaryButtonText = this.archiveText; this.showComment = true; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveProgramSummary', { programName: this.programName }, 'Archiving __programName__ will archive all applications, removing them from most views.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveProgram', {}, 'Archive Program' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textArchiveProgramsSummary', {}, 'Archiving these programs will archive all applications, removing them from most views.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textArchiveApplications', {}, 'Archive Applications' ); } break; case 'unarchiveProgram': this.primaryButtonText = this.unarchiveText; if (this.modalData.ids.length === 1) { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveProgramSummaryUpdated', { programName: this.programName }, 'Once unarchived, __programName__ will be shown in the default view for Applications and Insights.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchiveProgram', {}, 'Unarchive Program' ); } else { this.summaryText = this.i18n.translate( 'GLOBAL:textUnarchiveProgramssSummary', {}, 'Once unarchived, these programs will be shown in the default view for Applications and Insights.' ); this.modalHeader = this.i18n.translate( 'GLOBAL:textUnarchivePrograms', {}, 'Unarchive Programs' ); } break; } } } onCancel () { this.closeModal.emit(); } onSubmit () { this.closeModal.emit(this.formGroup.value); this.analyticsService.emitEvent({ eventName: 'Archive modal submit', eventType: EventType.Click, extras: null }); } }