import Link from 'next/link' import { notFound } from 'next/navigation' import type { Metadata } from 'next' import { CheckCircle2, Clock, PackageCheck, Truck } from 'lucide-react' import { formatPrice } from '@homaroma/types' import DynamicPageRenderer from '../../../components/dynamic/DynamicPageRenderer' import { getCategoriesResult, getCmsPageResult, getOrderResult } from '../../../lib/cms' import { splitCmsLayoutSections } from '../../../lib/cms-sections' const lang = 'th' function orderLabel(id: number) { return `#${id.toString().padStart(4, '0')}` } function statusLabel(status: string) { const labels: Record = { PENDING_PAYMENT: 'รอชำระเงิน', PAID: 'ชำระเงินแล้ว', PROCESSING: 'กำลังจัดเตรียมสินค้า', SHIPPED: 'จัดส่งแล้ว', DELIVERED: 'จัดส่งสำเร็จ', CANCELLED: 'ยกเลิกแล้ว', } return labels[status] ?? status.replaceAll('_', ' ') } function statusTone(status: string) { if (status === 'PENDING_PAYMENT') return 'bg-amber-50 text-amber-700 border-amber-100' if (status === 'PAID' || status === 'PROCESSING') return 'bg-emerald-50 text-emerald-700 border-emerald-100' if (status === 'SHIPPED' || status === 'DELIVERED') return 'bg-sky-50 text-sky-700 border-sky-100' if (status === 'CANCELLED') return 'bg-rose-50 text-rose-700 border-rose-100' return 'bg-gray-50 text-gray-700 border-gray-100' } export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise { const { id } = await params const result = await getOrderResult(id) if (!result.ok) return { title: 'Order Not Found | HomAroma' } return { title: `Order ${orderLabel(result.data.id)} | HomAroma`, description: `ตรวจสอบสถานะคำสั่งซื้อ ${orderLabel(result.data.id)} จาก HomAroma`, } } export default async function OrderStatusPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params const [orderResult, categoriesResult, cmsLayoutResult] = await Promise.all([ getOrderResult(id), getCategoriesResult(lang), getCmsPageResult('order-success-layout', lang), ]) const categories = categoriesResult.ok ? categoriesResult.data : [] const cmsSections = cmsLayoutResult.ok ? cmsLayoutResult.data.sections ?? [] : [] const { announcementSections, bottomSections } = splitCmsLayoutSections(cmsSections) if (!cmsLayoutResult.ok && cmsLayoutResult.status !== 404) { console.error(`[website-cms] order-success-layout unavailable: ${cmsLayoutResult.error}`) } if (!orderResult.ok) { if (orderResult.status === 404) notFound() return (
{announcementSections.length > 0 && ( )}

ไม่สามารถโหลดคำสั่งซื้อนี้ได้

{orderResult.error}

กลับไปค้นหาคำสั่งซื้อ
) } const order = orderResult.data const subtotal = order.subtotal ?? Math.max(0, order.totalAmount - order.shippingFee) return (
{announcementSections.length > 0 && ( )}

Order Status

{orderLabel(order.id)}

คำสั่งซื้อของคุณถูกบันทึกแล้ว สามารถตรวจสอบสถานะล่าสุดได้จากหน้านี้

Created

{new Date(order.createdAt).toLocaleDateString('th-TH')}

Status

{statusLabel(order.status)}

Tracking No.

{order.trackingNo || 'อยู่ระหว่างจัดเตรียมพัสดุ'}

Order Items

{order.items.map((item) => (
{item.productName}

{item.productName}

{item.variantSize ? `${item.variantSize} · ` : ''}x {item.quantity}

{formatPrice(item.priceAtPurchase * item.quantity)}

))}
Subtotal {formatPrice(subtotal)}
Shipping Fee {formatPrice(order.shippingFee)}
{(order.discountAmount ?? 0) > 0 && (
Discount{order.couponCode ? ` (${order.couponCode})` : ''} -{formatPrice(order.discountAmount)}
)}
Total {formatPrice(order.totalAmount)}
{order.status === 'PENDING_PAYMENT' && (

คำสั่งซื้อนี้ยังรอการชำระเงิน

หน้านี้รองรับการตรวจสอบสถานะคำสั่งซื้อแล้ว ส่วนการชำระเงินและอัปโหลดสลิปบน website จะย้ายมาในรอบถัดไป เพื่อไม่ทำ workaround ที่เสี่ยงกับ payment flow

)}
ค้นหาออเดอร์อื่น กลับไปช้อปต่อ
{bottomSections.length > 0 && ( )}
) }