From c57e88ee755e3ebdfcb0dc45a38666627a0fccdd Mon Sep 17 00:00:00 2001 From: Developing-Gamer Date: Tue, 2 Jun 2026 10:57:31 -0700 Subject: [PATCH] Extract shared purchase page pricing utilities. Move interval formatting, price labels, and free-price detection into reusable helpers for the checkout redesign. Co-authored-by: Cursor --- .../src/components/payments/purchase-utils.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 apps/dashboard/src/components/payments/purchase-utils.ts diff --git a/apps/dashboard/src/components/payments/purchase-utils.ts b/apps/dashboard/src/components/payments/purchase-utils.ts new file mode 100644 index 000000000..517e7c229 --- /dev/null +++ b/apps/dashboard/src/components/payments/purchase-utils.ts @@ -0,0 +1,43 @@ +export function shortenedInterval(interval: [number, string]): string { + if (interval[0] === 1) { + return interval[1]; + } + return `${interval[0]} ${interval[1]}s`; +} + +export function getPriceLabel(interval: [number, string] | undefined): string { + if (!interval) { + return "One-time"; + } + const [count, unit] = interval; + + if (count === 1) { + if (unit === "day") { + return "Daily"; + } else if (unit === "week") { + return "Weekly"; + } else if (unit === "month") { + return "Monthly"; + } else if (unit === "year") { + return "Yearly"; + } else { + return `Every ${unit}`; + } + } + + if (unit === "day") { + return `Every ${count} days`; + } else if (unit === "week") { + return `Once every ${count} weeks`; + } else if (unit === "month") { + return `Every ${count} months`; + } else if (unit === "year") { + return `Every ${count} years`; + } else { + return `Every ${count} ${unit}s`; + } +} + +export function isFreePrice(usd: string | undefined): boolean { + return usd === "0" || usd === "0.00"; +}