"use client"; import Image from "@/components/ui/resilient-image"; import { useEffect, useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { MobileSlipHandoff } from "@/components/commission/mobile-slip-handoff"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; import { verificationError } from "@/lib/commission/verification-error"; export function CommissionPaymentForm({ checkoutId, amountBaht, qr, expiresAt, serverNow }: { checkoutId: string; amountBaht: number; qr: string | null; expiresAt: number; serverNow: number; }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); const [now, setNow] = useState(serverNow); const expired = now >= expiresAt; const secondsLeft = Math.max(0, Math.ceil((expiresAt - now) / 1000)); useEffect(() => { const timer = window.setInterval(() => setNow(Date.now()), 1000); return () => window.clearInterval(timer); }, []); async function submit(event: FormEvent) { event.preventDefault(); if (Date.now() >= expiresAt) { setNow(Date.now()); return; } setBusy(true); setError(""); try { const response = await fetch(`/api/commission/checkouts/${checkoutId}/verify`, { method: "POST", body: new FormData(event.currentTarget), }); const result = await response.json(); if (!response.ok) { if (result.error === "checkout-expired") setNow(Date.now()); throw new Error(verificationError(result.error)); } router.push(`/commission/tickets/${result.ticketId}`); } catch (cause) { setError(cause instanceof Error ? cause.message : "เกิดข้อผิดพลาด"); } finally { setBusy(false); } } if (expired || !qr) return หมดเวลาชำระเงิน

คำขอนี้หมดอายุแล้ว กรุณาสร้างคำขอใหม่

สร้างคำขอใหม่
; return <>สแกน PromptPay {/* Generated locally from the fixed checkout amount and configured recipient. */} {`PromptPay ฿{amountBaht}

ใช้มือถือเครื่องนี้ชำระเงิน: บันทึก QR แล้วเลือกรูปในแอปธนาคาร

โอนเงินแล้วอัปโหลดรูปสลิปเพื่อยืนยัน

เวลาชำระเงินที่เหลือ {String(Math.floor(secondsLeft / 60)).padStart(2, "0")}:{String(secondsLeft % 60).padStart(2, "0")}

อัปโหลดสลิปที่ชำระเงินแล้ว {error && {error}}
; }