"use client" import { useState } from "react" export function PaypalCancelButton() { const [loading, setLoading] = useState(false) async function handleClick() { if (!confirm("Cancel your PayPal subscription? You'll keep access until the end of the current billing period.")) { return } setLoading(true) const res = await fetch("/api/paypal/cancel", { method: "POST" }) const data = await res.json().catch(() => ({})) if (res.ok) { window.location.href = "/settings/billing?canceled=true" } else { setLoading(false) alert(data.error || "Could not cancel the subscription.") } } return ( ) }