From af54c0d860be1a0bec28d3e9688abc0a8468b589 Mon Sep 17 00:00:00 2001
From: JOY <5027251+JOY@users.noreply.github.com>
Date: Sun, 22 Nov 2026 20:29:05 +0700
Subject: [PATCH] feat(campaigns): add dynamic OG card, QR poster, and
thank-you card (#313)
---
.../(public)/donations/[code]/page.test.ts | 12 +
.../app/(public)/donations/[code]/page.tsx | 32 +-
.../campaigns/[slug]/opengraph-image.test.ts | 149 ++++
.../app/campaigns/[slug]/opengraph-image.tsx | 306 ++++++++
.../web/src/app/campaigns/[slug]/page.test.ts | 50 +-
apps/web/src/app/campaigns/[slug]/page.tsx | 5 +-
.../web/src/app/me/contributions/page.test.ts | 92 ++-
apps/web/src/app/me/contributions/page.tsx | 82 ++-
.../src/assets/fonts/BeVietnamPro-Bold.ttf | Bin 0 -> 140300 bytes
.../src/assets/fonts/BeVietnamPro-Regular.ttf | Bin 0 -> 132948 bytes
apps/web/src/assets/fonts/OFL.txt | 93 +++
apps/web/src/components/DonationStatus.tsx | 16 +
.../web/src/components/QrPosterButton.test.ts | 196 +++++
apps/web/src/components/QrPosterButton.tsx | 157 ++++
.../src/components/ThankYouCardButton.test.ts | 153 ++++
.../web/src/components/ThankYouCardButton.tsx | 161 +++++
apps/web/src/components/ui/ModalDialog.tsx | 121 ++++
apps/web/src/components/ui/icons.tsx | 15 +
apps/web/src/lib/canvas-cards.ts | 678 ++++++++++++++++++
apps/web/src/lib/viral-sharing.test.ts | 370 ++++++++++
apps/web/src/lib/viral-sharing.ts | 364 ++++++++++
apps/web/src/server/contributions/index.ts | 13 +-
apps/web/src/server/viral-sharing.test.ts | 159 ++++
apps/web/src/server/viral-sharing.ts | 110 +++
24 files changed, 3307 insertions(+), 27 deletions(-)
create mode 100644 apps/web/src/app/campaigns/[slug]/opengraph-image.test.ts
create mode 100644 apps/web/src/app/campaigns/[slug]/opengraph-image.tsx
create mode 100644 apps/web/src/assets/fonts/BeVietnamPro-Bold.ttf
create mode 100644 apps/web/src/assets/fonts/BeVietnamPro-Regular.ttf
create mode 100644 apps/web/src/assets/fonts/OFL.txt
create mode 100644 apps/web/src/components/QrPosterButton.test.ts
create mode 100644 apps/web/src/components/QrPosterButton.tsx
create mode 100644 apps/web/src/components/ThankYouCardButton.test.ts
create mode 100644 apps/web/src/components/ThankYouCardButton.tsx
create mode 100644 apps/web/src/components/ui/ModalDialog.tsx
create mode 100644 apps/web/src/lib/canvas-cards.ts
create mode 100644 apps/web/src/lib/viral-sharing.test.ts
create mode 100644 apps/web/src/lib/viral-sharing.ts
create mode 100644 apps/web/src/server/viral-sharing.test.ts
create mode 100644 apps/web/src/server/viral-sharing.ts
diff --git a/apps/web/src/app/(public)/donations/[code]/page.test.ts b/apps/web/src/app/(public)/donations/[code]/page.test.ts
index 87400a6b..47cba1dc 100644
--- a/apps/web/src/app/(public)/donations/[code]/page.test.ts
+++ b/apps/web/src/app/(public)/donations/[code]/page.test.ts
@@ -109,6 +109,7 @@ describe("DonationPage (/donations/[code], DOS/Give#50)", () => {
expect(html).toContain("Bữa trưa cho em")
expect(html).toContain("GVABCDEFG")
expect(html).toContain("Đã nhận")
+ expect(html).toContain("Tải thẻ “Tôi đã chung tay”")
expect(html).toContain("Sao chép đường dẫn")
expect(html).toContain("Lưu đường dẫn theo dõi")
// Neither the SSR DOM attributes/text nor the DB select list exposes personal data or raw token.
@@ -247,5 +248,16 @@ describe("DonationPage for a monthly plan's donation (DOS/Give#276)", () => {
expect(html).toContain("Chiến dịch hiện không nhận chuyển khoản")
expect(html).not.toContain("0123456789")
+ expect(html).not.toContain("Tải thẻ “Tôi đã chung tay”")
+ })
+
+ it("hides the thank-you card button while awaiting transfer and shows it once received (DOS/Give#313)", async () => {
+ setUp(ownRow({ status: "awaiting_transfer", received_amount: 0 }))
+ const awaitingHtml = await render()
+ expect(awaitingHtml).not.toContain("Tải thẻ “Tôi đã chung tay”")
+
+ setUp(ownRow({ status: "received", received_amount: 200000, public_name: "Nguyễn Minh", is_anonymous: false }))
+ const receivedHtml = await render()
+ expect(receivedHtml).toContain("Tải thẻ “Tôi đã chung tay”")
})
})
diff --git a/apps/web/src/app/(public)/donations/[code]/page.tsx b/apps/web/src/app/(public)/donations/[code]/page.tsx
index 791b3b5c..f5d7afbc 100644
--- a/apps/web/src/app/(public)/donations/[code]/page.tsx
+++ b/apps/web/src/app/(public)/donations/[code]/page.tsx
@@ -10,6 +10,7 @@ import { Money } from "@/components/ui/Money"
import { RefCode } from "@/components/ui/RefCode"
import { siteOrigin } from "@/lib/auth/origin"
import { getSession } from "@/lib/auth/session"
+import { isPublicStatus, type CampaignStatus } from "@/lib/campaigns"
import { donationTrackingPath, qrExpiresAt } from "@/lib/contributions"
import { NEW_CODE_EVERY_MONTH, periodEnd, periodLabel, planDonationPayable, planQrUntil } from "@/lib/plans"
import { dbAs, dbService } from "@/lib/supabase"
@@ -65,13 +66,15 @@ function planQrCaption(until: Date, period: string): string {
* back; anyone else gets the not-found page, which explains where the page
* can be opened.
*/
-async function loadDonation(code: string): Promise<{ donation: PaymentContribution; guestToken: string | null }> {
+async function loadDonation(
+ code: string
+): Promise<{ donation: PaymentContribution; guestToken: string | null; donorDisplayName: string | null }> {
const session = await getSession()
let sessionRejected = false
if (session) {
try {
const own = await ownContribution(dbAs(session.accessToken), session.user.id, code)
- if (own) return { donation: own, guestToken: null }
+ if (own) return { donation: own, guestToken: null, donorDisplayName: session.user.name ?? null }
} catch (error) {
if (!isSessionRejected(error)) throw error
sessionRejected = true
@@ -79,7 +82,7 @@ async function loadDonation(code: string): Promise<{ donation: PaymentContributi
}
const token = donationCookieToken(await cookies(), code, hostnameFrom((await headers()).get("host")))
const guest = token ? await guestContribution(dbService(), code, token) : null
- if (guest && token) return { donation: guest, guestToken: token }
+ if (guest && token) return { donation: guest, guestToken: token, donorDisplayName: null }
if (sessionRejected) redirect(`/auth/login?return_path=${encodeURIComponent(`/donations/${code}`)}`)
notFound()
}
@@ -87,7 +90,7 @@ async function loadDonation(code: string): Promise<{ donation: PaymentContributi
export default async function DonationPage({ params }: { params: Promise<{ code: string }> }) {
const { code } = await params
if (!isDonationCode(code)) notFound()
- const { donation, guestToken } = await loadDonation(code)
+ const { donation, guestToken, donorDisplayName } = await loadDonation(code)
const service = dbService()
const campaign = await paymentCampaign(service, donation.campaign_id)
@@ -180,6 +183,21 @@ export default async function DonationPage({ params }: { params: Promise<{ code:
instructions = closedNote
}
+ const origin = siteOrigin()
+ const thankYou = isPublicStatus(campaign.status as CampaignStatus)
+ ? {
+ kind: "donation" as const,
+ campaignTitle: campaign.title,
+ campaignSlug: campaign.slug,
+ campaignType: campaign.type,
+ // Guest tracking views never expose donor PII; signed-in owners respect anonymity.
+ donorName: guestToken ? null : donation.is_anonymous ? null : donation.public_name?.trim() || donorDisplayName,
+ isAnonymous: guestToken ? false : donation.is_anonymous === true,
+ createdAt: donation.created_at,
+ origin,
+ }
+ : null
+
return (
@@ -227,10 +245,7 @@ export default async function DonationPage({ params }: { params: Promise<{ code:
Lưu đường dẫn theo dõi để xem trạng thái khoản ủng hộ này trên thiết bị khác trong 7 ngày. Đường dẫn
không chứa thông tin cá nhân.
-
+