mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
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 <cursoragent@cursor.com>
This commit is contained in:
parent
a2a14833ee
commit
c57e88ee75
43
apps/dashboard/src/components/payments/purchase-utils.ts
Normal file
43
apps/dashboard/src/components/payments/purchase-utils.ts
Normal file
@ -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";
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user