feat(tip): add coffee tipping page

This commit is contained in:
2026-07-08 19:21:42 +08:00
parent c1aba64573
commit cb7791dd8d
14 changed files with 1224 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
import type { LoginStatus } from "@/data/dto/auth";
import type { PaymentPlan } from "@/data/dto/payment";
const TIP_COFFEE_PLAN_ID = "tip_coffee";
const TIP_COFFEE_ORDER_TYPE = "tip_coffee";
export function findTipCoffeePlan(
plans: readonly PaymentPlan[],
): PaymentPlan | null {
return (
plans.find((plan) => plan.planId === TIP_COFFEE_PLAN_ID) ??
plans.find((plan) => plan.orderType === TIP_COFFEE_ORDER_TYPE) ??
null
);
}
export function formatTipPrice(plan: PaymentPlan | null): string {
if (!plan) return "US$ 5";
const amount = plan.amountCents / 100;
const formattedAmount = Number.isInteger(amount)
? String(amount)
: amount.toFixed(2).replace(/\.?0+$/, "");
const currency = plan.currency.trim().toUpperCase();
if (currency === "USD") return `US$ ${formattedAmount}`;
if (currency.length > 0) return `${currency} ${formattedAmount}`;
return formattedAmount;
}
export function isRealLoginStatus(loginStatus: LoginStatus): boolean {
return loginStatus !== "notLoggedIn" && loginStatus !== "guest";
}