import React, { useState, useEffect } from 'react'; import { Card } from '../ui/card'; import { Button } from '../ui/button'; import { StatCard } from '../dashboard/StatCard'; import { CreateAPIKeyModal } from './modals/CreateAPIKeyModal'; import { Key, Activity, Globe, Plus, Trash2, Eye, ExternalLink, Loader2 } from 'lucide-react'; import { useToast } from '../../context/ToastContext'; import { developerService } from '../../services/developerService'; import { logger } from '@/utils/logger'; interface ApiKey { id: string; name: string; prefix: string; created: string; lastUsed: string; status: 'active' | 'revoked'; } export const DeveloperDashboardView: React.FC = () => { const { addToast } = useToast(); const [keys, setKeys] = useState([]); const [loading, setLoading] = useState(true); const [stats, setStats] = useState({}); const [showCreateModal, setShowCreateModal] = useState(false); useEffect(() => { const fetchData = async () => { setLoading(true); try { const [keysData, statsData] = await Promise.all([ developerService.listKeys(), developerService.getStats() ]); setKeys(keysData); setStats(statsData); } catch (e) { logger.error('Error loading developer dashboard data', { error: e instanceof Error ? e.message : String(e), stack: e instanceof Error ? e.stack : undefined, }); } finally { setLoading(false); } }; fetchData(); }, []); const handleCreateKey = async (data: { name: string, scopes: string[] }) => { try { const newKey = await developerService.createKey(data); setKeys([newKey, ...keys]); addToast("API Key created successfully", "success"); } catch (e) { addToast("Failed to create API key", "error"); } }; const handleRevoke = async (id: string) => { if (confirm('Are you sure you want to revoke this key?')) { await developerService.revokeKey(id); setKeys(keys.filter(k => k.id !== id)); addToast("API Key revoked", "info"); } }; if (loading) return
; return (
{/* Header */}

DEVELOPER PORTAL

Build on top of the Veza Platform.

{/* Stats */}
} trend={5.2} color="cyan" /> } trend={-12} color="lime" /> } color="gold" />
{/* API Keys List */}

Active API Keys

{keys.map(key => ( ))} {keys.length === 0 && ( )}
Name Key Prefix Created Last Used Actions
{key.name} {key.prefix} {key.created} {key.lastUsed}
No active API keys. Create one to get started.
{showCreateModal && setShowCreateModal(false)} onCreate={handleCreateKey} />}
); };