Skip to content

Commit

Permalink
Fix loader when sending data to DHIS2
Browse files Browse the repository at this point in the history
  • Loading branch information
josephatJ committed Jun 30, 2023
1 parent 77b2dc3 commit a38642f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -76,7 +76,7 @@ export class DatasetViewFormComponent implements OnInit, AfterViewInit {
dataValueFetchs: DataValueFetchInterface[] | undefined;
dataValueFetch: any;
sendingData: boolean = false;
sendingDataResponse$: Observable<any> | undefined;
sendingDataResponse$: Observable<any> | undefined = of([]);
constructor(
private uiService: UiService,
private reportService: ReportsService,
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
7 changes: 5 additions & 2 deletions ui/src/app/services/reports/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -65,6 +65,9 @@ export class ReportsService {

sendReport(payload: any): Observable<any> {
const url = `${this.apiUrl}/sendValues`;
return this.httpClient.post<any>(url, payload, this.httpOptions);
return this.httpClient.post<any>(url, payload, this.httpOptions).pipe(
map((response) => response),
catchError((error) => of(error))
);
}
}

0 comments on commit a38642f

Please sign in to comment.