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"; +}