"use client"; import { useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; import { MobileSlipHandoff } from "@/components/commission/mobile-slip-handoff"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; 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 }: { checkoutId: string }) { const router = useRouter(); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); async function submit(event: FormEvent) { event.preventDefault(); 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) throw new Error(verificationError(result.error)); router.push(`/commission/tickets/${result.ticketId}`); } catch (cause) { setError(cause instanceof Error ? cause.message : "เกิดข้อผิดพลาด"); } finally { setBusy(false); } } return
อัปโหลดสลิปที่ชำระเงินแล้ว {error && {error}}
; }