"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { adminCancelTripAction } from "@/features/trip/actions"; interface AdminCancelTripButtonProps { tripId: string; } export function AdminCancelTripButton({ tripId }: AdminCancelTripButtonProps) { const router = useRouter(); const [open, setOpen] = useState(false); const [reason, setReason] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [result, setResult] = useState<{ refundCount: number; cancelledCount: number; skippedCount: number; } | null>(null); async function handleConfirm() { setLoading(true); setError(""); const res = await adminCancelTripAction(tripId, reason); setLoading(false); if ("error" in res && res.error) { setError(res.error); return; } if ("success" in res && res.success) { setResult({ refundCount: res.refundCount, cancelledCount: res.cancelledCount, skippedCount: res.skippedCount, }); router.refresh(); } } if (result) { return (

✅ Trip berhasil dibatalkan.

); } if (!open) { return ( ); } return (