aboutsummaryrefslogtreecommitdiff
path: root/ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-02 21:08:38 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-02 21:08:38 -0400
commitf88e5d727ae42d0e27ae7949d0f0d4189dda464d (patch)
treec83c116b44a293d74e1757009e654e5b735d9c10 /ufund-ui/src/app/components/funding-basket/funding-basket.component.ts
parent6b7c830eeefb6a6a28136a3faacf7713953a6138 (diff)
downloadJellySolutions-f88e5d727ae42d0e27ae7949d0f0d4189dda464d.tar.gz
JellySolutions-f88e5d727ae42d0e27ae7949d0f0d4189dda464d.tar.bz2
JellySolutions-f88e5d727ae42d0e27ae7949d0f0d4189dda464d.zip
[incomplete] checkout flow improvement
Diffstat (limited to 'ufund-ui/src/app/components/funding-basket/funding-basket.component.ts')
-rw-r--r--ufund-ui/src/app/components/funding-basket/funding-basket.component.ts60
1 files changed, 17 insertions, 43 deletions
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 847baee..18bb9b8 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
@@ -23,7 +23,6 @@ export class FundingBasketComponent implements OnInit {
) {}
@ViewChild("contribution") contribution?: Input;
- @Input() isValid: boolean = true;
// this is for login rerouting
ngOnInit(): void {
@@ -37,58 +36,33 @@ export class FundingBasketComponent implements OnInit {
}
async checkout() {
- this.isValid = true;
- for (let c of document.querySelectorAll('.contribution')!) {
- let contribution = c as HTMLInputElement;
- contribution.setAttribute("style", "");
- if (contribution.value == '' || contribution.valueAsNumber <= 0) {
- this.isValid = false;
+ let order: { id: number, quantity: number }[] = []
+ for (let contribution of document.querySelectorAll<HTMLInputElement>('.contribution')!) {
+ if (contribution.value == '' || contribution.valueAsNumber <= 0) {
contribution.setAttribute("style", "border-color: #ff0000");
this.toastService.sendToast(ToastType.ERROR, "Invalid input in funding basket!")
-
- setTimeout(() => {
- contribution.setAttribute("style", "border-color: #ffffff");
- }, 3000);
+ return;
}
+ order.push({id: +contribution.id, quantity: contribution.valueAsNumber});
}
- // if (this.usersService.getBasket().value != await firstValueFrom(this.usersService.getUser(1))
- // for (let c of this.usersService.getBasket().value) {
- // if (c == null) {
- // this.isValid = false;
- // this.statusText.next("One or more needs have been deleted")
- // } else {
- // this.statusText.next("test")
- // }
- // }
- if (this.isValid) {
- for (let c of document.querySelectorAll('.contribution')!) {
- let contribution = c as HTMLInputElement;
+
+ for (let c of document.querySelectorAll('.contribution')!) {
+ let contribution = c as HTMLInputElement;
+ try {
let need = await firstValueFrom(this.cupboardService.getNeed(+contribution.id));
+ await firstValueFrom(this.cupboardService.checkoutNeed(need.id, +contribution.value));
need.current += +contribution.value;
this.usersService.removeNeed(+need.id);
- this.cupboardService.checkoutNeed(need.id, +contribution.value)
- .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 new Observable<string>();
- }))
- .subscribe((result) => {
- if (result) {
- //this.needList?.refresh()
- } else {
- console.log('need update failed');
- }
- this.toastService.sendToast(ToastType.INFO, "Checkout successful");
- });
+ this.toastService.sendToast(ToastType.INFO, "Checkout successful");
+ } catch (ex: any) {
+ this.toastService.sendToast(ToastType.ERROR, ex.error);
}
}
}
-
+ resetColor(ev: any) {
+ console.log(ev);
+ (ev.target as HTMLInputElement).setAttribute("style", "border-color: unset")
+ }
}