Skip to content

Commit

Permalink
fix: split save button loader race condition (#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashpatil78 authored Feb 19, 2024
1 parent 1c3860a commit ea1fc81
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/app/fyle/split-expense/split-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ export class SplitExpensePage {
}

showSuccessToast(): void {
this.saveSplitExpenseLoading = false;
const toastMessage = 'Expense split successfully.';
if (this.reportId) {
this.router.navigate(['/', 'enterprise', 'my_view_report', { id: this.reportId }]);
Expand Down Expand Up @@ -723,6 +724,8 @@ export class SplitExpensePage {
.splitExpense(this.formattedSplitExpense, this.fileObjs, this.transaction, reportAndCategoryParams)
.pipe(
catchError((errResponse: HttpErrorResponse) => {
this.saveSplitExpenseLoading = false;

const splitTrackingProps = this.getSplitExpensePoperties();
splitTrackingProps['Error Message'] = (errResponse?.error as { message: string })?.message;
this.trackingService.splitExpensePolicyCheckFailed(splitTrackingProps);
Expand Down Expand Up @@ -846,22 +849,25 @@ export class SplitExpensePage {
{ reportId: this.reportId, unspecifiedCategory: this.unspecifiedCategory }
);

this.saveSplitExpenseLoading = false;

this.trackingService.splitExpensePolicyCheckFailed(splitTrackingProps);

const message = 'We were unable to split your expense. Please try again later.';
this.toastWithoutCTA(message, ToastType.FAILURE, 'msb-failure-with-camera-icon');
return throwError(errResponse);
}),
finalize(() => {
this.saveSplitExpenseLoading = false;

const splitTrackingProps = this.getSplitExpensePoperties();
this.trackingService.splittingExpense(splitTrackingProps);
})
)
.subscribe((response) => {
if (response && response.action === 'continue') {
this.handleSplitExpense(response.comments);
} else {
// If user clicks on cancel button, then stop the loader
this.saveSplitExpenseLoading = false;
}
});
});
Expand Down

0 comments on commit ea1fc81

Please sign in to comment.