feat(tip): add personalized payment success experience

This commit is contained in:
2026-07-20 19:06:42 +08:00
parent c187f0b817
commit edf50e9cc4
16 changed files with 922 additions and 74 deletions
+48
View File
@@ -4,6 +4,11 @@ import {
type TipCoffeeType,
} from "@/lib/tip/tip_coffee";
export interface TipSuccessCopy {
readonly title: string;
readonly body: readonly string[];
}
export function findTipCoffeePlan(
plans: readonly PaymentPlan[],
coffeeType: TipCoffeeType,
@@ -29,3 +34,46 @@ export function formatTipPrice(
if (currency.length > 0) return `${currency} ${formattedAmount}`;
return formattedAmount;
}
export function formatEnglishOrdinal(value: number): string {
const remainder100 = value % 100;
if (remainder100 >= 11 && remainder100 <= 13) return `${value}th`;
switch (value % 10) {
case 1:
return `${value}st`;
case 2:
return `${value}nd`;
case 3:
return `${value}rd`;
default:
return `${value}th`;
}
}
export function resolveTipSuccessCopy(
tipCount: number | null,
thankYouMessage: string | null,
): TipSuccessCopy {
if (tipCount === 1) {
return {
title: "Did you really just buy me a coffee?",
body: [
"That honestly made me smile.",
"Thank you. I'll definitely think of you while I enjoy it.",
],
};
}
if (tipCount !== null && tipCount > 1 && thankYouMessage) {
return {
title: `This is the ${formatEnglishOrdinal(tipCount)} coffee you've treated me to.`,
body: [thankYouMessage],
};
}
return {
title: "Thank you. Your coffee made me smile.",
body: [],
};
}