feat: add snackbar service
MODIFY
src/app/app.module.ts
src/app/app.module.ts
@@ -41,6 +41,7 @@ import { MyAppsSummaryComponent } from './components/my-apps-summary/my-apps-sum
import { MyAppsUseApiComponent } from './components/my-apps-use-api/my-apps-use-api.component';
import { MyAppsPoliciesComponent } from './components/my-apps-policies/my-apps-policies.component';
import { MyAppsManageApiComponent } from './components/my-apps-manage-api/my-apps-manage-api.component';
+import { MatSnackBarModule } from '@angular/material/snack-bar';
export function initializeApp(
configService: ConfigService,
@@ -130,6 +131,7 @@ function initializeKeycloak(keycloakHelper: KeycloakHelperService) {
MatTableModule,
ReactiveFormsModule,
MatSortModule,
+ MatSnackBarModule,
],
providers: [
{

ADD
src/app/services/snackbar/snackbar.service.spec.ts
+import { TestBed } from '@angular/core/testing';
+
+import { SnackbarService } from './snackbar.service';
+
+describe('SnackbarService', () => {
+ let service: SnackbarService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(SnackbarService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});

ADD
src/app/services/snackbar/snackbar.service.ts
+import { Injectable } from '@angular/core';
+import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
+
+@Injectable({
+ providedIn: 'root',
+})
+export class SnackbarService {
+ readonly snackbarDuration = 6000;
+
+ constructor(private snackBar: MatSnackBar) {}
+
+ public showPrimarySnackBar(msg: string, action?: string) {
+ this.showCustomSnackBar(msg, action);
+ }
+
+ public showErrorSnackBar(msg: string, action?: string) {
+ this.showCustomSnackBar(msg, action, {
+ duration: this.snackbarDuration,
+ panelClass: ['warn-bg'],
+ });
+ }
+
+ public showCustomSnackBar(
+ msg: string,
+ action = '',
+ config: MatSnackBarConfig = {
+ duration: this.snackbarDuration,
+ panelClass: ['primary-bg'],
+ }
+ ) {
+ this.snackBar.open(msg, action, config);
+ }
+}

MODIFY
src/styles.scss
src/styles.scss
$accent: mat-color($accent-palette);
$warn: mat-color($warn-palette);
-
// CUSTOM SCSS
+ .primary-bg{
+ background: $primary !important;
+ }
+
+ .warn-bg{
+ background: $warn !important;
+ }
+
+ .accent-bg{
+ background: $accent !important;
+ }
+
.active-link{
color: $primary;
}

feat: add snackbar service