diff --git a/ui/src/app/modules/idapter-dashboard/components/reports/dataset-view-form/dataset-view-form.component.ts b/ui/src/app/modules/idapter-dashboard/components/reports/dataset-view-form/dataset-view-form.component.ts index 6db6a32c..d8c12ba8 100755 --- a/ui/src/app/modules/idapter-dashboard/components/reports/dataset-view-form/dataset-view-form.component.ts +++ b/ui/src/app/modules/idapter-dashboard/components/reports/dataset-view-form/dataset-view-form.component.ts @@ -45,7 +45,7 @@ import { onFormReady, onDataValueChange } from 'src/app/Helpers/form.helper'; import { MatDialog } from '@angular/material/dialog'; import { DatasetInterface, SourceInterface } from 'src/app/models/source.model'; import { DataValueFetchInterface } from 'src/app/resources/interfaces'; -import { Observable } from 'rxjs'; +import { Observable, of } from 'rxjs'; @Component({ selector: 'app-dataset-view-form', @@ -76,7 +76,7 @@ export class DatasetViewFormComponent implements OnInit, AfterViewInit { dataValueFetchs: DataValueFetchInterface[] | undefined; dataValueFetch: any; sendingData: boolean = false; - sendingDataResponse$: Observable | undefined; + sendingDataResponse$: Observable | undefined = of([]); constructor( private uiService: UiService, private reportService: ReportsService, @@ -173,15 +173,11 @@ export class DatasetViewFormComponent implements OnInit, AfterViewInit { this.sendingDataResponse$ = this.reportService.sendReport( this.sendingObject ); - this.sendingDataResponse$.subscribe({ - next: (response) => { - this.valueSentToDHIS2.emit(response); - }, - error: (err) => this.valueSentToDHIS2.emit(err), - }); + this.sendingDataResponse$.subscribe((response) => { if (response) { this.sendingData = false; + this.valueSentToDHIS2.emit(response); } }); } diff --git a/ui/src/app/services/reports/reports.service.ts b/ui/src/app/services/reports/reports.service.ts index 24874144..511a1a0c 100755 --- a/ui/src/app/services/reports/reports.service.ts +++ b/ui/src/app/services/reports/reports.service.ts @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { Observable, catchError, map, of } from 'rxjs'; @Injectable({ providedIn: 'root', @@ -65,6 +65,9 @@ export class ReportsService { sendReport(payload: any): Observable { const url = `${this.apiUrl}/sendValues`; - return this.httpClient.post(url, payload, this.httpOptions); + return this.httpClient.post(url, payload, this.httpOptions).pipe( + map((response) => response), + catchError((error) => of(error)) + ); } }