Spaces:
Sleeping
Sleeping
Download src/pages/Webhooks.tsx from sitcod3/BRIDGE_Modul-S_prod: direct link, hf CLI and curl.
- Browser
- Download file 14.9 kB
-
https://huggingface.co/spaces/sitcod3/BRIDGE_Modul-S_prod/resolve/main/src/pages/Webhooks.tsx
- Command line
-
hf download hf://spaces/sitcod3/BRIDGE_Modul-S_prod/src/pages/Webhooks.tsx
-
curl -L -o Webhooks.tsx https://huggingface.co/spaces/sitcod3/BRIDGE_Modul-S_prod/resolve/main/src/pages/Webhooks.tsx
14.9 kB
| import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; | |
| import { apiClient } from "../lib/apiClient"; | |
| import { | |
| Webhook, | |
| Plus, | |
| Play, | |
| Trash2, | |
| CheckCircle2, | |
| AlertCircle, | |
| Code, | |
| ExternalLink, | |
| Copy, | |
| Terminal | |
| } from "lucide-react"; | |
| import { useState } from "react"; | |
| import StatusBadge from "../components/StatusBadge"; | |
| import FormDrawer from "../components/FormDrawer"; | |
| import ConfirmModal from "../components/ConfirmModal"; | |
| import toast from "react-hot-toast"; | |
| const AVAILABLE_EVENTS = [ | |
| { id: "EMAIL_REPLIED", label: "Email Replied" }, | |
| { id: "EMAIL_OPENED", label: "Email Opened" }, | |
| { id: "EMAIL_CLICKED", label: "Link Clicked" }, | |
| { id: "EMAIL_BOUNCED", label: "Email Bounced" }, | |
| { id: "LEAD_CATEGORY_UPDATED", label: "Lead Category Updated" }, | |
| { id: "EMAIL_UNSUBSCRIBED", label: "Lead Unsubscribed" }, | |
| { id: "CAMPAIGN_COMPLETED", label: "Campaign Completed" }, | |
| ]; | |
| export default function Webhooks() { | |
| const queryClient = useQueryClient(); | |
| const [isCreateOpen, setIsCreateOpen] = useState(false); | |
| const [selectedForDelete, setSelectedForDelete] = useState<string | null>(null); | |
| const [testExecutionResult, setTestExecutionResult] = useState<any | null>(null); | |
| const { data: webhooks = [], isLoading, refetch } = useQuery({ | |
| queryKey: ["webhooks"], | |
| queryFn: async () => { | |
| const res = await apiClient.get("/webhooks"); | |
| return res.data; | |
| }, | |
| }); | |
| const { data: campaigns = [] } = useQuery({ | |
| queryKey: ["campaigns"], | |
| queryFn: async () => { | |
| const res = await apiClient.get("/campaigns"); | |
| return res.data; | |
| }, | |
| }); | |
| const testFireMutation = useMutation({ | |
| mutationFn: async (id: string) => { | |
| const res = await apiClient.post(`/webhooks/${id}/test`); | |
| return res.data; | |
| }, | |
| onSuccess: (data) => { | |
| toast.success("Webhook test payload dispatched!"); | |
| setTestExecutionResult(data); | |
| }, | |
| onError: () => { | |
| toast.error("Failed to fire test webhook"); | |
| }, | |
| }); | |
| const deleteMutation = useMutation({ | |
| mutationFn: async (id: string) => { | |
| const res = await apiClient.delete(`/webhooks/${id}`); | |
| return res.data; | |
| }, | |
| onSuccess: () => { | |
| toast.success("Webhook endpoint removed"); | |
| setSelectedForDelete(null); | |
| refetch(); | |
| }, | |
| }); | |
| return ( | |
| <div className="p-4 md:p-6 max-w-7xl mx-auto space-y-10 animate-fadeIn"> | |
| {/* Header */} | |
| <div className="flex flex-col md:flex-row md:items-center justify-between gap-6"> | |
| <div className="space-y-2"> | |
| <div className="flex items-center gap-2 text-[10px] font-bold uppercase tracking-widest text-zinc-500 font-mono"> | |
| <span>External Connectivity</span> | |
| <span className="text-zinc-700">/</span> | |
| <span className="text-zinc-400">REST Integration Gateway</span> | |
| </div> | |
| <h1 className="text-3xl font-bold tracking-tight text-white font-sans flex items-center gap-3"> | |
| <Webhook className="w-8 h-8 text-emerald-400" /> | |
| Event Webhooks | |
| </h1> | |
| <p className="text-zinc-400 text-sm max-w-xl leading-relaxed"> | |
| Stream real-time outreach events directly to your CRM, Slack, Zapier, or private backend clusters via HTTPS callbacks. | |
| </p> | |
| </div> | |
| <button | |
| onClick={() => setIsCreateOpen(true)} | |
| className="px-6 py-2.5 bg-emerald-500 hover:bg-emerald-400 text-zinc-950 text-xs font-bold rounded-xl transition-all shadow-[0_4px_20px_-4px_rgba(0,229,188,0.4)] flex items-center gap-2 active:scale-95" | |
| > | |
| <Plus className="w-4 h-4" /> Provision Webhook | |
| </button> | |
| </div> | |
| {/* Webhooks Table */} | |
| <div className="bg-zinc-900/30 border border-white/5 backdrop-blur-md rounded-2xl overflow-hidden shadow-2xl"> | |
| <div className="overflow-x-auto"> | |
| <table className="w-full text-sm text-left"> | |
| <thead className="bg-black/20 border-b border-white/5 text-zinc-500 text-[10px] font-bold uppercase tracking-widest"> | |
| <tr> | |
| <th className="px-6 py-4">Destination Endpoint</th> | |
| <th className="px-6 py-4">Campaign Scope</th> | |
| <th className="px-6 py-4">Trigger Matrix</th> | |
| <th className="px-6 py-4">Status</th> | |
| <th className="px-6 py-4 text-right">Operational Controls</th> | |
| </tr> | |
| </thead> | |
| <tbody className="divide-y divide-white/5"> | |
| {webhooks.map((hook: any) => ( | |
| <tr key={hook.id} className="hover:bg-white/[0.02] transition-colors group"> | |
| <td className="px-6 py-5"> | |
| <div className="flex items-center gap-3"> | |
| <div className="p-2 rounded-lg bg-zinc-950 border border-white/5 text-zinc-400 group-hover:text-emerald-400 transition-colors"> | |
| <Terminal className="w-4 h-4" /> | |
| </div> | |
| <div className="flex items-center gap-2"> | |
| <span className="font-mono text-[11px] text-zinc-200 font-bold tracking-tight"> | |
| {hook.target_url} | |
| </span> | |
| <button | |
| onClick={() => { | |
| navigator.clipboard.writeText(hook.target_url); | |
| toast.success("Copied webhook URL"); | |
| }} | |
| className="text-zinc-600 hover:text-zinc-300 p-1 transition-colors" | |
| > | |
| <Copy className="w-3.5 h-3.5" /> | |
| </button> | |
| </div> | |
| </div> | |
| </td> | |
| <td className="px-6 py-5"> | |
| <span className="text-[10px] font-bold uppercase tracking-widest text-zinc-400 font-mono"> | |
| {hook.campaign_id ? `CLUSTER: ${hook.campaign_id}` : "GLOBAL FLEET"} | |
| </span> | |
| </td> | |
| <td className="px-6 py-5"> | |
| <div className="flex flex-wrap gap-1.5 max-w-xs"> | |
| {hook.event_types?.map((ev: string) => ( | |
| <span | |
| key={ev} | |
| className="px-2 py-0.5 bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 rounded text-[9px] font-bold uppercase tracking-widest font-mono" | |
| > | |
| {ev} | |
| </span> | |
| ))} | |
| </div> | |
| </td> | |
| <td className="px-6 py-5"> | |
| <StatusBadge status={hook.status || "ACTIVE"} size="sm" /> | |
| </td> | |
| <td className="px-6 py-5 text-right"> | |
| <div className="flex items-center justify-end gap-2"> | |
| <button | |
| onClick={() => testFireMutation.mutate(hook.id)} | |
| disabled={testFireMutation.isPending} | |
| className="px-4 py-1.5 bg-zinc-950 border border-white/5 hover:border-emerald-500/40 text-zinc-400 hover:text-emerald-400 text-[10px] font-bold uppercase tracking-widest rounded-xl transition-all flex items-center gap-2 active:scale-95" | |
| > | |
| <Play className="w-3 h-3" /> Test Dispatch | |
| </button> | |
| <button | |
| onClick={() => setSelectedForDelete(hook.id)} | |
| className="p-2 bg-zinc-950 border border-white/5 hover:border-rose-500/40 text-zinc-600 hover:text-rose-400 rounded-xl transition-all" | |
| > | |
| <Trash2 className="w-3.5 h-3.5" /> | |
| </button> | |
| </div> | |
| </td> | |
| </tr> | |
| ))} | |
| {webhooks.length === 0 && ( | |
| <tr> | |
| <td colSpan={5} className="py-20 text-center"> | |
| <div className="flex flex-col items-center gap-3"> | |
| <div className="p-4 rounded-full bg-zinc-950 border border-white/5 text-zinc-700"> | |
| <Webhook className="w-8 h-8" /> | |
| </div> | |
| <span className="text-[10px] font-bold uppercase tracking-widest text-zinc-600 font-mono"> | |
| No active relay nodes configured | |
| </span> | |
| </div> | |
| </td> | |
| </tr> | |
| )} | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| {/* Test Fire Response Inspector */} | |
| {testExecutionResult && ( | |
| <div className="bg-zinc-950 border border-white/5 rounded-2xl p-8 shadow-2xl space-y-6 animate-fadeIn"> | |
| <div className="flex items-center justify-between"> | |
| <h3 className="text-[10px] font-bold text-emerald-400 flex items-center gap-3 uppercase tracking-widest font-mono"> | |
| <Terminal className="w-5 h-5" /> Payload Dispatch Simulation Trace (200 OK) | |
| </h3> | |
| <button | |
| onClick={() => setTestExecutionResult(null)} | |
| className="text-[10px] font-bold uppercase tracking-widest text-zinc-600 hover:text-zinc-300 transition-colors" | |
| > | |
| Terminate Trace | |
| </button> | |
| </div> | |
| <div className="p-6 bg-black/60 border border-white/5 rounded-2xl"> | |
| <pre className="text-[11px] font-mono text-emerald-400/80 overflow-x-auto selection:bg-emerald-500 selection:text-zinc-950"> | |
| {JSON.stringify(testExecutionResult, null, 2)} | |
| </pre> | |
| </div> | |
| </div> | |
| )} | |
| {/* Delete Confirmation */} | |
| <ConfirmModal | |
| isOpen={Boolean(selectedForDelete)} | |
| onClose={() => setSelectedForDelete(null)} | |
| onConfirm={() => selectedForDelete && deleteMutation.mutate(selectedForDelete)} | |
| title="Terminate Relay Node" | |
| description="Are you sure you want to delete this webhook endpoint? Signal notifications will cease dispatching to this destination immediately." | |
| confirmText="Terminate" | |
| /> | |
| {/* Create Webhook Drawer */} | |
| <FormDrawer | |
| isOpen={isCreateOpen} | |
| onClose={() => setIsCreateOpen(false)} | |
| title="Register Event Relay" | |
| subtitle="Provision a new HTTPS callback node for real-time signal processing." | |
| > | |
| <form | |
| onSubmit={async (e) => { | |
| e.preventDefault(); | |
| const form = e.target as HTMLFormElement; | |
| const target_url = (form.elements.namedItem("target_url") as HTMLInputElement).value; | |
| const campaign_id = (form.elements.namedItem("campaign_id") as HTMLSelectElement).value; | |
| const checkedEvents = AVAILABLE_EVENTS.filter( | |
| (ev) => (form.elements.namedItem(ev.id) as HTMLInputElement)?.checked | |
| ).map((ev) => ev.id); | |
| if (checkedEvents.length === 0) { | |
| toast.error("Please select at least one event trigger"); | |
| return; | |
| } | |
| try { | |
| await apiClient.post("/webhooks", { | |
| target_url, | |
| campaign_id: campaign_id === "ALL" ? null : campaign_id, | |
| event_types: checkedEvents, | |
| }); | |
| toast.success("Webhook configured successfully!"); | |
| setIsCreateOpen(false); | |
| refetch(); | |
| } catch (err: any) { | |
| toast.error("Failed to create webhook node"); | |
| } | |
| }} | |
| className="space-y-8 text-sm p-2" | |
| > | |
| <div className="space-y-2"> | |
| <label className="text-[10px] font-bold uppercase tracking-widest text-zinc-500">Target Endpoint Identity (HTTPS) *</label> | |
| <input | |
| name="target_url" | |
| type="url" | |
| required | |
| placeholder="https://api.domain.io/webhooks/inbound" | |
| className="w-full bg-zinc-950 border border-white/10 rounded-xl p-3 text-emerald-400 font-mono text-xs focus:outline-none focus:border-emerald-500 transition-colors placeholder:text-zinc-800" | |
| /> | |
| </div> | |
| <div className="space-y-2"> | |
| <label className="text-[10px] font-bold uppercase tracking-widest text-zinc-500">Operation Cluster Scope</label> | |
| <select | |
| name="campaign_id" | |
| defaultValue="ALL" | |
| className="w-full bg-zinc-950 border border-white/10 rounded-xl p-3 text-zinc-200 focus:outline-none focus:border-emerald-500 transition-colors text-xs font-bold" | |
| > | |
| <option value="ALL">Global Operational Fleet</option> | |
| {campaigns.map((c: any) => ( | |
| <option key={c.id} value={c.id}> | |
| {c.name} | |
| </option> | |
| ))} | |
| </select> | |
| </div> | |
| <div className="space-y-4 pt-4 border-t border-white/5"> | |
| <label className="text-[10px] font-bold uppercase tracking-widest text-zinc-500">Signal Subscription Matrix *</label> | |
| <div className="grid grid-cols-1 gap-2"> | |
| {AVAILABLE_EVENTS.map((ev) => ( | |
| <label | |
| key={ev.id} | |
| className="flex items-center gap-4 p-4 bg-zinc-950 border border-white/5 rounded-2xl cursor-pointer hover:bg-emerald-500/5 hover:border-emerald-500/20 transition-all group" | |
| > | |
| <input | |
| type="checkbox" | |
| name={ev.id} | |
| defaultChecked | |
| className="w-4 h-4 rounded border-white/10 bg-black text-emerald-500 focus:ring-emerald-500/40" | |
| /> | |
| <div> | |
| <div className="text-[11px] font-bold text-zinc-200 group-hover:text-emerald-400 transition-colors">{ev.label}</div> | |
| <div className="text-[9px] text-zinc-600 font-mono uppercase tracking-tighter mt-0.5">{ev.id}</div> | |
| </div> | |
| </label> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="pt-8 flex justify-end gap-3 border-t border-white/5"> | |
| <button | |
| type="button" | |
| onClick={() => setIsCreateOpen(false)} | |
| className="px-6 py-2.5 text-zinc-400 hover:text-white font-bold transition-colors text-xs" | |
| > | |
| Cancel | |
| </button> | |
| <button | |
| type="submit" | |
| className="px-8 py-2.5 bg-emerald-500 hover:bg-emerald-400 text-zinc-950 font-bold rounded-xl text-xs shadow-lg active:scale-95 transition-all" | |
| > | |
| Register Relay Node | |
| </button> | |
| </div> | |
| </form> | |
| </FormDrawer> | |
| </div> | |
| ); | |
| } | |