"use client"; import { useState } from "react"; import { ApiError, api } from "@/lib/api"; import { Button } from "@/components/Button"; /* Opens Paddle's hosted customer portal in a new tab. The account learns its * paddle_customer_id from its first paid subscription's webhook, so this reports * a plain message rather than erroring when there is no billing account yet. */ export function ManageBillingButton() { const [busy, setBusy] = useState(false); const [note, setNote] = useState(null); async function open() { setBusy(true); setNote(null); try { const { url } = await api.billingPortal(); window.open(url, "_blank", "noopener"); } catch (e) { setNote(e instanceof ApiError ? e.message : "Could not open billing."); } finally { setBusy(false); } } return ( {note && {note}} ); }