Skip to content

Commit 4a15668

Browse files
apphelper: fix login footer overlap, untranslated labels and reCAPTCHA bypass error (#126)
Login footer no longer overlaps on phones; leftover donation and sermon labels translated; "No saved payment methods." when a member has none; guest donation form honours the reCAPTCHA bypass.
1 parent f9664c9 commit 4a15668

12 files changed

Lines changed: 103 additions & 16 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@churchapps/apphelper": patch
3+
---
4+
5+
Fix the login footer overlapping on phones, translate leftover donation and sermon labels, show "No saved payment methods." when a member has none, and stop the guest donation form reporting a missing reCAPTCHA key when the captcha is bypassed.

‎apphelper/public/locales/en.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@
7575
"cover": "I'll generously add {} to cover the transaction fees so you can keep 100% of my donation.",
7676
"donate": "Donate",
7777
"editRecurring": "Edit Recurring Donation",
78+
"enterNewCard": "Enter new card",
7879
"fees": "Transaction fees of {} are applied.",
7980
"frequency": "Frequency",
8081
"fund": "Fund",
8182
"funds": "Funds",
83+
"loginToManage": "Login to manage existing donations",
8284
"make": "Make a Donation",
8385
"makeRecurring": "Make a Recurring Donation",
8486
"method": "Method",
@@ -88,6 +90,7 @@
8890
"preview": "Preview Donation",
8991
"quarterly": "Quarterly",
9092
"recurringUpdated": "Recurring donation updated.",
93+
"saveCard": "Save this card for future donations",
9194
"startDate": "Start Date",
9295
"thankYou": "Thank you for your donation!",
9396
"tooLow": "Donation amount must be greater than $0.50",
@@ -146,7 +149,7 @@
146149
"addCard": "Add Card",
147150
"confirmDelete": "Are you sure you wish to delete this payment method?",
148151
"deleted": "Payment method deleted.",
149-
"noMethod": "No Method",
152+
"noSavedMethods": "No saved payment methods.",
150153
"verify": "Verify Account"
151154
},
152155
"paypal": {
@@ -391,6 +394,10 @@
391394
},
392395
"zip": "Zip / Postal Code"
393396
},
397+
"sermon": {
398+
"back": "Back",
399+
"playlists": "Playlists"
400+
},
394401
"stockPhotos": {
395402
"photoBy": "Photo by:",
396403
"providedBy": "Stock photos provided by"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ const MultiGatewayDonationInner: React.FC<Props> = (props) => {
507507
))}
508508
{paymentProvider.capabilities.memberNewCard && (
509509
<MenuItem value="__new__">
510-
<Icon sx={{ mr: 1, fontSize: 18 }}>add_circle</Icon> Enter new card
510+
<Icon sx={{ mr: 1, fontSize: 18 }}>add_circle</Icon> {Locale.label("donation.donationForm.enterNewCard", "Enter new card")}
511511
</MenuItem>
512512
)}
513513
</Select>
@@ -524,7 +524,7 @@ const MultiGatewayDonationInner: React.FC<Props> = (props) => {
524524
<FormGroup sx={{ mt: 1 }}>
525525
<FormControlLabel
526526
control={<Checkbox checked={saveCard} onChange={(e) => setSaveCard(e.target.checked)} />}
527-
label="Save this card for future donations"
527+
label={Locale.label("donation.donationForm.saveCard", "Save this card for future donations")}
528528
/>
529529
</FormGroup>
530530
)}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React, { useState, useEffect } from "react";
44
import { ApiHelper } from "@churchapps/helpers";
55
import type { PaymentGateway } from "../helpers";
6+
import { Locale } from "../helpers";
67
import { getPaymentProvider, pickDefaultGateway } from "../providers";
78
import { Box, Typography } from "@mui/material";
89
import type { PaperProps } from "@mui/material/Paper";
@@ -49,7 +50,7 @@ export const NonAuthDonation: React.FC<Props> = ({ mainContainerCssProps, showHe
4950
{showHeader && (
5051
<Box sx={{ mb: 2 }}>
5152
<Typography variant="h5" component="h2" gutterBottom>
52-
Donate
53+
{Locale.label("donation.donationForm.donate", "Donate")}
5354
</Typography>
5455
</Box>
5556
)}
@@ -68,7 +69,7 @@ export const NonAuthDonation: React.FC<Props> = ({ mainContainerCssProps, showHe
6869
/>
6970
<Box sx={{ marginTop: "15px", fontSize: "14px" }}>
7071
<a href="/mobile/donate" style={{ color: "#1976d2" }}>
71-
Login to manage existing donations
72+
{Locale.label("donation.donationForm.loginToManage", "Login to manage existing donations")}
7273
</a>
7374
</Box>
7475
</Box>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const PaymentMethods: React.FC<Props> = (props) => {
150150
</TableBody>
151151
</Table>
152152
);
153-
} else return <div>{Locale.label("donation.paymentMethods.noMethod")}</div>;
153+
} else return <div>{Locale.label("donation.paymentMethods.noSavedMethods", "No saved payment methods.")}</div>;
154154
};
155155

156156
const provider = gateway ? getPaymentProvider(gateway.provider) : undefined;

‎apphelper/src/donations/helpers/Locale.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class Locale {
133133
"addCard": "Add Card",
134134
"confirmDelete": "Are you sure you wish to delete this payment method?",
135135
"deleted": "Payment method deleted.",
136-
"noMethod": "No payment methods. Add a payment method to make a donation.",
136+
"noSavedMethods": "No saved payment methods.",
137137
"verify": "Verify Account"
138138
},
139139
"preview": {
@@ -323,8 +323,13 @@ export class Locale {
323323
}
324324

325325
// Keep the old method for backward compatibility
326-
static label(key: string): string {
327-
return this.t(key);
326+
static label(key: string, fallback?: string): string {
327+
const translation = this.t(key);
328+
// If translation equals the key, it means no translation was found
329+
if (translation === key && fallback) {
330+
return fallback;
331+
}
332+
return translation;
328333
}
329334

330335
// Helper method to check if i18n is initialized

‎apphelper/src/helpers/Locale.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class Locale {
144144
"addCard": "Add Card",
145145
"confirmDelete": "Are you sure you wish to delete this payment method?",
146146
"deleted": "Payment method deleted.",
147-
"noMethod": "No payment methods. Add a payment method to make a donation.",
147+
"noSavedMethods": "No saved payment methods.",
148148
"verify": "Verify Account"
149149
},
150150
"page": {

‎apphelper/src/login/__tests__/loginFooterClearance.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ describe("Login footer clearance", () => {
6666
expect(inline.replace(/\s/g, "")).toContain("z-index:1");
6767
});
6868

69+
it("wraps its items and keeps side padding so they don't overlap on phone widths", () => {
70+
mountLogin(true);
71+
const inline = (document.getElementById("login-footer")!.getAttribute("style") || "").replace(/\s/g, "");
72+
expect(inline).toContain("flex-wrap:wrap");
73+
expect(inline).toContain("padding:12px72px");
74+
});
75+
6976
it("publishes the footer height as a CSS variable while mounted", () => {
7077
mountLogin(true);
7178
const footer = document.getElementById("login-footer") as HTMLElement;

‎apphelper/src/login/components/Login.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,21 @@ export const Login: React.FC<Props> = ({ mainContainerCssProps = {}, ...props })
264264
zIndex: 1,
265265
backgroundColor: "#f9fafb",
266266
borderTop: "1px solid #e5e7eb",
267-
padding: "16px",
267+
// Side padding keeps the links clear of a floating help bubble in
268+
// either bottom corner; wrapping stacks the items on phone widths
269+
// instead of letting them run into each other.
270+
padding: "12px 72px",
268271
display: "flex",
272+
flexWrap: "wrap",
269273
justifyContent: "center",
270274
alignItems: "center",
271-
gap: "24px",
275+
columnGap: "24px",
276+
rowGap: "8px",
277+
textAlign: "center",
272278
fontSize: "14px",
273279
color: "#6b7280"
274280
}}>
275-
<span style={{ marginRight: "8px" }}>Ministry that's supported, not sold</span>
281+
<span>Ministry that's supported, not sold</span>
276282
<a
277283
href="https://churchapps.org/partner"
278284
target="_blank"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from "react";
2+
import { act } from "react";
3+
import { createRoot, type Root } from "react-dom/client";
4+
import { afterEach, describe, expect, it, vi } from "vitest";
5+
6+
vi.mock("../../../donations", () => ({ NonAuthDonation: (props: { recaptchaSiteKey: string }) => <div data-testid="donation-form" data-sitekey={props.recaptchaSiteKey} /> }));
7+
vi.mock("../../helpers", () => ({ EnvironmentHelper: { init: () => {} } }));
8+
9+
import { NonAuthDonationWrapper } from "../donate/NonAuthDonationWrapper";
10+
11+
let container: HTMLDivElement | null = null;
12+
let root: Root | null = null;
13+
14+
const mount = (props: { recaptchaSiteKey?: string } = {}) => {
15+
container = document.createElement("div");
16+
document.body.appendChild(container);
17+
root = createRoot(container);
18+
act(() => { root!.render(<NonAuthDonationWrapper churchId="CHU1" {...props} />); });
19+
return container;
20+
};
21+
22+
afterEach(() => {
23+
if (root) act(() => { root!.unmount(); });
24+
container?.remove();
25+
root = null;
26+
container = null;
27+
vi.unstubAllEnvs();
28+
});
29+
30+
describe("NonAuthDonationWrapper reCAPTCHA site key", () => {
31+
it("shows the missing-key error when there is no key and no bypass", () => {
32+
vi.stubEnv("NEXT_PUBLIC_GOOGLE_RECAPTCHA_SITE_KEY", "");
33+
vi.stubEnv("NEXT_PUBLIC_BYPASS_RECAPTCHA", "");
34+
const el = mount();
35+
expect(el.textContent).toContain("reCAPTCHA site key is missing");
36+
expect(el.querySelector("[data-testid='donation-form']")).toBeNull();
37+
});
38+
39+
it("renders the form without the error when the captcha is bypassed", () => {
40+
vi.stubEnv("NEXT_PUBLIC_GOOGLE_RECAPTCHA_SITE_KEY", "");
41+
vi.stubEnv("NEXT_PUBLIC_BYPASS_RECAPTCHA", "true");
42+
const el = mount();
43+
expect(el.textContent).not.toContain("reCAPTCHA site key is missing");
44+
expect(el.querySelector("[data-testid='donation-form']")).not.toBeNull();
45+
});
46+
47+
it("passes a provided key through to the form", () => {
48+
vi.stubEnv("NEXT_PUBLIC_BYPASS_RECAPTCHA", "");
49+
const el = mount({ recaptchaSiteKey: "site-key" });
50+
expect(el.querySelector("[data-testid='donation-form']")?.getAttribute("data-sitekey")).toBe("site-key");
51+
});
52+
});

0 commit comments

Comments
 (0)