veza/apps/web/src/components/developer/WebhooksView.tsx

149 lines
4.5 KiB
TypeScript
Raw Normal View History

import React, { useState } from 'react';
import { Card } from '../ui/card';
import { Button } from '../ui/button';
import { Input } from '../ui/input';
import { Radio, Plus, Trash2, Zap, AlertTriangle } from 'lucide-react';
import { useToast } from '../../context/ToastContext';
interface Webhook {
id: string;
url: string;
events: string[];
status: 'active' | 'failed';
lastTriggered: string;
}
const MOCK_WEBHOOKS: Webhook[] = [
{
id: 'w1',
url: 'https://api.myapp.com/veza-hook',
events: ['track.upload', 'user.update'],
status: 'active',
lastTriggered: '2 hours ago',
},
{
id: 'w2',
url: 'https://hooks.slack.com/services/T000...',
events: ['sales.new'],
status: 'failed',
lastTriggered: '1 day ago',
},
];
export const WebhooksView: React.FC = () => {
const { addToast } = useToast();
const [webhooks, setWebhooks] = useState<Webhook[]>(MOCK_WEBHOOKS);
const [newUrl, setNewUrl] = useState('');
const handleCreate = () => {
if (!newUrl) return;
const newHook: Webhook = {
id: `w-${Date.now()}`,
url: newUrl,
events: ['all'],
status: 'active',
lastTriggered: 'Never',
};
setWebhooks([...webhooks, newHook]);
setNewUrl('');
addToast('Webhook created', 'success');
};
const handleTest = (_id: string) => {
addToast(`Sending test payload to webhook...`, 'info');
};
const handleDelete = (id: string) => {
setWebhooks(webhooks.filter((w) => w.id !== id));
addToast('Webhook deleted', 'info');
};
return (
<div className="space-y-8 animate-fadeIn pb-20">
<div>
<h2 className="text-2xl font-bold text-white mb-2">WEBHOOKS</h2>
<p className="text-kodo-content-dim font-mono text-sm">
Subscribe to real-time events.
</p>
</div>
<Card variant="default">
<h3 className="font-bold text-white mb-4 flex items-center gap-2">
aesthetic-improvements: reduce decorative cyan across multiple component categories (80/20 rule, batch 11) - Social: FeedView, ConnectionsView, GroupsView, ExploreView, GroupDetailView loading spinners and decorative text, CreatePostModal decorative select text and hashtag links, PostCard decorative tag links and waveform bars and view comments link, CreateGroupModal decorative icon (9 instances) - Settings: DataExportModal decorative icon, LoginHistory decorative IP text, AppearanceSettingsView decorative icon and selected theme checkmark, BackupsView decorative icon, CloudIntegrationView decorative icon, AccessibilitySettingsView decorative icon, SecuritySettings decorative icon, PasskeyModal decorative icon and loading spinner (8 instances) - Studio: ProjectsManager loading spinner and progress percentage text, CloudFileBrowser decorative music icons, AIToolsView decorative music icon, ConnectivityView decorative icon, CreateProjectModal decorative icon, CloudSettingsView decorative icon (6 instances) - Admin: AdminDashboardView loading spinner and decorative chart bars and icon, AdminSettingsView decorative icon, AdminModerationView loading spinner, AdminUsersView loading spinner (5 instances) - Inventory: InventoryView loading spinner, EquipmentCard decorative price icon, EquipmentDetailView loading spinner and decorative icons and price text, AddEquipmentView decorative icon (5 instances) - Seller: CreateProductView decorative icon, SellerDashboardView loading spinner and decorative icon and sales text (3 instances) - Live: LiveStreamDetailView decorative streamer name text (1 instance) - Developer: DeveloperDashboardView loading spinner, WebhooksView decorative icon (2 instances) - Upload: BulkUploadModal decorative icon, FilePreviewCard decorative audio file icon, MetadataForm decorative button text, CoverArtUploadModal decorative icon, LyricsEditorModal decorative icon (5 instances) - Notifications: NotificationItem decorative follow icon and mark as read button, NotificationBell decorative mark all read link (3 instances) - Total: ~46 files, ~46 instances replaced - Preserved: Active/selected states (CloudFileBrowser selected files checkmarks, CreatePostModal post type active state, GroupCard/GroupDetailView public/private badges - semantic indicators, DataExportModal checkbox accents - focus/interaction, AppearanceSettingsView selected theme - active state, PasskeyModal checkbox accent - focus/interaction, LyricsEditorModal checkbox accent - focus/interaction, FileUploadZone drag active state - active state, EquipmentDetailView support link - functional link, FlashSaleModal link - functional link, EquipmentDetailView image indicator dots - active state), primary actions, design system variants - Action 11.3.1.3 in progress (eleventh batch: social, settings, studio, admin, inventory, seller, live, developer, upload, notifications components)
2026-01-16 10:26:33 +00:00
<Plus className="w-4 h-4 text-kodo-steel" /> Add Endpoint
</h3>
<div className="flex gap-4">
<Input
placeholder="https://your-domain.com/webhook"
value={newUrl}
onChange={(e) => setNewUrl(e.target.value)}
className="flex-1"
/>
<Button variant="primary" onClick={handleCreate} disabled={!newUrl}>
Create
</Button>
</div>
</Card>
<div className="space-y-4">
{webhooks.map((hook) => (
<Card
key={hook.id}
variant="gaming"
className="flex flex-col md:flex-row items-start md:items-center justify-between p-4 gap-4"
>
<div className="flex items-start gap-4">
<div
className={`p-2 rounded-full ${hook.status === 'active' ? 'bg-kodo-lime/10 text-kodo-lime' : 'bg-kodo-red/10 text-kodo-red'}`}
>
{hook.status === 'active' ? (
<Radio className="w-5 h-5" />
) : (
<AlertTriangle className="w-5 h-5" />
)}
</div>
<div>
<div className="font-bold text-white font-mono text-sm break-all">
{hook.url}
</div>
<div className="text-xs text-kodo-content-dim mt-1 flex flex-wrap gap-2">
<span className="text-kodo-content-dim">Events:</span>
{hook.events.map((e) => (
<span
key={e}
className="bg-white/5 px-1.5 rounded text-kodo-text-main"
>
{e}
</span>
))}
<span className="text-kodo-content-dim ml-2">
Last Triggered: {hook.lastTriggered}
</span>
</div>
</div>
</div>
<div className="flex gap-2 w-full md:w-auto">
<Button
variant="ghost"
size="sm"
className="flex-1 md:flex-none border border-kodo-steel"
onClick={() => handleTest(hook.id)}
>
<Zap className="w-4 h-4 mr-2" /> Test
</Button>
<Button
variant="ghost"
size="sm"
className="flex-1 md:flex-none text-kodo-red hover:bg-kodo-red/10"
onClick={() => handleDelete(hook.id)}
>
<Trash2 className="w-4 h-4" />
</Button>
</div>
</Card>
))}
</div>
</div>
);
};