Skip to content

Commit

Permalink
fix: show error notification when server returns error
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyOplachko committed Jun 28, 2024
1 parent ae47f13 commit ec68fac
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ export class PageAdvancedSettingsComponent implements OnInit, AfterViewInit, OnD
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
})
};
if (item) {
item.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ export class PageAgentSubscriptionsComponent implements OnInit, AfterViewInit, O
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

this.openDialog(DialogAgentsubComponent, item, onOpenDialog, isCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export class PageAliasComponent implements OnInit, OnDestroy, AfterViewInit {
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};
if (item) {
item.actionType = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class PageApiAuthComponent implements OnInit, AfterViewInit, OnDestroy {
);
}
this.updateData();
this.alertService.success(`${this.page} Successfully ${(_result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
};

const onOpenDialog = (result) => {
Expand All @@ -145,8 +146,9 @@ export class PageApiAuthComponent implements OnInit, AfterViewInit, OnDestroy {
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(onServiceRes);
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(onServiceRes, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

this.openDialog(DialogAuthKeyComponent, item, onOpenDialog, isCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export class PageMappingComponent implements OnInit, AfterViewInit, OnDestroy {
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ export class PageProfileComponent implements OnInit {
}
this.alertService.success(`${this.page} Successfully Updated`);

});
}, () => {
this.alertService.error(`Failed to Update ${this.page}`)
});
} else {
this.username.markAsTouched();
this.usergroup.markAsTouched();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ export class PageScriptsComponent implements OnInit, AfterViewInit, OnDestroy {
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => this.updateData(), () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

this.openDialog(DialogScriptsComponent, Functions.cloneObject(item), onOpenDialog, isCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ export class PageSystemOverviewComponent implements OnInit, AfterViewInit, OnDes
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

this.openDialog(DialogUsersComponent, item, onOpenDialog, isCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ export class PageUserSettingsComponent implements OnInit, OnDestroy, AfterViewIn
result.isCopy = isCopy;
this.service[result.isnew ? 'add' : (isCopy ? 'copy' : 'update')](result.data)
.toPromise()
.then(() => this.updateData());
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
.then(() => {
this.updateData();
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

if (item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ export class PageUsersComponent implements OnInit, OnDestroy, AfterViewInit {
this.authenticationService.logout();
this.router.navigate([{ outlets: { primary: null, system: 'login' } }]);
}
});
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);
this.alertService.success(`${this.page} Successfully ${(result.isnew ? 'Added' : (isCopy ? 'Copied' : 'Updated'))}`);

}, () => {
this.alertService.error(`Failed to ${(result.isnew ? 'Add' : (isCopy ? 'Copy' : 'Update'))} ${this.page}`)
});
};

this.openDialog(DialogUsersComponent, Functions.cloneObject(item), onOpenDialog, isCopy);
Expand Down

0 comments on commit ec68fac

Please sign in to comment.