From e1ef22279baccb4b2a5a1ecbb5222e4008d4d523 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 31 Mar 2025 20:28:35 -0400 Subject: Added toasts for error handling --- .../app/components/cupboard/cupboard.component.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts') diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 9c8a173..653edd4 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -1,10 +1,11 @@ -import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, ViewChild} from '@angular/core'; import { CupboardService } from '../../services/cupboard.service'; import { Need, GoalType } from '../../models/Need'; import { userType } from '../../models/User'; -import { BehaviorSubject, catchError, of } from 'rxjs'; +import { catchError, of } from 'rxjs'; import { NeedListComponent } from '../need-list/need-list.component'; import {AuthService} from '../../services/auth.service'; +import {ToastsService, ToastType} from '../../services/toasts.service'; @Component({ selector: 'app-cupboard', @@ -15,14 +16,14 @@ import {AuthService} from '../../services/auth.service'; export class CupboardComponent implements OnInit { - protected statusText = new BehaviorSubject("") selectedForm = "create"; needs: any; @ViewChild("needList") needList?: NeedListComponent constructor( private cupboardService: CupboardService, - private authService: AuthService + private authService: AuthService, + private toastService: ToastsService ) {} ngOnInit(): void { @@ -99,11 +100,11 @@ export class CupboardComponent implements OnInit { this.cupboardService.updateNeed(need.id, need) .pipe(catchError((ex, _) => { if (ex.status == 500) { - this.statusText.next("Fields cannot be blank"); + this.toastService.sendToast(ToastType.INFO, 'Fields cannot be blank'); } else if (ex.status == 400) { - this.statusText.next("Goal must be greater than 0"); + this.toastService.sendToast(ToastType.INFO, "Goal must be greater than 0"); } else { - this.statusText.next("Error on creating need"); + this.toastService.sendToast(ToastType.INFO, "Error on creating need"); } return of() })) @@ -138,11 +139,11 @@ export class CupboardComponent implements OnInit { this.cupboardService.createNeed(need) .pipe(catchError((ex, _) => { if (ex.status == 500) { - this.statusText.next("Fields cannot be blank"); + this.toastService.sendToast(ToastType.INFO, "Fields cannot be blank"); } else if (ex.status == 400) { - this.statusText.next("Goal must be greater than 0"); + this.toastService.sendToast(ToastType.INFO, "Goal must be greater than 0"); } else { - this.statusText.next("Error on creating need"); + this.toastService.sendToast(ToastType.INFO, "Error on creating need"); } return of() })) -- cgit v1.2.3