From 594e0d42d1c6313bbffeb2949c465719d2c9adeb Mon Sep 17 00:00:00 2001 From: Thanakarn Klangkasame <77600906+Simulationable@users.noreply.github.com> Date: Thu, 2 Oct 2025 13:05:51 +0700 Subject: [PATCH] Change Redeem Page --- .../(public)/redeem/[transactionId]/page.tsx | 109 +++++++++--------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/src/app/(public)/redeem/[transactionId]/page.tsx b/src/app/(public)/redeem/[transactionId]/page.tsx index 3ff3da3..baaaba6 100644 --- a/src/app/(public)/redeem/[transactionId]/page.tsx +++ b/src/app/(public)/redeem/[transactionId]/page.tsx @@ -37,6 +37,7 @@ function getTenantKeyFromHost() { return process.env.NEXT_PUBLIC_DEFAULT_TENANT_KEY ?? "demo"; } +// แปลงเลขไทย→อารบิก แล้วเหลือเฉพาะ 0-9 เท่านั้น function toAsciiDigitsOnly(input: string) { const map: Record = { "๐": "0", "๑": "1", "๒": "2", "๓": "3", "๔": "4", @@ -46,10 +47,12 @@ function toAsciiDigitsOnly(input: string) { return thToEn.replace(/\D/g, ""); } +// รับเฉพาะเบอร์มือถือไทย 10 หลัก ที่ขึ้นต้นด้วย 06/08/09 function isStrictThaiMobile10(digitsOnly: string) { return /^0(6|8|9)\d{8}$/.test(digitsOnly); } +// รูปแบบที่ดูเหมือน +66/66xxxxx (ไม่อนุญาต) function looksLikeCountryCodeFormat(raw: string) { const t = raw.trim(); return t.startsWith("+66") || /^66\d+/.test(t); @@ -61,7 +64,7 @@ function looksLikeCountryCodeFormat(raw: string) { async function redeemPoints(input: { tenantKey: string; transactionId: string; - phoneDigits10: string; + phoneDigits10: string; // 0812345678 idempotencyKey: string; }): Promise { const res = await fetch(`${API_BASE}/api/v1/loyalty/redeem`, { @@ -100,6 +103,7 @@ export default function RedeemPage() { const [error, setError] = useState(null); const [result, setResult] = useState(null); + // Validation message const phoneError: string | null = useMemo(() => { if (!phoneDigits) return null; if (looksLikeCountryCodeFormat(phoneDigits)) { @@ -116,7 +120,7 @@ export default function RedeemPage() { const phoneValid = phoneDigits.length === 10 && !phoneError && isStrictThaiMobile10(phoneDigits); - // Input guards — allow only digits (รองรับเลขไทย) + // Guard input — digits only (รองรับเลขไทย) function handleChange(e: React.ChangeEvent) { const onlyDigits = toAsciiDigitsOnly(e.target.value).slice(0, 10); setPhoneDigits(onlyDigits); @@ -170,65 +174,54 @@ export default function RedeemPage() { } return ( -
- {/* Background: mono grid + soft lights */} -
-
-
- -
+
+
{/* Brand */}
-
- {/* Headings */} -

- Redeem Points -

+ {/* Heading */} +

Redeem Points

Transaction: {transactionId || "—"}

- {/* Card */} -
+ {/* Card — เรียบแต่เนี๊ยบขึ้น */} +
{!transactionId && (
ไม่พบ TransactionId ใน URL โปรดสแกน QR ใหม่
)} -
-
- -
- - {/* subtle input gloss */} - -
+ +
+ +
รองรับเฉพาะเบอร์โทรศัพท์มือถือ
@@ -242,36 +235,42 @@ export default function RedeemPage() { - {/* Result banners */} + {/* Banners */} {message && ( -
+
สะสมคะแนนสำเร็จ
)} {error && ( -
+
สะสมคะแนนไม่สำเร็จ
)} {result && ( -
-
รายละเอียด
+
+
รายละเอียด
{"balance" in result && ( -
ยอดคงเหลือใหม่: {result.balance}
+
+ ยอดคงเหลือใหม่: {result.balance} +
)} {"voucherCode" in result && ( -
รหัสคูปอง: {result.voucherCode}
+
+ รหัสคูปอง: {result.voucherCode} +
)} {"ledgerEntryId" in result && ( -
Ledger: {result.ledgerEntryId}
+
+ Ledger: {result.ledgerEntryId} +
)} {"redeemed" in result &&
สถานะ: {String(result.redeemed)}
}