diff options
Diffstat (limited to 'ufund-ui/src/app/components/cupboard/cupboard.component.ts')
-rw-r--r-- | ufund-ui/src/app/components/cupboard/cupboard.component.ts | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/ufund-ui/src/app/components/cupboard/cupboard.component.ts b/ufund-ui/src/app/components/cupboard/cupboard.component.ts index 88ab46c..fff8760 100644 --- a/ufund-ui/src/app/components/cupboard/cupboard.component.ts +++ b/ufund-ui/src/app/components/cupboard/cupboard.component.ts @@ -2,9 +2,10 @@ 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 { @@ -85,23 +86,25 @@ export class CupboardComponent implements OnInit { console.log(form); const need: Need = { name: form.name, + image: form.image, location: form.location, id: this.selectedNeed.id, //system will control this maxGoal: form.maxGoal, type: GoalType[form.type as keyof typeof GoalType], urgent: form.urgent, filterAttributes: [], - current: 0 + current: 0, + description: form.description }; 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(ex.error); + this.toastService.sendToast(ToastType.INFO, ex.error); } else { - this.statusText.next("Error on creating need"); + this.toastService.sendToast(ToastType.INFO, "Error on creating need"); } return of() })) @@ -121,24 +124,26 @@ export class CupboardComponent implements OnInit { submit(form: any) { const need: Need = { name: form.name, + image: form.image, location: form.location, id: 0, maxGoal: form.maxGoal, type: form.type, urgent: form.urgent ? true : false, filterAttributes: [], - current: 0 + current: 0, + description: form.description }; console.log("need:", need); console.log("form submitted. creating need: ", need); 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(ex.error); + this.toastService.sendToast(ToastType.INFO, ex.error); } else { - this.statusText.next("Error on creating need"); + this.toastService.sendToast(ToastType.INFO, "Error on creating need"); } return of() })) |