'use client' import { Card, CardContent, CardHeader } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { DeleteWebhookButton } from './delete-webhook-button' import { Edit2, Eye, EyeOff } from 'lucide-react' import { Switch } from '@/components/ui/switch' import { useState } from 'react' import { useToast } from '@/hooks/use-toast' import { CopyButton } from '@/components/shared/copy-button' import { WebhookData } from '@/lib/types' import httpBrowserClient from '@/lib/httpBrowserClient' import { ApiEndpoints } from '@/config/api' import { useQueryClient } from '@tanstack/react-query' interface WebhookCardProps { webhook: WebhookData onEdit: () => void onDelete?: () => void } export function WebhookCard({ webhook, onEdit, onDelete }: WebhookCardProps) { const { toast } = useToast() const [isLoading, setIsLoading] = useState(false) const queryClient = useQueryClient() const [showSecret, setShowSecret] = useState(false) const handleToggle = async (checked: boolean) => { setIsLoading(true) try { await httpBrowserClient.patch( ApiEndpoints.gateway.updateWebhook(webhook._id), { isActive: checked } ) await queryClient.invalidateQueries({ queryKey: ['webhooks'] }) toast({ title: `Webhook ${checked ? 'enabled' : 'disabled'}`, description: `Webhook notifications are now ${ checked ? 'enabled' : 'disabled' }.`, }) } catch (error) { toast({ title: 'Error', description: `Failed to ${checked ? 'enable' : 'disable'} webhook`, variant: 'destructive', }) } finally { setIsLoading(false) } } const maskSecret = (secret: string) => { // if the secret is less than 18 characters, show all if (secret.length <= 18) { return secret.slice(0, 18) } return secret.slice(0, 18) + '*'.repeat(secret.length - 24) } return (

Webhook Endpoint

{webhook.isActive ? 'Active' : 'Inactive'}

Notifications for SMS events

{webhook.deliveryUrl}
{showSecret ? webhook.signingSecret : maskSecret(webhook.signingSecret)}
{webhook.events.map((event) => ( {event} ))}
) }