import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { SpinnerService } from '@core/services/spinner.service'; import { WorkflowManager } from '@core/typings/workflow.typing'; import { TopLevelFilter } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { ConfirmationModalComponent, ModalFactory } from '@yourcause/common/modals'; import { WorkflowManagerModalComponent } from '../workflow-manager-modal/workflow-manager-modal.component'; import { WorkflowService } from '../workflow.service'; @Component({ selector: 'gc-workflow-managers-table', templateUrl: './workflow-managers-table.component.html', styleUrls: ['./workflow-managers-table.component.scss'] }) export class WorkflowManagersTableComponent { id = this.activatedRoute.snapshot.parent.params.id; topLevelFilters: TopLevelFilter[] = [ new TopLevelFilter( 'text', 'fullName', '', this.i18n.translate( 'GLOBAL:textSearchByNameOrEmail', {}, 'Search by name or email' ), undefined, undefined, [{ column: 'fullName', filterType: 'cn' }, { column: 'email', filterType: 'cn' }] ) ]; constructor ( private activatedRoute: ActivatedRoute, private workflowService: WorkflowService, private i18n: I18nService, private spinnerService: SpinnerService, private modalFactory: ModalFactory ) { } get workflowMap () { return this.workflowService.get('workflowMap'); } get workflow () { return this.workflowMap[this.id]; } get workflowManagers () { return this.workflow?.workflowLevelManagers || []; } async workflowManagerModal (workflowManager?: WorkflowManager) { const response = await this.modalFactory.open( WorkflowManagerModalComponent, { workflow: this.workflow, workflowManager } ); if (response) { this.spinnerService.startSpinner(); await this.workflowService.handleAddWorkflowManager( this.id, response.manager, !workflowManager ); this.spinnerService.stopSpinner(); if (response.addAnother) { this.workflowManagerModal(); } } } async removeWorkflowManager (manager: WorkflowManager) { const response = await this.modalFactory.open( ConfirmationModalComponent, { modalHeader: this.i18n.translate( 'WORKFLOW:hdrRemoveWorkflowManager', {}, 'Remove Workflow Manager' ), modalSubHeader: manager.fullName, confirmText: this.i18n.translate( 'WORKFLOW:textRemoveWorkflowManagerConfirm', { name: manager.fullName, workflowName: this.workflow.name }, 'This action will remove __name__ as a workflow manager for __workflowName__. They will no longer have access to application data for this workflow. Are you sure you want to remove them?' ), confirmButtonText: this.i18n.translate( 'common:btnSave', {}, 'Save' ) } ); if (response) { this.spinnerService.startSpinner(); await this.workflowService.handleRemoveWorkflowManager( this.id, manager.clientUserId ); this.spinnerService.stopSpinner(); } } }