import React, { FC } from "react"; import { currencyCodeToSymbol } from "../schema"; import { get as getEnv, getStr as getEnvStr } from "../env"; export interface IncomeGuidancePlan { value: string; label: string; amount: string | number; currency: string; frequency: string; allowCustomAmount?: boolean; incomeWeekly?: string; incomeMonthly?: string; } interface IncomeGuidanceProps { groupedPlans: Record; selected?: string; onSelect: (plan: IncomeGuidancePlan) => void; } const HEADING_ID = "income-guidance-heading"; // Names a free tier instead of pricing it when zero prices are hidden, as // the tier panels do. const feeLabel = (plan: IncomeGuidancePlan) => { if (getEnv("HIDE_ZERO_PRICE_DISPLAY") && Number(plan.amount) === 0) { return plan.label; } return `${currencyCodeToSymbol(plan.currency)}${plan.amount} ${plan.frequency}`; }; /** * Income bands against the plans they suggest, so people can see which tier * fits their income. Choosing a row selects that plan. */ export const IncomeGuidance: FC = ({ groupedPlans, selected, onSelect }) => { if (!getEnv("INCOME_GUIDANCE_ENABLED")) { return null; } // One row per tier. A tier offered in several currencies shows whichever // currency is currently chosen. const rows = Object.values(groupedPlans) .map((group) => group.find((plan) => plan.value === selected) || group[0]) .filter((plan) => plan.incomeWeekly || plan.incomeMonthly); if (!rows.length) { return null; } const showWeekly = rows.some((plan) => plan.incomeWeekly); const showMonthly = rows.some((plan) => plan.incomeMonthly); const heading = getEnvStr("INCOME_GUIDANCE_HEADING"); const note = getEnvStr("INCOME_GUIDANCE_NOTE"); return (
{heading && (

{heading}

)} {showWeekly && } {showMonthly && } {rows.map((plan) => { const chosen = plan.value === selected; return ( onSelect(plan)} > {showWeekly && ( )} {showMonthly && ( )} ); })}
Weekly incomeMonthly incomeSuggested dues
{plan.incomeWeekly}{plan.incomeMonthly}
{note && (
)}
); };