87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
import { ROUTES } from "@/router/routes";
|
|
|
|
export const TIP_COFFEE_TYPE_PARAM = "coffee_type";
|
|
export const DEFAULT_TIP_COFFEE_TYPE = "medium";
|
|
|
|
export type TipCoffeeType = "small" | "medium" | "large";
|
|
|
|
export interface TipCoffeeOption {
|
|
readonly type: TipCoffeeType;
|
|
readonly amountCents: number;
|
|
readonly displayName: string;
|
|
readonly image: {
|
|
readonly src: string;
|
|
readonly width: number;
|
|
readonly height: number;
|
|
};
|
|
readonly planId: string;
|
|
}
|
|
|
|
const TIP_COFFEE_OPTION_BY_TYPE: Record<TipCoffeeType, TipCoffeeOption> = {
|
|
small: {
|
|
type: "small",
|
|
amountCents: 499,
|
|
displayName: "Velvet Espresso",
|
|
image: {
|
|
src: "/images/tip/small.jpg",
|
|
width: 736,
|
|
height: 736,
|
|
},
|
|
planId: "tip_coffee_usd_4_99",
|
|
},
|
|
medium: {
|
|
type: "medium",
|
|
amountCents: 999,
|
|
displayName: "Gilded Heart",
|
|
image: {
|
|
src: "/images/tip/medium.png",
|
|
width: 1024,
|
|
height: 1024,
|
|
},
|
|
planId: "tip_coffee_usd_9_99",
|
|
},
|
|
large: {
|
|
type: "large",
|
|
amountCents: 1999,
|
|
displayName: "Crown Blossom",
|
|
image: {
|
|
src: "/images/tip/large.png",
|
|
width: 1024,
|
|
height: 1024,
|
|
},
|
|
planId: "tip_coffee_usd_19_99",
|
|
},
|
|
};
|
|
|
|
export const TIP_COFFEE_OPTIONS: readonly TipCoffeeOption[] = [
|
|
TIP_COFFEE_OPTION_BY_TYPE.small,
|
|
TIP_COFFEE_OPTION_BY_TYPE.medium,
|
|
TIP_COFFEE_OPTION_BY_TYPE.large,
|
|
];
|
|
|
|
export function resolveTipCoffeeType(
|
|
value: string | null | undefined,
|
|
): TipCoffeeType | null {
|
|
const normalized = value?.trim().toLowerCase();
|
|
if (
|
|
normalized === "small" ||
|
|
normalized === "medium" ||
|
|
normalized === "large"
|
|
) {
|
|
return normalized;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getTipCoffeeOption(type: TipCoffeeType): TipCoffeeOption {
|
|
return TIP_COFFEE_OPTION_BY_TYPE[type];
|
|
}
|
|
|
|
export function buildTipCoffeePath(
|
|
type: TipCoffeeType,
|
|
basePath: string = ROUTES.tip,
|
|
): string {
|
|
const params = new URLSearchParams({ [TIP_COFFEE_TYPE_PARAM]: type });
|
|
return `${basePath}?${params.toString()}`;
|
|
}
|