"use client"; import { useEffect } from "react"; import { useFormState } from "react-dom"; import { useRouter } from "next/navigation"; import { redeliverWebhookDeliveryAction, redeliverWebhookDeliveryTourAction, type WebhookRedeliverState, } from "../app/(app)/dashboard/actions"; type WebhookDeliverySummary = { id: string; webhook_id: string | null; event: string; url: string; invoice_id: string | null; invoice_address: string | null; invoice_subaddress_index: number | null; invoice_amount_xmr: string | null; invoice_status: | "pending" | "payment_detected" | "confirmed" | "expired" | "invalid" | null; http_status: number | null; error_message: string | null; created_at: string; }; const initialState: WebhookRedeliverState = { error: null, success: null }; export default function WebhookHistoryPanel({ mode = "live", deliveries, }: { mode?: "live" | "tour"; deliveries: WebhookDeliverySummary[]; }) { const router = useRouter(); const [state, formAction] = useFormState( mode === "tour" ? redeliverWebhookDeliveryTourAction : redeliverWebhookDeliveryAction, initialState ); useEffect(() => { if (state.success && mode !== "tour") { router.refresh(); } }, [mode, router, state.success]); const formatTimestamp = (value: string) => new Date(value).toLocaleString(); return (
{state.error}
) : null} {state.success ? ({state.success}
) : null} {deliveries.length === 0 ? (No webhook calls recorded yet.
) : ({delivery.event}
{delivery.url}
{formatTimestamp(delivery.created_at)}
Invoice id
{delivery.invoice_id}
Subaddress
{delivery.invoice_address}
Subaddress index
{delivery.invoice_subaddress_index}
Invoice amount (XMR)
{delivery.invoice_amount_xmr}
Invoice status
{delivery.invoice_status}
Delivery error: {delivery.error_message}
) : null}