ghostguild-org/app/config/contributions.js
Jennie Robinson Faber 0dd68ff1aa fix(display): cadence-aware contribution suffix across UI + admin dashboard
Add formatContribution helper in app/config/contributions.js and route
all member-facing and admin contribution displays through cadence-aware
expressions so annual members see /yr instead of /mo. Normalize annual
amounts to monthly equivalents in the admin dashboard revenue
aggregate now that contributionAmount is stored in cadence units.
2026-05-23 15:47:10 +01:00

31 lines
1.2 KiB
JavaScript

// Guidance presets for the contribution amount input.
// These are NOT tiers — just suggested amounts with matching guidance copy.
export const CONTRIBUTION_PRESETS = [
{ amount: 0, label: "I need support right now" },
{ amount: 5, label: "I can contribute" },
{ amount: 15, label: "I can sustain the community" },
{ amount: 30, label: "I can support others too" },
{ amount: 50, label: "I want to sponsor multiple members" },
]
export const requiresPayment = (amount) => amount > 0
export const isValidContributionAmount = (amount) =>
Number.isInteger(amount) && amount >= 0
export const getGuidanceLabel = (amount) => {
if (amount === null || amount === undefined) return null
const n = Number(amount)
if (!Number.isFinite(n) || n < 0) return null
const match = CONTRIBUTION_PRESETS.findLast(p => p.amount <= n)
return match?.label ?? null
}
// Format a contribution amount with cadence-aware suffix.
// amount is interpreted in cadence units (e.g. 180 + 'annual' → "$180/yr").
export const formatContribution = (amount, cadence) => {
const n = Number(amount) || 0
if (n === 0) return '$0'
const suffix = cadence === 'annual' ? '/yr' : '/mo'
return `$${n}${suffix}`
}