Skip to main content

max / makenotwork

1.3 KB · 35 lines History Blame Raw
1 // Pure price-mode logic (no DOM), imported by both the element and its test.
2
3 /** Which of the two prices the tier radios should carry. */
4 export type PriceMode = 'founder' | 'list';
5
6 /** The two prices a tier card publishes as data attributes. */
7 export interface TierPrices {
8 std: string | null;
9 founder: string | null;
10 }
11
12 /**
13 * The price a tier should carry in the given mode.
14 *
15 * Returns `null` when the card does not publish the price that mode needs, so
16 * the caller leaves the DOM alone rather than writing `undefined` into a form
17 * value the server computes on. That happens on a page rendered with the
18 * founder window shut, where there is no toggle and nothing should move.
19 */
20 export function priceFor(prices: TierPrices, mode: PriceMode): string | null {
21 const chosen = mode === 'founder' ? prices.founder : prices.std;
22 return chosen === null || chosen === '' ? null : chosen;
23 }
24
25 /**
26 * Render a monthly price the way the tier card writes it.
27 *
28 * Kept here rather than inlined so the test pins the format: the server
29 * renders the first one, the toggle renders every one after, and the two must
30 * agree or the price visibly reformats the first time somebody flips it.
31 */
32 export function formatMonthly(price: string): string {
33 return `$${price}/mo`;
34 }
35