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