Skip to content

Commit

Permalink
Merge pull request #1801 from thebiggive/DON-998-fetch-one-mandate-fr…
Browse files Browse the repository at this point in the history
…om-matchbot

DON-998: add resolver for an single mandate
  • Loading branch information
dorota-joanna authored Dec 16, 2024
2 parents 6bb8ddf + 8ab2e08 commit c52040c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 41 deletions.
19 changes: 12 additions & 7 deletions src/app/app-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -73,6 +74,16 @@ const LoggedInPersonResolver: ResolveFn<Person | null> = async () => {
return await firstValueFrom(person$);
}

const mandateResolver: ResolveFn<Mandate> = 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: '',
Expand Down Expand Up @@ -283,13 +294,7 @@ if (flags.regularGivingEnabled) {
requireLogin,
],
resolve: {
/**
* need similar method but for one mandate
*/
// mandates: () => {
// inject(MandateService).getActiveMandate(mandateId),
// }

mandate: mandateResolver,
},
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/app/mandate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -32,7 +31,7 @@ export class MandateService {
}));
}

getActiveMandate(regularGivingCampaignId: Campaign) {
getActiveMandate(mandateId: string) {
const jwt = this.identityService.getJWT();
const person$ = this.identityService.getLoggedInPerson();

Expand All @@ -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));
}));
Expand Down
45 changes: 14 additions & 31 deletions src/app/mandate/mandate.component.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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'
}
};
}

0 comments on commit c52040c

Please sign in to comment.