import { Component , OnDestroy , OnInit } from '@angular/core' ; import { filter , tap } from 'rxjs/operators' ; import { ErrorHandlingService } from 'apps/gauzy/src/app/@core/services/error-handling.service' ; import { TranslateService } from '@ngx-translate/core' ; import { TranslationBaseComponent } from 'apps/gauzy/src/app/@shared/language-base/translation-base.component' ; import { Store } from 'apps/gauzy/src/app/@core/services/store.service' ; import { UpworkService } from 'apps/gauzy/src/app/@core/services/upwork.service' ; import { ToastrService } from 'apps/gauzy/src/app/@core/services/toastr.service' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; import { IOrganization } from '@gauzy/contracts' ; @ UntilDestroy ( { checkProperties : true } ) @ Component ( { selector : 'ngx-transactions' , templateUrl : './transactions.component.html' , styleUrls : [ './transactions.component.scss' ] } ) export class TransactionsComponent extends TranslationBaseComponent implements OnInit , OnDestroy { private _selectedOrganizationId : string ; file : File ; constructor ( private _upworkService , private _store , readonly translateService , private toastrService , private errorHandler ) { super ( translateService ) ; } ngOnInit ( ) { this . _store . selectedOrganization$ . pipe ( filter ( ( organization ) => ! ! organization ) , untilDestroyed ( this ) ) . subscribe ( ( organization ) => { this . _selectedOrganizationId = organization . id ; } ) ; } ngOnDestroy ( ) { } imageUrlChanged ( event ) { const [ file ] = event . target . files ; this . file = file ; event . target . value = null ; } importCsv ( ) { const formData = new FormData ( ) ; formData . append ( 'file' , this . file ) ; formData . append ( 'organizationId' , this . _selectedOrganizationId ) ; this . _upworkService . uploadTransaction ( formData ) . pipe ( untilDestroyed ( this ) , tap ( ( ) => ( this . file = null ) ) ) . subscribe ( ( { totalExpenses , totalIncomes } ) => { this . toastrService . success ( this . getTranslation ( 'INTEGRATIONS.TOTAL_UPWORK_TRANSACTIONS_SUCCEED' , { totalExpenses , totalIncomes } ) ) ; } , ( err ) => { this . errorHandler . handleError ( err , 0 ) ; } ) ; } }