From 696a4dd64ce94678001310f92bde1dd613836f5f Mon Sep 17 00:00:00 2001 From: Jasjeet Mavi <42419193+judgemavi@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:11:36 -0500 Subject: [PATCH] Add df-alert component to df-role-details component --- .../df-role-details.component.html | 7 +++- .../df-role-details.component.ts | 32 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/app/adf-roles/df-role-details/df-role-details.component.html b/src/app/adf-roles/df-role-details/df-role-details.component.html index 62ac8ea8..a5134279 100644 --- a/src/app/adf-roles/df-role-details/df-role-details.component.html +++ b/src/app/adf-roles/df-role-details/df-role-details.component.html @@ -1,7 +1,12 @@

{{ 'roles.rolesOverview.description' | transloco }}

- + + {{ alertMsg }} +
{{ 'name' | transloco }} diff --git a/src/app/adf-roles/df-role-details/df-role-details.component.ts b/src/app/adf-roles/df-role-details/df-role-details.component.ts index 26477e1d..4b93e57b 100644 --- a/src/app/adf-roles/df-role-details/df-role-details.component.ts +++ b/src/app/adf-roles/df-role-details/df-role-details.component.ts @@ -25,6 +25,11 @@ import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { MatButtonModule } from '@angular/material/button'; import { DfRolesAccessComponent } from '../df-roles-access/df-roles-access.component'; import { UntilDestroy } from '@ngneat/until-destroy'; +import { + AlertType, + DfAlertComponent, +} from 'src/app/shared/components/df-alert/df-alert.component'; +import { catchError, throwError } from 'rxjs'; @UntilDestroy({ checkProperties: true }) @Component({ selector: 'df-role-details', @@ -42,11 +47,15 @@ import { UntilDestroy } from '@ngneat/until-destroy'; MatButtonModule, DfRolesAccessComponent, NgIf, + DfAlertComponent, ], }) export class DfRoleDetailsComponent implements OnInit { roleForm: FormGroup; type = ''; + alertMsg = ''; + showAlert = false; + alertType: AlertType = 'error'; constructor( @Inject(ROLE_SERVICE_TOKEN) @@ -137,6 +146,12 @@ export class DfRoleDetailsComponent implements OnInit { return result; } + triggerAlert(type: AlertType, msg: string) { + this.alertType = type; + this.alertMsg = msg; + this.showAlert = true; + } + onSubmit() { if (this.roleForm.invalid) return; @@ -168,7 +183,12 @@ export class DfRoleDetailsComponent implements OnInit { if (this.type === 'edit' && payload.id) { this.roleService .update(payload.id, payload) - + .pipe( + catchError(err => { + this.triggerAlert('error', err.error.error.message); + return throwError(() => new Error(err)); + }) + ) .subscribe(() => { this.goBack(); }); @@ -178,7 +198,15 @@ export class DfRoleDetailsComponent implements OnInit { fields: '*', related: 'role_service_access_by_role_id,lookup_by_role_id', }) - + .pipe( + catchError(err => { + this.triggerAlert( + 'error', + err.error.error.context.resource[0].message + ); + return throwError(() => new Error(err)); + }) + ) .subscribe(() => { this.goBack(); });