feat(contributions): rewrite client config as preset-based helpers

This commit is contained in:
Jennie Robinson Faber 2026-04-19 18:07:43 +01:00
parent 4da0265935
commit 62c606b30a
2 changed files with 96 additions and 19 deletions

View file

@ -1,22 +1,22 @@
// Central configuration for Ghost Guild Contribution Levels
export const CONTRIBUTION_TIERS = {
FREE: { value: "0", amount: 0, label: "$0 - I need support right now", tier: "free" },
SUPPORTER: { value: "5", amount: 5, label: "$5 - I can contribute", tier: "supporter" },
MEMBER: { value: "15", amount: 15, label: "$15 - I can sustain the community", tier: "member" },
ADVOCATE: { value: "30", amount: 30, label: "$30 - I can support others too", tier: "advocate" },
CHAMPION: { value: "50", amount: 50, label: "$50 - I want to sponsor multiple members", tier: "champion" },
}
// 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 getContributionOptions = () => Object.values(CONTRIBUTION_TIERS)
export const getValidContributionValues = () => Object.values(CONTRIBUTION_TIERS).map(t => t.value)
export const getContributionTierByValue = (value) =>
Object.values(CONTRIBUTION_TIERS).find(t => t.value === value)
export const requiresPayment = (value) => (getContributionTierByValue(value)?.amount ?? 0) > 0
export const isValidContributionValue = (value) => getValidContributionValues().includes(value)
export const getPaidContributionTiers = () =>
Object.values(CONTRIBUTION_TIERS).filter(t => t.amount > 0)
export const requiresPayment = (amount) => Number(amount) > 0
export function getTierAmount(tier, cadence = 'monthly') {
const base = parseFloat(tier.amount)
return cadence === 'annual' ? base * 10 : base
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].reverse().find(p => p.amount <= n)
return match?.label ?? null
}