import { useState } from "react" import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query" import { api } from "../lib/api" import type { Webhook } from "@emberclone/shared" export default function Webhooks() { const queryClient = useQueryClient() const [url, setUrl] = useState("") const [event, setEvent] = useState("customer.created") const { data: webhooks, isLoading, isError } = useQuery({ queryKey: ["webhooks"], queryFn: () => api.listWebhooks() }) const createMutation = useMutation({ mutationFn: (payload: { url: string; event: string }) => api.createWebhook(payload), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["webhooks"] }) setUrl("") } }) const deleteMutation = useMutation({ mutationFn: (id: string) => api.deleteWebhook(id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ["webhooks"] }) } }) const testMutation = useMutation({ mutationFn: (id: string) => api.testWebhook(id), onSuccess: () => { alert("Test webhook sent successfully") }, onError: (error: any) => { alert(`Test failed: ${error.message || "Unknown error"}`) } }) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() if (!url.trim()) return createMutation.mutate({ url, event }) } if (isLoading) return
Loading webhooks...
if (isError) return
Error loading webhooks.
return (

Webhooks

Configure external notifications for system events

Create New Webhook

setUrl(e.target.value)} placeholder="https://your-api.com/webhook" />
{webhooks?.length === 0 && ( )} {webhooks?.map((webhook: Webhook) => ( ))}
Event URL Actions
No webhooks configured.
{webhook.event} {webhook.url}
) }