diff --git a/src/app/app-routing.ts b/src/app/app-routing.ts index 502ecedec..bfd9cc5d6 100644 --- a/src/app/app-routing.ts +++ b/src/app/app-routing.ts @@ -19,6 +19,7 @@ import {RegularGivingComponent} from "./regular-giving/regular-giving.component" import {Person} from "./person.model"; import {firstValueFrom} from "rxjs"; import {MandateComponent} from "./mandate/mandate.component"; +import {Mandate} from "./mandate.model"; export const registerPath = 'register'; export const myAccountPath = 'my-account'; @@ -73,6 +74,16 @@ const LoggedInPersonResolver: ResolveFn = async () => { return await firstValueFrom(person$); } +const mandateResolver: ResolveFn = async (route: ActivatedRouteSnapshot) => { + const mandateService = inject(MandateService); + const mandateId = route.paramMap.get('mandateId'); + if (!mandateId) { + throw new Error('mandateId param missing in route'); + } + const mandate$ = mandateService.getActiveMandate(mandateId); + return await firstValueFrom(mandate$); +} + const routes: Routes = [ { path: '', @@ -283,13 +294,7 @@ if (flags.regularGivingEnabled) { requireLogin, ], resolve: { - /** - * need similar method but for one mandate - */ - // mandates: () => { - // inject(MandateService).getActiveMandate(mandateId), - // } - + mandate: mandateResolver, }, }) } diff --git a/src/app/mandate.service.ts b/src/app/mandate.service.ts index f2b141c58..788a1140a 100644 --- a/src/app/mandate.service.ts +++ b/src/app/mandate.service.ts @@ -4,7 +4,6 @@ import {environment} from "../environments/environment"; import {IdentityService, getPersonAuthHttpOptions } from "./identity.service"; import { HttpClient } from "@angular/common/http"; import {Mandate} from "./mandate.model"; -import {Campaign} from "./campaign.model"; @Injectable({ providedIn: 'root', @@ -32,7 +31,7 @@ export class MandateService { })); } - getActiveMandate(regularGivingCampaignId: Campaign) { + getActiveMandate(mandateId: string) { const jwt = this.identityService.getJWT(); const person$ = this.identityService.getLoggedInPerson(); @@ -42,7 +41,7 @@ export class MandateService { } return this.http.get<{ mandate: Mandate }>( - `${environment.donationsApiPrefix}/regular-giving/my-donation-mandate/${regularGivingCampaignId}`, + `${environment.donationsApiPrefix}/regular-giving/my-donation-mandates/${mandateId}`, getPersonAuthHttpOptions(jwt), ).pipe(map((response) => response.mandate)); })); diff --git a/src/app/mandate/mandate.component.ts b/src/app/mandate/mandate.component.ts index fa22730c9..8444389d2 100644 --- a/src/app/mandate/mandate.component.ts +++ b/src/app/mandate/mandate.component.ts @@ -1,9 +1,9 @@ -import { Component } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import {ComponentsModule} from "@biggive/components-angular"; import {DatePipe} from "@angular/common"; import {Mandate} from "../mandate.model"; -import {Donation} from "../donation.model"; import {ExactCurrencyPipe} from "../exact-currency.pipe"; +import {ActivatedRoute} from "@angular/router"; @Component({ selector: 'app-mandate', @@ -16,36 +16,19 @@ import {ExactCurrencyPipe} from "../exact-currency.pipe"; templateUrl: './mandate.component.html', styleUrl: './mandate.component.scss' }) -export class MandateComponent { - complete: boolean = true; - encodedShareUrl: string = ''; - encodedPrefilledText: string = ''; - donation: Donation; +export class MandateComponent implements OnInit { + protected encodedShareUrl: string = ''; + protected encodedPrefilledText: string = ''; + protected mandate: Mandate; + + constructor( + private route: ActivatedRoute + ) {} + + ngOnInit() { + this.mandate = this.route.snapshot.data.mandate; + } // @todo-regular-giving: calculate the total in matchbot and show on template // totalPaid: number = 0; - - // @todo-regular-giving : replace this with a mandate fetched from matchbot - mandate: Mandate = { - id: 'f7037101-b555-4482-afff-43145fac78bb', - campaignId: 'a056900002TPVz5AAH', - charityName: '0011r00002Hoe8lAAB', - donationAmount: { - amountInPence: 10_00, - currency: "GBP" - }, - matchedAmount: { - amountInPence: 10_00, - currency: "GBP" - }, - giftAid: false, - numberOfMatchedDonations: 3, - status: 'active', - schedule: { - type: "monthly", - dayOfMonth: 1, - activeFrom: '2024-12-06 11:00:17', - expectedNextPaymentDate: '2025-01-01 11:00:17' - } - }; }