"use client"; import { useFormState } from "react-dom"; import { createWebhookAction, createWebhookTourAction, deleteWebhookAction, deleteWebhookTourAction, type WebhookFormState, } from "../app/(app)/dashboard/actions"; type WebhookSummary = { id: string; url: string; events: string[]; event_urls?: Record | null; active: boolean; created_at: string; }; const initialState: WebhookFormState = { error: null, success: null }; const webhookEvents = [ { event: "invoice.created", key: "invoice_created", label: "invoice.created" }, { event: "invoice.payment_detected", key: "invoice_payment_detected", label: "invoice.payment_detected", }, { event: "invoice.confirmed", key: "invoice_confirmed", label: "invoice.confirmed" }, { event: "invoice.expired", key: "invoice_expired", label: "invoice.expired" }, ]; type WebhookSectionProps = { mode?: "live" | "tour"; webhooks: WebhookSummary[]; }; export default function WebhookSection({ mode = "live", webhooks }: WebhookSectionProps) { const [createState, createAction] = useFormState( mode === "tour" ? createWebhookTourAction : createWebhookAction, initialState ); const [deleteState, deleteAction] = useFormState( mode === "tour" ? deleteWebhookTourAction : deleteWebhookAction, initialState ); return (
{mode === "tour" ? (
Tour mode: webhook changes are simulated. No endpoints are saved.
) : null}

Used for any selected event without a specific override URL.

{webhookEvents.map(({ event, key, label }) => (
))}
{createState.error ? (

{createState.error}

) : null} {createState.success ? (

{createState.success}

) : null}

Hint

Webhooks are optional. You can poll{" "} /api/core/public/invoice/<invoice_id> without authentication to read invoice status.

Active webhooks

{deleteState.error ? (

{deleteState.error}

) : null} {deleteState.success ? (

{deleteState.success}

) : null} {webhooks.length === 0 ? (

No webhooks configured yet.

) : (
{webhooks.map((hook) => (

Webhook

{hook.url || "Per-event URLs only"}
{hook.events.map((event) => (
{event} {hook.event_urls?.[event] ?? hook.url}
))}
))}
)}
); }