From 42572020d86dcc636edd5f3bae518da47f04bcd4 Mon Sep 17 00:00:00 2001 From: Bkk1234 Date: Sun, 15 Nov 2026 23:56:46 +0700 Subject: [PATCH] =?UTF-8?q?fix(contacts):=20=E0=B8=8A=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=E0=B8=87=E0=B8=97=E0=B8=B2=E0=B8=87=E0=B8=95=E0=B8=B4=E0=B8=94?= =?UTF-8?q?=E0=B8=95=E0=B9=88=E0=B8=AD=E0=B8=81=E0=B8=94=E0=B9=83=E0=B8=8A?= =?UTF-8?q?=E0=B9=89=E0=B9=84=E0=B8=94=E0=B9=89=E0=B8=88=E0=B8=A3=E0=B8=B4?= =?UTF-8?q?=E0=B8=87=20(tel:/mailto:/=E0=B9=82=E0=B8=8B=E0=B9=80=E0=B8=8A?= =?UTF-8?q?=E0=B8=B5=E0=B8=A2=E0=B8=A5)=20+=20=E0=B8=8B=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=E0=B8=A1=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5?= =?UTF-8?q?=E0=B9=80=E0=B8=94=E0=B8=B4=E0=B8=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ปัญหา: href ในข้อมูลดิบไม่สม่ำเสมอ (ว่าง / www. ไม่มี scheme / เบอร์ไม่มี tel: / facebook ติด fbclid) ทำให้กดแล้วไม่เกิดอะไร และปุ่มโทรใช้ไม่ได้ - app/lib/contact-link.ts: resolveContact() จับคู่ลิงก์ตามชนิด · เบอร์ → tel:+66… (แปลง 0 นำหน้า, ตัดขีด/ช่องว่าง/วงเล็บ) · อีเมล → mailto: · LINE @id → line.me · เว็บ → https + ตัด fbclid/_rdc/utm_* - ContactPanel: ไอคอนตามชนิด (phone/mail/fb/ig/line/ticket/globe), tel/mailto เปิดแท็บเดิม, เว็บเปิดแท็บใหม่; แถวที่ไม่มีลิงก์แสดงเป็นข้อความ (ไม่หลอกให้กด) - sanitizeCinemas: คำนวณ href ใหม่ทุกครั้งที่บันทึก → ข้อมูลเก่าไม่กลับมาเพี้ยน - ContactsEditor: auto-format ตอนออกจากช่อง + พรีวิว "✓ กดโทรได้ → tel:+66…" - scripts/audit-contacts.mjs [--fix]: ตรวจ/ซ่อมทั้งไฟล์ (แก้ไป 13 จุด, สำรองข้อมูลแล้ว) - contact-link.spec.ts 13 tests · docs: admin-guide/api/DESIGN --- DESIGN.md | 1 + app/components/admin/ContactsEditor.tsx | 51 ++++++- app/components/cinema/ContactPanel.tsx | 107 +++++++++++-- app/lib/contact-link.spec.ts | 120 +++++++++++++++ app/lib/contact-link.ts | 194 ++++++++++++++++++++++++ app/lib/content.server.ts | 11 +- docs/admin-guide.md | 16 +- docs/api.md | 2 +- scripts/audit-contacts.mjs | 180 ++++++++++++++++++++++ 9 files changed, 656 insertions(+), 26 deletions(-) create mode 100644 app/lib/contact-link.spec.ts create mode 100644 app/lib/contact-link.ts create mode 100644 scripts/audit-contacts.mjs diff --git a/DESIGN.md b/DESIGN.md index 98c8259..934f290 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -253,6 +253,7 @@ Single source of truth per concern — do not duplicate these: - ขนาดรูป: กว้างไม่เกิน **1600px** และบีบอัด (JPEG q82 / WebP q82) — โฟลเดอร์ `public/images/cinemas` ควรอยู่ราว **≤ 3 MB** - **ทุก `` ของโรงหนังต้องใช้ ``** (`app/components/site/PhotoImage.tsx`) — มี `onError` สลับไปโลโก้แทนรูปแตก และจำ `src` ที่พังเพื่อให้เปลี่ยนรูปใหม่แล้วโหลดได้อีก (ห้ามเขียน `` ตรง ๆ ใน component ใหม่) - **อัปโหลดจากหลังบ้าน**: `PhotosEditor` → `POST /api/admin/uploads` (multipart, ≤ 8 MB, ตรวจ magic bytes) → เก็บ `data/uploads/cinemas/` → คืน `/uploads/cinemas/--.` (gitignored) เสิร์ฟผ่าน Nitro route `server/routes/uploads/[...path].get.ts` — **ห้ามย้ายไปเขียนใน `public/`** เพราะตอน production โฟลเดอร์นั้นถูก copy ตอน build (เขียน runtime ไม่ติด) +- **ช่องทางติดต่อ (`contacts`)** — `href` **ต้องใช้ได้จริง** และถูกคำนวณใหม่ทุกครั้งที่บันทึกผ่าน `contactHref()` (`app/lib/contact-link.ts`): เบอร์ → `tel:+66…`, อีเมล → `mailto:`, เว็บ/โซเชียล → `https://` (ตัด `fbclid`/`_rdc`/`utm_*`, เปลี่ยน `web.facebook.com` → `www.facebook.com`), LINE ID `@x` → `line.me/R/ti/p/~x` · หน้าเว็บใช้ `resolveContact()` ตัวเดียวกัน — **ห้าม hardcode href ใน component** และห้ามแสดง `` ที่ไม่มี href (ให้แสดงเป็นข้อความแทน) · ตรวจ/ซ่อมทั้งไฟล์: `node scripts/audit-contacts.mjs [--fix]` - `app/lib/upload.ts` คือกติกากลาง (เพดานขนาด · ชนิดที่รับ · sanitize ชื่อ · กัน path traversal) — ใช้ทั้ง client และ server ห้ามประกาศซ้ำ ## ลำดับการ์ดหน้าแรก (สลับทุกวัน) diff --git a/app/components/admin/ContactsEditor.tsx b/app/components/admin/ContactsEditor.tsx index ef5d8eb..5f5b21d 100644 --- a/app/components/admin/ContactsEditor.tsx +++ b/app/components/admin/ContactsEditor.tsx @@ -1,6 +1,7 @@ import { IconPlus, IconTrash } from "@tabler/icons-react"; import type { ContactChannel } from "@/lib/cinemas"; +import { resolveContact } from "@/lib/contact-link"; /** * แก้ช่องทางติดต่อของการ์ด "สอบถามข้อมูลและจองตั๋ว" ต่อโรง @@ -27,7 +28,12 @@ type Props = { labelClass: string; }; -export function ContactsEditor({ contacts, onChange, inputClass, labelClass }: Props) { +export function ContactsEditor({ + contacts, + onChange, + inputClass, + labelClass, +}: Props) { function updateAt(index: number, patch: Partial) { onChange( contacts.map((item, i) => (i === index ? { ...item, ...patch } : item)), @@ -56,7 +62,9 @@ export function ContactsEditor({ contacts, onChange, inputClass, labelClass }: P value={contact.label} placeholder="Website" list="contact-label-options" - onChange={(event) => updateAt(index, { label: event.target.value })} + onChange={(event) => + updateAt(index, { label: event.target.value }) + } />
@@ -91,6 +111,23 @@ export function ContactsEditor({ contacts, onChange, inputClass, labelClass }: P
+ + {(() => { + const resolved = resolveContact(contact); + if (!resolved.href) { + return contact.value.trim() === "" + ? "ใส่ข้อความหรือเบอร์ก่อน — ระบบจะสร้างลิงก์ให้" + : "⚠ ค่านี้ยังใช้เป็นลิงก์ไม่ได้ (ต้องเป็นเบอร์ / อีเมล / โดเมน / URL)"; + } + const label = + resolved.kind === "tel" + ? "กดโทรได้" + : resolved.kind === "mailto" + ? "เปิดอีเมล" + : "เปิดเว็บ (แท็บใหม่)"; + return `✓ ${label} → ${resolved.href}`; + })()} + ))} @@ -103,7 +140,9 @@ export function ContactsEditor({ contacts, onChange, inputClass, labelClass }: P