diff options
3 files changed, 52 insertions, 3 deletions
| 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 @@ +<ng-template #overfundWarn> +    <div class="overfundWarn"> +        <h1>Overfund Notice</h1> +        <p>One or more of the needs in your basket will be overfunded.</p> +        <div> +            <button (click) ="modalService.hideModal(); cancelModalFn!();">Cancel</button> +            <button (click)="modalService.hideModal(); acceptModalFn!();">Overfund Needs</button> +        </div> +    </div> +</ng-template> +  <div id="box">      @if ((authService.getCurrentUserSubject() | async)?.type === userType.HELPER) {          <h1>Funding Basket</h1> 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<any>;      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) { | 
