From 2552ef6a1805404add60aa93a757556549f94a05 Mon Sep 17 00:00:00 2001 From: sowgro Date: Tue, 8 Apr 2025 12:26:45 -0400 Subject: Add overfund warning --- .../funding-basket/funding-basket.component.css | 15 +++++++++++ .../funding-basket/funding-basket.component.html | 11 ++++++++ .../funding-basket/funding-basket.component.ts | 29 +++++++++++++++++++--- 3 files changed, 52 insertions(+), 3 deletions(-) (limited to 'ufund-ui') diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css index cff2bbe..259e18a 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.css +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.css @@ -93,3 +93,18 @@ display: flex; flex-direction: column; } + +.overfundWarn { + div { + display: flex; + flex-direction: row; + gap: 10px; + } + + background-color: var(--tertiary-color); + border-radius: 10px; + padding: 15px; + border-color: var(--secondary-color); + border-width: 1px; + border-style: solid; +} diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html index fa17b10..97375de 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.html +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.html @@ -1,3 +1,14 @@ + +
+

Overfund Notice

+

One or more of the needs in your basket will be overfunded.

+
+ + +
+
+
+
@if ((authService.getCurrentUserSubject() | async)?.type === userType.HELPER) {

Funding Basket

diff --git a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts index 920a7ef..45ca142 100644 --- a/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts +++ b/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts @@ -1,4 +1,4 @@ -import {Component, Input, OnInit, ViewChild} from '@angular/core'; +import {Component, Input, OnInit, TemplateRef, ViewChild} from '@angular/core'; import {UsersService} from '../../services/users.service'; import {Router} from '@angular/router'; import {CupboardService} from '../../services/cupboard.service'; @@ -7,6 +7,7 @@ import {AuthService} from '../../services/auth.service'; import {ToastsService, ToastType} from '../../services/toasts.service'; import {userType} from '../../models/User'; import {GoalType} from '../../models/Need'; +import {ModalService} from '../../services/modal.service'; @Component({ selector: 'app-funding-basket', @@ -17,16 +18,20 @@ import {GoalType} from '../../models/Need'; export class FundingBasketComponent implements OnInit { constructor( - private router: Router, protected cupboardService: CupboardService, protected usersService: UsersService, protected authService: AuthService, - private toastService: ToastsService + private toastService: ToastsService, + protected modalService: ModalService ) {} protected runningTotal = new BehaviorSubject(0) protected physicalTotal: string[] = [] + protected cancelModalFn?: () => void + protected acceptModalFn?: () => void + @ViewChild("contribution") contribution?: Input; + @ViewChild("overfundWarn") overfundWarn!: TemplateRef; ngOnInit(): void { @@ -53,6 +58,24 @@ export class FundingBasketComponent implements OnInit { return; } + let overfundWarn = false + for (let item of order) { + let n = await firstValueFrom(this.cupboardService.getNeed(item.needID)) + if (n.current + item.quantity > n.maxGoal) { + overfundWarn = true + } + } + if (overfundWarn) { + this.modalService.showModal(this.overfundWarn) + let res = await new Promise((resovle, _) => { + this.cancelModalFn = () => resovle(false) + this.acceptModalFn = () => resovle(true) + }) + if (!res) { + return; + } + } + try { await firstValueFrom(this.cupboardService.checkoutNeed(order)) } catch (ex:any) { -- cgit v1.2.3