Skip to content

Commit 0d793de

Browse files
Show a fund's description under the fund on the giving form (#156)
Adds FundInterface.description and shows the selected fund's description as plain text under the fund on the giving form and fund links.
1 parent 6c60088 commit 0d793de

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎.changeset/fund-description.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@churchapps/helpers": minor
3+
"@churchapps/apphelper": minor
4+
---
5+
6+
Funds can carry an optional `description` (`FundInterface.description`). The giving form and fund giving links show it as plain text under the selected fund.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { act } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import { afterEach, describe, expect, it } from "vitest";
4+
import { FundDonation } from "../components/FundDonation";
5+
6+
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
7+
8+
const funds: any[] = [
9+
{ id: "F1", name: "Building", description: "New roof and <b>parking</b> lot" },
10+
{ id: "F2", name: "General" }
11+
];
12+
13+
let root: ReturnType<typeof createRoot> | null = null;
14+
const render = (fundId: string, hideFundSelect = false) => {
15+
const container = document.createElement("div");
16+
root = createRoot(container);
17+
act(() => {
18+
root!.render(<FundDonation fundDonation={{ fundId, amount: 25 }} funds={funds} index={0} updatedFunction={() => {}} hideFundSelect={hideFundSelect} />);
19+
});
20+
return container;
21+
};
22+
23+
describe("Fund description on the giving form", () => {
24+
afterEach(() => { act(() => root?.unmount()); root = null; });
25+
26+
it("shows the selected fund's description as plain text", () => {
27+
const el = render("F1").querySelector("[data-testid='fund-description']");
28+
expect(el?.textContent).toBe("New roof and <b>parking</b> lot");
29+
expect(el?.querySelector("b")).toBeNull();
30+
});
31+
32+
it("shows it on a fund giving link, where the fund select is hidden", () => {
33+
expect(render("F1", true).querySelector("[data-testid='fund-description']")?.textContent).toContain("New roof");
34+
});
35+
36+
it("shows nothing for a fund without a description", () => {
37+
expect(render("F2").querySelector("[data-testid='fund-description']")).toBeNull();
38+
});
39+
});

‎apphelper/src/donations/components/FundDonation.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ export const FundDonation: React.FC<Props> = (props) => {
4141
props.updatedFunction(fd, props.index);
4242
};
4343

44+
const description = props.funds.find((f) => f.id === props.fundDonation.fundId)?.description?.trim();
45+
4446
return (
4547
<>
46-
<Grid container spacing={1} alignItems="center" sx={{ mb: 2 }}>
48+
<Grid container spacing={1} alignItems="center" sx={{ mb: description ? 1 : 2 }}>
4749
<Grid size={{ xs: (props.removeFunction && props.hideFundSelect) ? 10 : 12, md: props.hideFundSelect ? (props.removeFunction ? 11 : 12) : 5 }}>
4850
<TextField fullWidth name="amount" label={Locale.label("donation.fundDonations.amount")} type="number" disabled={props.params?.amount && props.params.amount !== ""} aria-label="amount" lang="en-150" value={props.fundDonation.amount || ""} onChange={handleChange} InputProps={{ startAdornment: <Icon><Typography>{props.currency ? CurrencyHelper.getCurrencySymbol(props.currency) : "$"}</Typography></Icon> }} />
4951
</Grid>
@@ -65,6 +67,9 @@ export const FundDonation: React.FC<Props> = (props) => {
6567
</Grid>
6668
)}
6769
</Grid>
70+
{description && (
71+
<Typography variant="body2" color="text.secondary" data-testid="fund-description" sx={{ mb: 2, whiteSpace: "pre-line" }}>{description}</Typography>
72+
)}
6873
</>
6974
);
7075
};

‎helpers/src/interfaces/Donation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface DonationSummaryDonation {
4040
export interface FundInterface {
4141
id: string;
4242
name: string;
43+
description?: string | null;
4344
taxDeductible?: boolean;
4445
amount?: number;
4546
visible?: boolean;

0 commit comments

Comments
 (0)