aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/need-edit/need-edit.component.ts
diff options
context:
space:
mode:
authorTyler Ferrari <69283684+Sowgro@users.noreply.github.com>2025-04-01 02:17:25 -0400
committerGitHub <noreply@github.com>2025-04-01 02:17:25 -0400
commit233fe120d2a9b30e0150401ebdfeb946dc9c2c07 (patch)
tree98583e1b1d21d1a0cc57e8ff3489fbbf758eccff /ufund-ui/src/app/components/need-edit/need-edit.component.ts
parentc6bbb29f42eaea7d0c8aebdb7b95be0287cbf4f9 (diff)
parent0e9c0803e35a23ef2e873dc7ebf224a49a92f207 (diff)
downloadJellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.tar.gz
JellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.tar.bz2
JellySolutions-233fe120d2a9b30e0150401ebdfeb946dc9c2c07.zip
Merge pull request #22 from RIT-SWEN-261-02/css
Merge css into main
Diffstat (limited to 'ufund-ui/src/app/components/need-edit/need-edit.component.ts')
-rw-r--r--ufund-ui/src/app/components/need-edit/need-edit.component.ts61
1 files changed, 61 insertions, 0 deletions
diff --git a/ufund-ui/src/app/components/need-edit/need-edit.component.ts b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
new file mode 100644
index 0000000..2462534
--- /dev/null
+++ b/ufund-ui/src/app/components/need-edit/need-edit.component.ts
@@ -0,0 +1,61 @@
+import { Component, Input, Output, EventEmitter } from '@angular/core';
+import { Need, GoalType } from '../../models/Need';
+import { CupboardService } from '../../services/cupboard.service';
+import { catchError, of } from 'rxjs';
+import { ToastsService, ToastType } from '../../services/toasts.service';
+
+@Component({
+ selector: 'app-need-edit',
+ standalone: false,
+ templateUrl: './need-edit.component.html',
+ styleUrl: './need-edit.component.css'
+})
+export class NeedEditComponent {
+ constructor(
+ private cupboardService: CupboardService,
+ private toastService: ToastsService
+
+ ) {}
+
+ @Input() selectedNeed!: Need;
+ @Output() refreshNeedList = new EventEmitter<void>();
+
+ update(form: any) {
+ 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,
+ description: form.description
+ };
+
+ this.cupboardService.updateNeed(need.id, need)
+ .pipe(catchError((ex, _) => {
+ if (ex.status == 500) {
+ this.toastService.sendToast(ToastType.ERROR, 'Fields cannot be blank');
+ } else if (ex.status == 400) {
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
+ } else {
+ this.toastService.sendToast(ToastType.ERROR, "Error on creating need");
+ }
+ return of()
+ }))
+ .subscribe(
+ (result) => {
+ if (result) {
+ console.log("need updated successfully");
+ this.refreshNeedList.emit();
+ } else {
+ console.log("need update failed");
+ }
+ }
+
+ );
+ }
+} \ No newline at end of file