ปัญหา: 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
151 lines
4.7 KiB
TypeScript
151 lines
4.7 KiB
TypeScript
import {
|
|
IconBrandFacebook,
|
|
IconBrandInstagram,
|
|
IconBrandLine,
|
|
IconCircleCheck,
|
|
IconExternalLink,
|
|
IconMail,
|
|
IconPhone,
|
|
IconTicket,
|
|
IconWorld,
|
|
} from "@tabler/icons-react";
|
|
|
|
import type { Cinema, ContactChannel } from "@/lib/cinemas";
|
|
import { resolveContact, type ContactKind } from "@/lib/contact-link";
|
|
import { COLORS } from "@/lib/design-tokens";
|
|
import { useI18n } from "@/lib/i18n";
|
|
import { translate } from "@/lib/i18n/messages";
|
|
|
|
/** ไอคอนตามชนิดช่องทาง (เดาจาก label ก่อน แล้วค่อยดูจาก kind/URL) */
|
|
function ChannelIcon({
|
|
label,
|
|
kind,
|
|
href,
|
|
}: {
|
|
label: string;
|
|
kind: ContactKind | null;
|
|
href: string | null;
|
|
}) {
|
|
const text = label.toLowerCase();
|
|
const url = (href ?? "").toLowerCase();
|
|
|
|
if (kind === "tel") return <IconPhone size={16} aria-hidden="true" />;
|
|
if (kind === "mailto") return <IconMail size={16} aria-hidden="true" />;
|
|
if (url.includes("facebook") || text.includes("facebook")) {
|
|
return <IconBrandFacebook size={16} aria-hidden="true" />;
|
|
}
|
|
if (url.includes("instagram") || text.includes("instagram")) {
|
|
return <IconBrandInstagram size={16} aria-hidden="true" />;
|
|
}
|
|
if (url.includes("line.me") || text.includes("line")) {
|
|
return <IconBrandLine size={16} aria-hidden="true" />;
|
|
}
|
|
if (
|
|
text.includes("จอง") ||
|
|
text.includes("book") ||
|
|
text.includes("ticket")
|
|
) {
|
|
return <IconTicket size={16} aria-hidden="true" />;
|
|
}
|
|
return <IconWorld size={16} aria-hidden="true" />;
|
|
}
|
|
|
|
function ContactRow({ channel }: { channel: ContactChannel }) {
|
|
const resolved = resolveContact(channel);
|
|
const value =
|
|
channel.value.trim() === "" ? (channel.href ?? "") : channel.value;
|
|
|
|
const body = (
|
|
<>
|
|
<span className="flex min-w-0 items-center gap-2">
|
|
<span className="text-[#999]">
|
|
<ChannelIcon
|
|
label={channel.label}
|
|
kind={resolved.kind}
|
|
href={resolved.href}
|
|
/>
|
|
</span>
|
|
<span className="truncate">{value}</span>
|
|
</span>
|
|
{resolved.external ? (
|
|
<IconExternalLink
|
|
size={16}
|
|
aria-hidden="true"
|
|
className="shrink-0 text-[#999]"
|
|
/>
|
|
) : null}
|
|
</>
|
|
);
|
|
|
|
const rowClass =
|
|
"flex min-h-11 items-center justify-between gap-3 rounded-lg text-sm transition-colors";
|
|
|
|
return (
|
|
<div className="flex flex-col gap-2">
|
|
<span className="text-sm text-[#999]">{channel.label}</span>
|
|
{resolved.href ? (
|
|
<a
|
|
href={resolved.href}
|
|
{...(resolved.external
|
|
? { target: "_blank", rel: "noopener noreferrer" }
|
|
: { rel: "nofollow" })}
|
|
className={`${rowClass} hover:text-[#D47272] focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#A92626]`}
|
|
>
|
|
{body}
|
|
</a>
|
|
) : (
|
|
// ไม่มีข้อมูลที่ใช้เป็นลิงก์ได้ — แสดงเป็นข้อความ ไม่หลอกให้กด
|
|
<span className={rowClass}>{body}</span>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** กล่องติดต่อ/จองตั๋ว — แต่ละส่วนซ่อนได้ถ้ายังไม่มีข้อมูล */
|
|
export function ContactPanel({ cinema }: { cinema: Cinema }) {
|
|
const { messages } = useI18n();
|
|
|
|
return (
|
|
<aside
|
|
className="flex flex-col justify-between gap-6 rounded-xl p-6"
|
|
style={{ border: `1px solid ${COLORS.border}` }}
|
|
>
|
|
<div className="flex flex-col gap-4">
|
|
<h2 className="text-2xl font-semibold leading-[1.3]">
|
|
{cinema.contact_heading?.trim() || messages.detail.contactTitle}
|
|
</h2>
|
|
|
|
{cinema.contacts.length === 0 ? (
|
|
<p className="text-sm text-[#999]">
|
|
{messages.detail.contactsFallback}
|
|
</p>
|
|
) : (
|
|
cinema.contacts.map((channel) => (
|
|
<ContactRow key={channel.label} channel={channel} />
|
|
))
|
|
)}
|
|
|
|
<div className="flex flex-col gap-3">
|
|
<span className="text-sm text-[#999]">
|
|
{messages.detail.paymentMethods}
|
|
</span>
|
|
{cinema.payments.length === 0 ? (
|
|
<span className="text-sm text-[#999]">
|
|
{messages.detail.paymentsFallback}
|
|
</span>
|
|
) : (
|
|
<div className="flex flex-wrap items-center gap-6">
|
|
{cinema.payments.map((payment) => (
|
|
<span key={payment} className="flex items-center gap-1 text-sm">
|
|
<IconCircleCheck size={16} />
|
|
{translate(messages.payments, payment)}
|
|
</span>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
);
|
|
}
|