feat(tip): add personalized payment success experience
This commit is contained in:
@@ -145,7 +145,6 @@ describe("TipScreen checkout", () => {
|
||||
["the selected plan is missing", { plans: [], selectedPlanId: "" }],
|
||||
["an order is being created", { isCreatingOrder: true }],
|
||||
["an order is being polled", { isPollingOrder: true }],
|
||||
["the order is paid", { isPaid: true }],
|
||||
] as const)("disables checkout when %s", (_label, overrides) => {
|
||||
mocks.payment = makePaymentState(overrides);
|
||||
renderScreen();
|
||||
@@ -153,6 +152,75 @@ describe("TipScreen checkout", () => {
|
||||
expect(getCheckoutButton().disabled).toBe(true);
|
||||
});
|
||||
|
||||
it("replaces checkout with the first Tip success experience", () => {
|
||||
mocks.payment = makePaymentState({
|
||||
status: "paid",
|
||||
isPaid: true,
|
||||
orderStatus: "paid",
|
||||
tipCount: 1,
|
||||
thankYouMessage: "A backend message that is not used for first Tip.",
|
||||
});
|
||||
renderScreen();
|
||||
|
||||
expect(container.querySelector('[data-testid="tip-checkout"]')).toBeNull();
|
||||
expect(container.textContent).toContain(
|
||||
"Did you really just buy me a coffee?",
|
||||
);
|
||||
expect(container.textContent).toContain("That honestly made me smile.");
|
||||
expect(container.textContent).toContain(
|
||||
"Thank you. I'll definitely think of you while I enjoy it.",
|
||||
);
|
||||
expect(document.activeElement?.id).toBe("tip-success-title");
|
||||
|
||||
const sendAgain = getButton("Send another coffee");
|
||||
act(() => sendAgain.click());
|
||||
expect(mocks.paymentDispatch).toHaveBeenCalledWith({
|
||||
type: "PaymentReset",
|
||||
});
|
||||
|
||||
expect(
|
||||
container
|
||||
.querySelector<HTMLAnchorElement>(
|
||||
'[data-analytics-key="tip.success_back_to_splash"]',
|
||||
)
|
||||
?.getAttribute("href"),
|
||||
).toBe("/characters/maya/splash");
|
||||
});
|
||||
|
||||
it("shows the repeat Tip count and backend thank-you message", () => {
|
||||
mocks.payment = makePaymentState({
|
||||
status: "paid",
|
||||
isPaid: true,
|
||||
orderStatus: "paid",
|
||||
tipCount: 22,
|
||||
thankYouMessage: "You always make my day sweeter.",
|
||||
});
|
||||
renderScreen();
|
||||
|
||||
expect(container.textContent).toContain(
|
||||
"This is the 22nd coffee you've treated me to.",
|
||||
);
|
||||
expect(container.textContent).toContain(
|
||||
"You always make my day sweeter.",
|
||||
);
|
||||
});
|
||||
|
||||
it("uses generic success copy when Tip metadata is incomplete", () => {
|
||||
mocks.payment = makePaymentState({
|
||||
status: "paid",
|
||||
isPaid: true,
|
||||
orderStatus: "paid",
|
||||
tipCount: 2,
|
||||
thankYouMessage: null,
|
||||
});
|
||||
renderScreen();
|
||||
|
||||
expect(container.textContent).toContain(
|
||||
"Thank you. Your coffee made me smile.",
|
||||
);
|
||||
expect(container.textContent).not.toContain("2nd coffee");
|
||||
});
|
||||
|
||||
function renderScreen(): void {
|
||||
act(() => root.render(<TipScreen />));
|
||||
}
|
||||
@@ -164,6 +232,14 @@ describe("TipScreen checkout", () => {
|
||||
if (!button) throw new Error("Missing Tip checkout button");
|
||||
return button;
|
||||
}
|
||||
|
||||
function getButton(label: string): HTMLButtonElement {
|
||||
const button = Array.from(
|
||||
container.querySelectorAll<HTMLButtonElement>("button"),
|
||||
).find((item) => item.textContent?.trim() === label);
|
||||
if (!button) throw new Error(`Missing button: ${label}`);
|
||||
return button;
|
||||
}
|
||||
});
|
||||
|
||||
function makePaymentState(
|
||||
@@ -180,6 +256,8 @@ function makePaymentState(
|
||||
currentOrderId: null,
|
||||
payParams: null,
|
||||
orderStatus: null,
|
||||
tipCount: null,
|
||||
thankYouMessage: null,
|
||||
errorMessage: null,
|
||||
launchNonce: 0,
|
||||
isLoadingPlans: false,
|
||||
|
||||
@@ -5,7 +5,9 @@ import type { PaymentPlanInput } from "@/data/schemas/payment/payment_plan";
|
||||
|
||||
import {
|
||||
findTipCoffeePlan,
|
||||
formatEnglishOrdinal,
|
||||
formatTipPrice,
|
||||
resolveTipSuccessCopy,
|
||||
} from "../tip-screen.helpers";
|
||||
|
||||
function makePlan(input: Partial<PaymentPlanInput>): PaymentPlan {
|
||||
@@ -73,4 +75,34 @@ describe("tip screen helpers", () => {
|
||||
expect(formatTipPrice(null, "medium")).toBe("US$ 9.99");
|
||||
expect(formatTipPrice(null, "large")).toBe("US$ 19.99");
|
||||
});
|
||||
|
||||
it.each([
|
||||
[2, "2nd"],
|
||||
[3, "3rd"],
|
||||
[11, "11th"],
|
||||
[12, "12th"],
|
||||
[13, "13th"],
|
||||
[21, "21st"],
|
||||
[22, "22nd"],
|
||||
])("formats %i as the English ordinal %s", (value, expected) => {
|
||||
expect(formatEnglishOrdinal(value)).toBe(expected);
|
||||
});
|
||||
|
||||
it("resolves first, repeat, and fallback success copy", () => {
|
||||
expect(resolveTipSuccessCopy(1, "Ignored for the first Tip")).toEqual({
|
||||
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.",
|
||||
],
|
||||
});
|
||||
expect(resolveTipSuccessCopy(22, "You made my day.")).toEqual({
|
||||
title: "This is the 22nd coffee you've treated me to.",
|
||||
body: ["You made my day."],
|
||||
});
|
||||
expect(resolveTipSuccessCopy(2, null)).toEqual({
|
||||
title: "Thank you. Your coffee made me smile.",
|
||||
body: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
.productCard,
|
||||
.paymentMethodSlot,
|
||||
.statusMessage,
|
||||
.successCard,
|
||||
.checkoutSlot {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
@@ -360,23 +359,7 @@
|
||||
box-shadow: 0 5px 14px rgba(248, 77, 150, 0.26);
|
||||
}
|
||||
|
||||
.successCard {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
margin-top: 16px;
|
||||
padding: 16px 18px;
|
||||
border: 1px solid rgba(118, 61, 55, 0.08);
|
||||
border-radius: 24px;
|
||||
background: rgba(255, 255, 255, 0.76);
|
||||
box-shadow: 0 16px 38px rgba(119, 72, 67, 0.09);
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
|
||||
.statusMessage,
|
||||
.successTitle,
|
||||
.successText {
|
||||
.statusMessage {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@@ -393,39 +376,6 @@
|
||||
margin-top: clamp(18px, 5.185vw, 28px);
|
||||
}
|
||||
|
||||
.successCard {
|
||||
justify-content: flex-start;
|
||||
border-color: rgba(255, 84, 135, 0.16);
|
||||
background: rgba(255, 246, 249, 0.86);
|
||||
color: #ff4f86;
|
||||
}
|
||||
|
||||
.successTitle {
|
||||
color: #25191b;
|
||||
font-size: 15px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.successText {
|
||||
margin-top: 2px;
|
||||
color: #8a686b;
|
||||
font-size: 13px;
|
||||
font-weight: 620;
|
||||
}
|
||||
|
||||
.successButton {
|
||||
margin-left: auto;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
padding: 9px 12px;
|
||||
background: #231719;
|
||||
color: #ffffff;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
font-weight: 850;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.checkoutSlot {
|
||||
margin-top: clamp(18px, 5.185vw, 28px);
|
||||
}
|
||||
|
||||
+17
-20
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useEffect, useMemo, useState, type CSSProperties } from "react";
|
||||
import Image from "next/image";
|
||||
import { Heart, Sparkles } from "lucide-react";
|
||||
import { Sparkles } from "lucide-react";
|
||||
|
||||
import { BackButton, CharacterAvatar } from "@/app/_components";
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
findTipCoffeePlan,
|
||||
formatTipPrice,
|
||||
} from "./tip-screen.helpers";
|
||||
import { TipSuccessView } from "./tip-success-view";
|
||||
import styles from "./tip-screen.module.css";
|
||||
|
||||
const TIP_ANALYTICS_CONTEXT: PaymentAnalyticsContext = {
|
||||
@@ -197,6 +198,21 @@ export function TipScreen({
|
||||
paymentDispatch({ type: "PaymentReset" });
|
||||
};
|
||||
|
||||
if (payment.isPaid) {
|
||||
return (
|
||||
<TipSuccessView
|
||||
characterName={character.displayName}
|
||||
characterAvatar={character.assets.avatar}
|
||||
characterCover={character.assets.cover}
|
||||
coffeeOption={coffeeOption}
|
||||
splashHref={characterRoutes.splash}
|
||||
tipCount={payment.tipCount}
|
||||
thankYouMessage={payment.thankYouMessage}
|
||||
onSendAgain={handleResetPaidState}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<MobileShell background="#fff5ed">
|
||||
<main
|
||||
@@ -288,25 +304,6 @@ export function TipScreen({
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{payment.isPaid ? (
|
||||
<section className={styles.successCard} aria-live="polite">
|
||||
<Heart size={18} aria-hidden="true" />
|
||||
<div>
|
||||
<p className={styles.successTitle}>Coffee sent</p>
|
||||
<p className={styles.successText}>
|
||||
Thank you. Your payment has been confirmed.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.successButton}
|
||||
onClick={handleResetPaidState}
|
||||
>
|
||||
Send again
|
||||
</button>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<div className={styles.checkoutSlot}>
|
||||
<TipCheckoutButton
|
||||
coffeeType={selectedCoffeeType}
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
.shell {
|
||||
position: relative;
|
||||
display: grid;
|
||||
min-height: var(--app-viewport-height, 100dvh);
|
||||
place-items: center;
|
||||
padding:
|
||||
calc(var(--app-safe-top, 0px) + clamp(24px, 7vw, 40px))
|
||||
calc(var(--app-safe-right, 0px) + clamp(18px, 5.5vw, 30px))
|
||||
calc(var(--app-safe-bottom, 0px) + clamp(24px, 7vw, 40px))
|
||||
calc(var(--app-safe-left, 0px) + clamp(18px, 5.5vw, 30px));
|
||||
overflow: hidden auto;
|
||||
background:
|
||||
radial-gradient(circle at 15% 18%, rgba(255, 183, 120, 0.28), transparent 30%),
|
||||
radial-gradient(circle at 87% 77%, rgba(244, 111, 151, 0.17), transparent 31%),
|
||||
#fff7f0;
|
||||
color: #2b1a1e;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.coverWash,
|
||||
.glowOne,
|
||||
.glowTwo {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.coverWash {
|
||||
inset: 0 0 auto;
|
||||
z-index: -3;
|
||||
height: min(47vh, 420px);
|
||||
background:
|
||||
linear-gradient(180deg, rgba(255, 247, 240, 0.48), #fff7f0 96%),
|
||||
var(--tip-success-cover) center 16% / cover no-repeat;
|
||||
filter: saturate(0.82);
|
||||
opacity: 0.32;
|
||||
}
|
||||
|
||||
.glowOne,
|
||||
.glowTwo {
|
||||
z-index: -2;
|
||||
border-radius: 999px;
|
||||
filter: blur(18px);
|
||||
}
|
||||
|
||||
.glowOne {
|
||||
top: 16%;
|
||||
right: -90px;
|
||||
width: 210px;
|
||||
height: 210px;
|
||||
background: rgba(255, 126, 157, 0.17);
|
||||
}
|
||||
|
||||
.glowTwo {
|
||||
bottom: 8%;
|
||||
left: -110px;
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
background: rgba(255, 188, 119, 0.2);
|
||||
}
|
||||
|
||||
.card {
|
||||
width: min(100%, 420px);
|
||||
box-sizing: border-box;
|
||||
padding: clamp(30px, 8vw, 44px) clamp(22px, 7vw, 36px) clamp(24px, 7vw, 36px);
|
||||
border: 1px solid rgba(88, 50, 55, 0.08);
|
||||
border-radius: clamp(28px, 8vw, 36px);
|
||||
background: rgba(255, 255, 255, 0.93);
|
||||
box-shadow: 0 28px 74px rgba(101, 61, 61, 0.14);
|
||||
text-align: center;
|
||||
backdrop-filter: blur(20px);
|
||||
}
|
||||
|
||||
.visual {
|
||||
position: relative;
|
||||
width: 164px;
|
||||
height: 140px;
|
||||
margin: 0 auto 16px;
|
||||
}
|
||||
|
||||
.avatarFrame {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 13px;
|
||||
width: 112px;
|
||||
height: 112px;
|
||||
border: 4px solid rgba(255, 255, 255, 0.98);
|
||||
border-radius: 999px;
|
||||
background: #f4d4c4;
|
||||
box-shadow: 0 17px 36px rgba(102, 54, 57, 0.18);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.coffeeFrame {
|
||||
position: absolute;
|
||||
right: 3px;
|
||||
bottom: 1px;
|
||||
width: 76px;
|
||||
height: 76px;
|
||||
border: 4px solid #ffffff;
|
||||
border-radius: 24px;
|
||||
background: #c69c80;
|
||||
box-shadow: 0 13px 28px rgba(86, 47, 42, 0.2);
|
||||
overflow: hidden;
|
||||
transform: rotate(3deg);
|
||||
}
|
||||
|
||||
.coffeeImage {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.sparkleOne,
|
||||
.sparkleTwo {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
color: #ef4f87;
|
||||
}
|
||||
|
||||
.sparkleOne {
|
||||
top: 5px;
|
||||
right: 6px;
|
||||
}
|
||||
|
||||
.sparkleTwo {
|
||||
bottom: 7px;
|
||||
left: 0;
|
||||
color: #f78a68;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
display: inline-flex;
|
||||
min-height: 32px;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
margin: 0;
|
||||
padding: 0 13px;
|
||||
border-radius: 999px;
|
||||
background: #fff0f4;
|
||||
color: #c74470;
|
||||
font-size: 12px;
|
||||
font-weight: 900;
|
||||
letter-spacing: 0.055em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.title {
|
||||
max-width: 340px;
|
||||
margin: 18px auto 0;
|
||||
color: #2b1a1e;
|
||||
font-family: var(--font-athelas), Georgia, serif;
|
||||
font-size: clamp(30px, 8vw, 42px);
|
||||
font-weight: 760;
|
||||
letter-spacing: -0.045em;
|
||||
line-height: 1.04;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.copy {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
max-width: 330px;
|
||||
margin: 16px auto 0;
|
||||
color: #756065;
|
||||
font-size: clamp(14px, 3.7vw, 17px);
|
||||
font-weight: 610;
|
||||
line-height: 1.55;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.copy p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: clamp(24px, 7vw, 34px);
|
||||
}
|
||||
|
||||
.primaryAction,
|
||||
.secondaryAction {
|
||||
display: inline-flex;
|
||||
min-height: 54px;
|
||||
box-sizing: border-box;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 999px;
|
||||
font: inherit;
|
||||
font-size: 15px;
|
||||
font-weight: 900;
|
||||
text-decoration: none;
|
||||
transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
|
||||
}
|
||||
|
||||
.primaryAction {
|
||||
border: 0;
|
||||
background: #2b1a1e;
|
||||
color: #ffffff;
|
||||
box-shadow: 0 14px 30px rgba(58, 29, 35, 0.2);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.secondaryAction {
|
||||
border: 1px solid rgba(67, 40, 45, 0.1);
|
||||
background: #faf6f4;
|
||||
color: #594349;
|
||||
}
|
||||
|
||||
.primaryAction:focus-visible,
|
||||
.secondaryAction:focus-visible {
|
||||
outline: 3px solid rgba(239, 79, 135, 0.28);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
.primaryAction:hover,
|
||||
.secondaryAction:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.primaryAction:hover {
|
||||
box-shadow: 0 17px 34px rgba(58, 29, 35, 0.24);
|
||||
}
|
||||
|
||||
.secondaryAction:hover {
|
||||
background: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.primaryAction:active,
|
||||
.secondaryAction:active {
|
||||
transform: translateY(1px) scale(0.99);
|
||||
}
|
||||
|
||||
@media (max-width: 350px) {
|
||||
.shell {
|
||||
padding-right: calc(var(--app-safe-right, 0px) + 14px);
|
||||
padding-left: calc(var(--app-safe-left, 0px) + 14px);
|
||||
}
|
||||
|
||||
.card {
|
||||
padding-right: 18px;
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.card {
|
||||
animation: cardReveal 0.46s cubic-bezier(0.22, 0.8, 0.32, 1) both;
|
||||
}
|
||||
|
||||
.avatarFrame {
|
||||
animation: avatarReveal 0.52s 0.08s cubic-bezier(0.2, 0.9, 0.28, 1.15) both;
|
||||
}
|
||||
|
||||
.coffeeFrame {
|
||||
animation: coffeeReveal 0.54s 0.16s cubic-bezier(0.2, 0.9, 0.28, 1.15) both;
|
||||
}
|
||||
|
||||
.sparkleOne,
|
||||
.sparkleTwo {
|
||||
animation: sparkleReveal 0.5s 0.34s ease both;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes cardReveal {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(14px) scale(0.985);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes avatarReveal {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(8px) scale(0.88);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes coffeeReveal {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translate(9px, 8px) rotate(8deg) scale(0.76);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translate(0, 0) rotate(3deg) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes sparkleReveal {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: scale(0.4) rotate(-10deg);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1) rotate(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, type CSSProperties } from "react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { Coffee, Heart, Sparkles } from "lucide-react";
|
||||
|
||||
import { CharacterAvatar } from "@/app/_components";
|
||||
import { MobileShell } from "@/app/_components/core";
|
||||
import type { TipCoffeeOption } from "@/lib/tip/tip_coffee";
|
||||
|
||||
import { resolveTipSuccessCopy } from "./tip-screen.helpers";
|
||||
import styles from "./tip-success-view.module.css";
|
||||
|
||||
export interface TipSuccessViewProps {
|
||||
characterName: string;
|
||||
characterAvatar: string;
|
||||
characterCover: string;
|
||||
coffeeOption: TipCoffeeOption;
|
||||
splashHref: string;
|
||||
tipCount: number | null;
|
||||
thankYouMessage: string | null;
|
||||
onSendAgain: () => void;
|
||||
}
|
||||
|
||||
export function TipSuccessView({
|
||||
characterName,
|
||||
characterAvatar,
|
||||
characterCover,
|
||||
coffeeOption,
|
||||
splashHref,
|
||||
tipCount,
|
||||
thankYouMessage,
|
||||
onSendAgain,
|
||||
}: TipSuccessViewProps) {
|
||||
const titleRef = useRef<HTMLHeadingElement>(null);
|
||||
const copy = resolveTipSuccessCopy(tipCount, thankYouMessage);
|
||||
|
||||
useEffect(() => {
|
||||
titleRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<MobileShell background="#fff7f0">
|
||||
<main
|
||||
className={styles.shell}
|
||||
style={
|
||||
{
|
||||
"--tip-success-cover": `url("${characterCover}")`,
|
||||
} as CSSProperties
|
||||
}
|
||||
>
|
||||
<div className={styles.coverWash} aria-hidden="true" />
|
||||
<div className={styles.glowOne} aria-hidden="true" />
|
||||
<div className={styles.glowTwo} aria-hidden="true" />
|
||||
|
||||
<section
|
||||
className={styles.card}
|
||||
aria-live="polite"
|
||||
aria-labelledby="tip-success-title"
|
||||
>
|
||||
<div className={styles.visual}>
|
||||
<span className={styles.sparkleOne} aria-hidden="true">
|
||||
<Sparkles size={22} strokeWidth={1.8} />
|
||||
</span>
|
||||
<span className={styles.sparkleTwo} aria-hidden="true">
|
||||
<Heart size={17} fill="currentColor" strokeWidth={1.8} />
|
||||
</span>
|
||||
<div className={styles.avatarFrame}>
|
||||
<CharacterAvatar
|
||||
src={characterAvatar}
|
||||
alt={characterName}
|
||||
size="100%"
|
||||
imageSize={112}
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<div className={styles.coffeeFrame}>
|
||||
<Image
|
||||
src={coffeeOption.image.src}
|
||||
alt={`${coffeeOption.displayName} coffee`}
|
||||
width={coffeeOption.image.width}
|
||||
height={coffeeOption.image.height}
|
||||
sizes="78px"
|
||||
className={styles.coffeeImage}
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className={styles.eyebrow}>
|
||||
<Coffee size={15} aria-hidden="true" />
|
||||
Coffee received
|
||||
</p>
|
||||
<h1
|
||||
ref={titleRef}
|
||||
id="tip-success-title"
|
||||
className={styles.title}
|
||||
tabIndex={-1}
|
||||
>
|
||||
{copy.title}
|
||||
</h1>
|
||||
{copy.body.length > 0 ? (
|
||||
<div className={styles.copy}>
|
||||
{copy.body.map((paragraph) => (
|
||||
<p key={paragraph}>{paragraph}</p>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className={styles.actions}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.primaryAction}
|
||||
data-analytics-key="tip.send_again"
|
||||
onClick={onSendAgain}
|
||||
>
|
||||
Send another coffee
|
||||
</button>
|
||||
<Link
|
||||
href={splashHref}
|
||||
className={styles.secondaryAction}
|
||||
data-analytics-key="tip.success_back_to_splash"
|
||||
>
|
||||
Back to {characterName}
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</MobileShell>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user